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, |