1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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;
}
|