redmine

Control socket support continued (socket.c is still unusable)

... ... @@ -1367,7 +1367,13 @@ preserve_fileaccess_end:
ret = socket_run(&options);
if(ret == 0) {
// == RUNNING ==
ret = sync_run(&options);
// == RUNNING ==
if(options.socketpath != NULL)
socket_cleanup(&options);
}
if(options.pidfile != NULL) {
... ...
... ... @@ -22,12 +22,76 @@
#include <sys/un.h> // for "struct sockaddr_un"
#include "output.h"
#include "sync.h"
#include "socket.h"
static pthread_t pthread_socket;
int socket_loop(options_t *options_p) {
// Configuring signals
sigset_t sigset;
sigemptyset(&sigset);
sigaddset(&sigset, SIGTERM);
int ret = pthread_sigmask(SIG_BLOCK, &sigset, NULL);
if(ret) return ret;
// Starting
printf_d("Debug2: socket_loop() started\n");
int s;
while((s=options_p->socket)) {
// Checking for new signals
int signal = sigwait(&sigset, &signal);
if(signal) {
switch(signal) {
case SIGTERM:
close(options_p->socket);
options_p->socket=0;
break;
default:
printf_e("Warning: Got unknown signal %i. Ignoring\n", signal);
break;
}
continue;
}
// Check if the socket is still alive
int error_code, ret;
socklen_t error_code_len = sizeof(error_code);
if((ret=getsockopt(s, SOL_SOCKET, SO_ERROR, &error_code, &error_code_len))) {
printf_d("Debug: Control socket closed [case 0]: %s\n", strerror(ret));
options_p->socket=0;
continue;
}
if(error_code) {
printf_d("Debug: Control socket closed [case 1]: %s\n", strerror(error_code));
options_p->socket=0;
continue;
}
// Waiting for event
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(s, &rfds);
int count = select(s+1, &rfds, NULL, NULL, NULL);
// Processing the events
(void) count;
}
// Cleanup
printf_d("Debug2: socket_loop() finished\n");
return 0;
}
... ... @@ -74,3 +138,8 @@ int socket_run(options_t *options_p) {
return 0;
}
int socket_cleanup(options_t *options_p) {
pthread_kill(pthread_socket, SIGTERM);
return pthread_join(pthread_socket, NULL);
}
... ...
... ... @@ -19,5 +19,6 @@
extern int socket_run(options_t *options_p);
extern int socket_cleanup(options_t *options_p);
... ...