|
@@ -32,6 +32,7 @@
|
|
|
#include <netinet/in.h>
|
|
#include <netinet/in.h>
|
|
|
#include <arpa/inet.h>
|
|
#include <arpa/inet.h>
|
|
|
#include <poll.h>
|
|
#include <poll.h>
|
|
|
|
|
+#include <signal.h>
|
|
|
|
|
|
|
|
#include <vcc/vcc.h>
|
|
#include <vcc/vcc.h>
|
|
|
#include <vcc/vccd.h>
|
|
#include <vcc/vccd.h>
|
|
@@ -85,6 +86,8 @@ int becomes_daemon(void) {
|
|
|
(void) dup(0);
|
|
(void) dup(0);
|
|
|
(void) dup(0);
|
|
(void) dup(0);
|
|
|
|
|
|
|
|
|
|
+ setsid();
|
|
|
|
|
+
|
|
|
if (unlikely(fd = open("/var/run/vccd.pid", O_WRONLY | O_CREAT, 0644)) < 0) {
|
|
if (unlikely(fd = open("/var/run/vccd.pid", O_WRONLY | O_CREAT, 0644)) < 0) {
|
|
|
perror("open(/var/run/vccd.pid)");
|
|
perror("open(/var/run/vccd.pid)");
|
|
|
|
|
|
|
@@ -140,16 +143,24 @@ static int init_socket(void) {
|
|
|
fds[0].fd = fd;
|
|
fds[0].fd = fd;
|
|
|
fds[0].events = POLLIN;
|
|
fds[0].events = POLLIN;
|
|
|
|
|
|
|
|
- fds[1].fd = 0;
|
|
|
|
|
- fds[1].events = POLLIN;
|
|
|
|
|
-
|
|
|
|
|
- next_fd = 2;
|
|
|
|
|
|
|
+ next_fd = 1;
|
|
|
|
|
|
|
|
return fd;
|
|
return fd;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static inline int prompt(void) {
|
|
|
|
|
- fputs("> ", stderr);
|
|
|
|
|
|
|
+void sigpipe_handler(int nr) {
|
|
|
|
|
+ (void) nr;
|
|
|
|
|
+
|
|
|
|
|
+ vcc_log("SIGPIPE caused. \n");
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+static int setup_signals(void) {
|
|
|
|
|
+ struct sigaction act;
|
|
|
|
|
+
|
|
|
|
|
+ memset(&act, 0, sizeof(struct sigaction));
|
|
|
|
|
+ act.sa_handler = sigpipe_handler;
|
|
|
|
|
+
|
|
|
|
|
+ sigaction(SIGPIPE, &act, NULL);
|
|
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
|
}
|
|
}
|
|
@@ -171,7 +182,9 @@ int main(int argc, const char **argv) {
|
|
|
init_socket();
|
|
init_socket();
|
|
|
users_init();
|
|
users_init();
|
|
|
|
|
|
|
|
- nfds_total = 2;
|
|
|
|
|
|
|
+ setup_signals();
|
|
|
|
|
+
|
|
|
|
|
+ nfds_total = 1;
|
|
|
|
|
|
|
|
if (unlikely(!(buf = amalloc(REQ_SIZE)))) {
|
|
if (unlikely(!(buf = amalloc(REQ_SIZE)))) {
|
|
|
vcc_log("*** malloc() failed\n");
|
|
vcc_log("*** malloc() failed\n");
|
|
@@ -179,8 +192,6 @@ int main(int argc, const char **argv) {
|
|
|
return 1;
|
|
return 1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- prompt();
|
|
|
|
|
-
|
|
|
|
|
for (;;) {
|
|
for (;;) {
|
|
|
nfds_ready = poll(fds, nfds_total, -1);
|
|
nfds_ready = poll(fds, nfds_total, -1);
|
|
|
|
|
|
|
@@ -216,14 +227,7 @@ int main(int argc, const char **argv) {
|
|
|
nfds_total++;
|
|
nfds_total++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (fds[1].revents & POLLIN) {
|
|
|
|
|
- monitor_cmd();
|
|
|
|
|
- prompt();
|
|
|
|
|
-
|
|
|
|
|
- fds[1].revents = 0;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- for (i = 2; i < nfds_total; i++) {
|
|
|
|
|
|
|
+ for (i = 1; i < nfds_total; i++) {
|
|
|
if (fds[i].fd == -1)
|
|
if (fds[i].fd == -1)
|
|
|
continue;
|
|
continue;
|
|
|
|
|
|