-
Notifications
You must be signed in to change notification settings - Fork 2
/
trigger.c
87 lines (76 loc) · 2.11 KB
/
trigger.c
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
*
* Authors:
* Thierry Danis <[email protected]>
*
* This software is Copyright 1996,1997 by the above mentioned author(s),
* All Rights Reserved.
*
* The license which is distributed with this software in the file COPYRIGHT
* applies to this software. If your distribution is missing this file, you
* may request it from <[email protected]>.
*
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <syslog.h>
#include <errno.h>
#include "pvd.h"
#include "log.h"
#include "trigger.h"
// trigger_socket : create a pipe on which companion daemons
// can send messages to trigger various operations on the radvd
// daemon
int trigger_pipe(char *trigger_pipe_name)
{
int fd;
unlink(trigger_pipe_name);
if (mkfifo(trigger_pipe_name, S_IREAD | S_IWRITE) == -1) {
flog(LOG_ERR, "can not create trigger pipe (%s) : %s",
trigger_pipe_name,
strerror(errno));
return(-1);
}
if ((fd = open(trigger_pipe_name, O_RDONLY)) == -1) {
flog(LOG_ERR, "can not open trigger pipe (%s) : %s",
trigger_pipe_name,
strerror(errno));
return(-1);
}
if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK) == -1) {
flog(LOG_ERR,
"can not set trigger pipe to non blocking mode (%s) : %s",
trigger_pipe_name,
strerror(errno));
close(fd);
return(-1);
}
return(fd);
}
// FIXME : handle SIGHUP here (writing end has closed) : we need to avoid
// conflict with the legacy way of using SIGHUP to reload the configuration
// file
void process_trigger_msg(int fd)
{
char PvdId[1024];
char msg[1024]; // messages should be much shorter than that
int n;
if ((n = read(fd, msg, sizeof(msg) - 1)) > 0) {
msg[n] = '\0';
}
// Messages formats are defined in the following document : ...
// We have chosen to use text based messages to make it simpler to
// have triggers implementations written in scripting languages
if (sscanf(msg, "PVD %[^ ] UPDATED\n", PvdId) == 1) {
if (strlen(PvdId) > PVDIDNAMSIZ - 1) {
flog(LOG_INFO, "incorrect trigger message (-%s- too large)", PvdId);
}
else {
}
}
}