src/server/daemon/srvctrl.c

branch
srvctrl
changeset 166
c07122f66676
parent 158
77f4f0079428
child 167
4be7dd2b75b9
equal deleted inserted replaced
158:77f4f0079428 166:c07122f66676
39 #include "srvctrl.h" 39 #include "srvctrl.h"
40 40
41 #define SRVCTRL_THREAD_STACKSIZE 8192 41 #define SRVCTRL_THREAD_STACKSIZE 8192
42 42
43 static int srvctrl; 43 static int srvctrl;
44 static sstr_t srvctrl_path;
45
44 static WSBool srv_shutdown; 46 static WSBool srv_shutdown;
45 47
46 int srvctrl_init(ServerConfiguration *cfg) { 48 int srvctrl_init(ServerConfiguration *cfg) {
47 // create srvctrl unix domain socket 49 // create srvctrl unix domain socket
48 // this socket is used for stop, reconfigure and other operations 50 // this socket is used for stop, reconfigure and other operations
49 sstr_t uds_path = ucx_sprintf("%s/private/srvctrl.sock", cfg->tmp.ptr); 51 srvctrl_path = ucx_sprintf("%s/private/srvctrl.sock", cfg->tmp.ptr);
50 struct sockaddr_un addr; 52 struct sockaddr_un addr;
51 if(uds_path.length > sizeof(addr.sun_path)-1) { 53 if(srvctrl_path.length > sizeof(addr.sun_path)-1) {
52 log_ereport( 54 log_ereport(
53 LOG_CATASTROPHE, 55 LOG_CATASTROPHE,
54 "path '%s' too long for unix domain socket", 56 "path '%s' too long for unix domain socket",
55 uds_path.ptr); 57 srvctrl_path.ptr);
56 return -1; 58 return -1;
57 } 59 }
58 60
59 // make sure there is no old srvctrl socket file 61 // make sure there is no old srvctrl socket file
60 // otherweise bind would fail 62 // otherweise bind would fail
61 if(unlink(uds_path.ptr)) { 63 if(unlink(srvctrl_path.ptr)) {
62 if(errno != ENOENT) { 64 if(errno != ENOENT) {
63 log_ereport( 65 log_ereport(
64 LOG_CATASTROPHE, 66 LOG_CATASTROPHE,
65 "cannot unlink old srvctrl socket '%s': %s", 67 "cannot unlink old srvctrl socket '%s': %s",
66 uds_path.ptr, 68 srvctrl_path.ptr,
67 strerror(errno)); 69 strerror(errno));
68 return -1; 70 return -1;
69 } 71 }
70 } 72 }
71 73
72 ZERO(&addr, sizeof(addr)); 74 ZERO(&addr, sizeof(addr));
73 addr.sun_family = AF_UNIX; 75 addr.sun_family = AF_UNIX;
74 memcpy(addr.sun_path, uds_path.ptr, uds_path.length); 76 memcpy(addr.sun_path, srvctrl_path.ptr, srvctrl_path.length);
75 77
76 srvctrl = socket(AF_UNIX, SOCK_STREAM, 0); 78 srvctrl = socket(AF_UNIX, SOCK_STREAM, 0);
77 if(srvctrl == -1) { 79 if(srvctrl == -1) {
78 log_ereport( 80 log_ereport(
79 LOG_CATASTROPHE, 81 LOG_CATASTROPHE,
86 LOG_CATASTROPHE, 88 LOG_CATASTROPHE,
87 "srvctrl socket bind failed: %s", 89 "srvctrl socket bind failed: %s",
88 strerror(errno)); 90 strerror(errno));
89 return -1; 91 return -1;
90 } 92 }
91
92 free(uds_path.ptr);
93 93
94 return 0; 94 return 0;
95 } 95 }
96 96
97 int srvctrl_wait() { 97 int srvctrl_wait() {
118 (thrstartfunc)srvctrl_thread, 118 (thrstartfunc)srvctrl_thread,
119 client); 119 client);
120 systhread_detach(t); 120 systhread_detach(t);
121 121
122 } 122 }
123
124 unlink(srvctrl_path.ptr);
125 free(srvctrl_path.ptr);
126
127 return 0;
123 } 128 }
124 129
125 void srvctrl_shutdown() { 130 void srvctrl_shutdown() {
126 srv_shutdown = TRUE; 131 srv_shutdown = TRUE;
127 close(srvctrl); 132 close(srvctrl);

mercurial