X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fsysdep.c;h=f4e20d72ebb3c6bda71acff9ecad6fce5d95f1e9;hb=11219dbc3e638e7ee47feffbbb7d63588d7dd77f;hp=33fde1e5157cf9106575fa8cfbef3fd64d6a1c53;hpb=abcd4c63c02f9f3a1349f50925b3325e1148bddd;p=citadel.git diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 33fde1e51..f4e20d72e 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -154,6 +154,7 @@ void lprintf(enum LogLevel loglevel, const char *format, ...) { */ volatile int time_to_die = 0; +volatile int shutdown_and_halt = 0; static RETSIGTYPE signal_cleanup(int signum) { lprintf(CTDL_DEBUG, "Caught signal %d; shutting down.\n", signum); @@ -247,6 +248,7 @@ void begin_critical_section(int which_one) #ifdef DEBUG_MEMORY_LEAKS && (which_one != S_DEBUGMEMLEAKS) #endif + && (which_one != S_RPLIST) ) { cdb_check_handles(); } @@ -268,7 +270,7 @@ void end_critical_section(int which_one) * a TCP port. The server shuts down if the bind fails. * */ -int ig_tcp_server(char *ip_addr, int port_number, int queue_len) +int ig_tcp_server(char *ip_addr, int port_number, int queue_len, char **errormessage) { struct sockaddr_in sin; int s, i; @@ -294,8 +296,11 @@ int ig_tcp_server(char *ip_addr, int port_number, int queue_len) s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (s < 0) { - lprintf(CTDL_EMERG, "citserver: Can't create a socket: %s\n", - strerror(errno)); + *errormessage = (char*) malloc(SIZ + 1); + snprintf(*errormessage, SIZ, + "citserver: Can't create a socket: %s", + strerror(errno)); + lprintf(CTDL_EMERG, "%s\n", *errormessage); return(-1); } @@ -303,24 +308,32 @@ int ig_tcp_server(char *ip_addr, int port_number, int queue_len) setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i)); if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) { - lprintf(CTDL_EMERG, "citserver: Can't bind: %s\n", - strerror(errno)); + *errormessage = (char*) malloc(SIZ + 1); + snprintf(*errormessage, SIZ, + "citserver: Can't bind: %s", + strerror(errno)); + lprintf(CTDL_EMERG, "%s\n", *errormessage); close(s); return(-1); } /* set to nonblock - we need this for some obscure situations */ if (fcntl(s, F_SETFL, O_NONBLOCK) < 0) { - lprintf(CTDL_EMERG, - "citserver: Can't set socket to non-blocking: %s\n", - strerror(errno)); + *errormessage = (char*) malloc(SIZ + 1); + snprintf(*errormessage, SIZ, + "citserver: Can't set socket to non-blocking: %s", + strerror(errno)); + lprintf(CTDL_EMERG, "%s\n", *errormessage); close(s); return(-1); } if (listen(s, actual_queue_len) < 0) { - lprintf(CTDL_EMERG, "citserver: Can't listen: %s\n", - strerror(errno)); + *errormessage = (char*) malloc(SIZ + 1); + snprintf(*errormessage, SIZ, + "citserver: Can't listen: %s", + strerror(errno)); + lprintf(CTDL_EMERG, "%s\n", *errormessage); close(s); return(-1); } @@ -333,7 +346,7 @@ int ig_tcp_server(char *ip_addr, int port_number, int queue_len) /* * Create a Unix domain socket and listen on it */ -int ig_uds_server(char *sockpath, int queue_len) +int ig_uds_server(char *sockpath, int queue_len, char **errormessage) { struct sockaddr_un addr; int s; @@ -345,8 +358,10 @@ int ig_uds_server(char *sockpath, int queue_len) i = unlink(sockpath); if (i != 0) if (errno != ENOENT) { - lprintf(CTDL_EMERG, "citserver: can't unlink %s: %s\n", + *errormessage = (char*) malloc(SIZ + 1); + snprintf(*errormessage, SIZ, "citserver: can't unlink %s: %s", sockpath, strerror(errno)); + lprintf(CTDL_EMERG, "%s\n", *errormessage); return(-1); } @@ -356,29 +371,40 @@ int ig_uds_server(char *sockpath, int queue_len) s = socket(AF_UNIX, SOCK_STREAM, 0); if (s < 0) { - lprintf(CTDL_EMERG, "citserver: Can't create a socket: %s\n", - strerror(errno)); + *errormessage = (char*) malloc(SIZ + 1); + snprintf(*errormessage, SIZ, + "citserver: Can't create a socket: %s", + strerror(errno)); + lprintf(CTDL_EMERG, "%s\n", *errormessage); return(-1); } if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) { - lprintf(CTDL_EMERG, "citserver: Can't bind: %s\n", - strerror(errno)); + *errormessage = (char*) malloc(SIZ + 1); + snprintf(*errormessage, SIZ, + "citserver: Can't bind: %s", + strerror(errno)); + lprintf(CTDL_EMERG, "%s\n", *errormessage); return(-1); } /* set to nonblock - we need this for some obscure situations */ if (fcntl(s, F_SETFL, O_NONBLOCK) < 0) { - lprintf(CTDL_EMERG, - "citserver: Can't set socket to non-blocking: %s\n", - strerror(errno)); + *errormessage = (char*) malloc(SIZ + 1); + snprintf(*errormessage, SIZ, + "citserver: Can't set socket to non-blocking: %s", + strerror(errno)); + lprintf(CTDL_EMERG, "%s\n", *errormessage); close(s); return(-1); } if (listen(s, actual_queue_len) < 0) { - lprintf(CTDL_EMERG, "citserver: Can't listen: %s\n", - strerror(errno)); + *errormessage = (char*) malloc(SIZ + 1); + snprintf(*errormessage, SIZ, + "citserver: Can't listen: %s", + strerror(errno)); + lprintf(CTDL_EMERG, "%s\n", *errormessage); return(-1); }