summaryrefslogtreecommitdiff
path: root/ecp/server
diff options
context:
space:
mode:
Diffstat (limited to 'ecp/server')
-rw-r--r--ecp/server/Makefile2
-rw-r--r--ecp/server/server.c15
-rw-r--r--ecp/server/sig.c61
-rw-r--r--ecp/server/sig.h2
4 files changed, 75 insertions, 5 deletions
diff --git a/ecp/server/Makefile b/ecp/server/Makefile
index 84070bf..977e891 100644
--- a/ecp/server/Makefile
+++ b/ecp/server/Makefile
@@ -3,7 +3,7 @@ include $(src_dir)/ecp/common.mk
CFLAGS += -I../util -Wno-int-to-void-pointer-cast
LDFLAGS += -lrt
-obj = server.o dir.o vlink.o ht.o acl.o timer.o
+obj = server.o dir.o vlink.o ht.o acl.o sig.o timer.o
dep = ../build-posix/*.a ../util/libecputil.a
%.o: %.c
diff --git a/ecp/server/server.c b/ecp/server/server.c
index 890d468..a4bd8f6 100644
--- a/ecp/server/server.c
+++ b/ecp/server/server.c
@@ -16,6 +16,7 @@
#include "vlink.h"
#include "ht.h"
#include "acl.h"
+#include "sig.h"
#include "server.h"
@@ -97,6 +98,10 @@ static ECPConnection *conn_new(ECPSocket *sock, ECPConnection *parent, unsigned
return conn;
}
+static void conn_free(ECPConnection *conn) {
+ free(conn);
+}
+
static int key_check(ECPSocket *sock, ECPConnection *parent, unsigned char ctype, ecp_ecdh_public_t *public) {
switch (ctype) {
case CTYPE_DIR: {
@@ -115,10 +120,6 @@ static int key_check(ECPSocket *sock, ECPConnection *parent, unsigned char ctype
}
}
-static void conn_free(ECPConnection *conn) {
- free(conn);
-}
-
void log_print(int level, char *format, ...) {
va_list args;
time_t t;
@@ -221,6 +222,9 @@ int main(int argc, char *argv[]) {
if (rv) fail("acl_load err:%d\n", rv);
}
+ rv = sig_init();
+ if (rv) fail("sig_init err:%d\n", rv);
+
rv = dir_init(&sock);
if (rv) fail("dir_init err:%d\n", rv);
@@ -230,6 +234,9 @@ int main(int argc, char *argv[]) {
rv = ecp_start_receiver(&sock);
if (rv) fail("ecp_start_receiver err:%d\n", rv);
+ rv = sig_start_handler();
+ if (rv) fail("sig_start_handler err:%d\n", rv);
+
if (argc == _argc + 2) {
ECPNode node;
ecp_ecdh_public_t node_pub;
diff --git a/ecp/server/sig.c b/ecp/server/sig.c
new file mode 100644
index 0000000..09593d3
--- /dev/null
+++ b/ecp/server/sig.c
@@ -0,0 +1,61 @@
+#include <stdlib.h>
+#include <unistd.h>
+#include <signal.h>
+
+#include <ecp/core.h>
+#include <ecp/dir/dir.h>
+
+#include "server.h"
+#include "acl.h"
+#include "sig.h"
+
+static pthread_t sig_handler_thd;
+static sigset_t sig_set;
+
+static void * _sig_handler(void *arg) {
+ sigset_t *set = arg;
+ int rv, sig;
+
+ while (1) {
+ rv = sigwait(set, &sig);
+ if (rv) {
+ LOG(LOG_ERR, "sig_handler: sigwait err:%d\n", rv);
+ continue;
+ }
+ switch (sig) {
+ case SIGUSR1: {
+ rv = acl_load();
+ if (rv) {
+ LOG(LOG_ERR, "sig_handler: acl load err:%d\n", rv);
+ continue;
+ }
+ LOG(LOG_DEBUG, "sig_handler: acl reloaded\n");
+ break;
+ }
+ }
+ }
+
+ return NULL;
+}
+
+int sig_start_handler(void) {
+ int rv;
+
+ rv = pthread_create(&sig_handler_thd, NULL, &_sig_handler, (void *)&sig_set);
+ if (rv) return ECP_ERR;
+ return ECP_OK;
+
+}
+
+int sig_init(void) {
+ int rv;
+
+ sigemptyset(&sig_set);
+ sigaddset(&sig_set, SIGUSR1);
+
+ rv = pthread_sigmask(SIG_BLOCK, &sig_set, NULL);
+ if (rv) return ECP_ERR;
+
+ return ECP_OK;
+}
+
diff --git a/ecp/server/sig.h b/ecp/server/sig.h
new file mode 100644
index 0000000..be4d647
--- /dev/null
+++ b/ecp/server/sig.h
@@ -0,0 +1,2 @@
+int sig_start_handler(void);
+int sig_init(void);