--- a/src/server/daemon/srvctrl.c Wed Jan 25 11:50:19 2017 +0100 +++ b/src/server/daemon/srvctrl.c Sun Jan 29 09:04:06 2017 +0100 @@ -41,29 +41,31 @@ #define SRVCTRL_THREAD_STACKSIZE 8192 static int srvctrl; +static sstr_t srvctrl_path; + static WSBool srv_shutdown; int srvctrl_init(ServerConfiguration *cfg) { // create srvctrl unix domain socket // this socket is used for stop, reconfigure and other operations - sstr_t uds_path = ucx_sprintf("%s/private/srvctrl.sock", cfg->tmp.ptr); + srvctrl_path = ucx_sprintf("%s/private/srvctrl.sock", cfg->tmp.ptr); struct sockaddr_un addr; - if(uds_path.length > sizeof(addr.sun_path)-1) { + if(srvctrl_path.length > sizeof(addr.sun_path)-1) { log_ereport( LOG_CATASTROPHE, "path '%s' too long for unix domain socket", - uds_path.ptr); + srvctrl_path.ptr); return -1; } // make sure there is no old srvctrl socket file // otherweise bind would fail - if(unlink(uds_path.ptr)) { + if(unlink(srvctrl_path.ptr)) { if(errno != ENOENT) { log_ereport( LOG_CATASTROPHE, "cannot unlink old srvctrl socket '%s': %s", - uds_path.ptr, + srvctrl_path.ptr, strerror(errno)); return -1; } @@ -71,7 +73,7 @@ ZERO(&addr, sizeof(addr)); addr.sun_family = AF_UNIX; - memcpy(addr.sun_path, uds_path.ptr, uds_path.length); + memcpy(addr.sun_path, srvctrl_path.ptr, srvctrl_path.length); srvctrl = socket(AF_UNIX, SOCK_STREAM, 0); if(srvctrl == -1) { @@ -89,8 +91,6 @@ return -1; } - free(uds_path.ptr); - return 0; } @@ -120,6 +120,11 @@ systhread_detach(t); } + + unlink(srvctrl_path.ptr); + free(srvctrl_path.ptr); + + return 0; } void srvctrl_shutdown() {