src/server/daemon/srvctrl.c

branch
srvctrl
changeset 177
f144b60c71b1
parent 176
f2268fcbe487
child 178
4760f7f1b197
equal deleted inserted replaced
176:f2268fcbe487 177:f144b60c71b1
102 listen(srvctrl, 8); 102 listen(srvctrl, 8);
103 103
104 for(;;) { 104 for(;;) {
105 int fd = accept(srvctrl, NULL, 0); 105 int fd = accept(srvctrl, NULL, 0);
106 if(fd < 0) { 106 if(fd < 0) {
107 if(srv_shutdown) { 107 if(srv_shutdown) break;
108 break;
109 }
110
111 log_ereport( 108 log_ereport(
112 LOG_FAILURE, 109 LOG_FAILURE,
113 "srvctrl: accept failed: %s", 110 "srvctrl: accept failed: %s",
114 strerror(errno)); 111 strerror(errno));
115 continue; 112 break;
116 } 113 }
117 114
118 SrvCtrlClient *client = srvctrl_create_client(fd); 115 SrvCtrlClient *client = srvctrl_create_client(fd);
119 SYS_THREAD t = systhread_start( 116 SYS_THREAD t = systhread_start(
120 SYSTHREAD_DEFAULT_PRIORITY, 117 SYSTHREAD_DEFAULT_PRIORITY,
123 client); 120 client);
124 systhread_detach(t); 121 systhread_detach(t);
125 122
126 } 123 }
127 124
125 close(srvctrl);
128 unlink(srvctrl_path.ptr); 126 unlink(srvctrl_path.ptr);
129 free(srvctrl_path.ptr); 127 free(srvctrl_path.ptr);
130 128
131 return 0; 129 return 0;
132 } 130 }
133 131
134 void srvctrl_shutdown() { 132 void srvctrl_shutdown() {
135 srv_shutdown = TRUE; 133 srv_shutdown = TRUE;
136 close(srvctrl); 134 shutdown(srvctrl, SHUT_RDWR);
137 } 135 }
138 136
139 SrvCtrlClient* srvctrl_create_client(int fd) { 137 SrvCtrlClient* srvctrl_create_client(int fd) {
140 SrvCtrlClient *client = malloc(sizeof(SrvCtrlClient)); 138 SrvCtrlClient *client = malloc(sizeof(SrvCtrlClient));
141 ZERO(client, sizeof(SrvCtrlClient)); 139 ZERO(client, sizeof(SrvCtrlClient));
169 } 167 }
170 if(br) { 168 if(br) {
171 break; 169 break;
172 } 170 }
173 } 171 }
174
175 log_remove_logdup(&log); 172 log_remove_logdup(&log);
176 173
177 ucx_buffer_free(line); 174 ucx_buffer_free(line);
178 close(client->fd); 175 close(client->fd);
179 free(client); 176 free(client);
180
181 return NULL; 177 return NULL;
182 } 178 }
183 179
184 int srvctrl_handle_cmd(SrvCtrlClient *client, sstr_t cmd) { 180 int srvctrl_handle_cmd(SrvCtrlClient *client, sstr_t cmd) {
185 if(!sstrcmp(cmd, S("reconfig"))) { 181 if(!sstrcmp(cmd, S("reconfig"))) {

mercurial