... | ... |
@@ -33,7 +33,7 @@ pkgconfig_DATA = libclamav.pc |
33 | 33 |
# don't complain that configuration files and databases are not removed, this is intended |
34 | 34 |
distuninstallcheck_listfiles = find . -type f ! -name clamd.conf ! -name freshclam.conf ! -name daily.cvd ! -name main.cvd -print |
35 | 35 |
DISTCLEANFILES = target.h |
36 |
-DISTCHECK_CONFIGURE_FLAGS=--enable-milter --disable-clamav --enable-all-jit-targets --enable-llvm=yes |
|
36 |
+DISTCHECK_CONFIGURE_FLAGS=--enable-milter --disable-clamav --enable-all-jit-targets --enable-llvm=yes --with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir) |
|
37 | 37 |
lcov: |
38 | 38 |
($(MAKE); cd unit_tests; $(MAKE) lcov) |
39 | 39 |
quick-check: |
62 | 66 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,17 @@ |
0 |
+[Unit] |
|
1 |
+Description=Clam AntiVirus userspace daemon |
|
2 |
+Documentation=man:clamd(8) man:clamd.conf(5) http://www.clamav.net/lang/en/doc/ |
|
3 |
+Requires=clamav-daemon.socket |
|
4 |
+# Check for database existence |
|
5 |
+ConditionPathExistsGlob=@DBDIR@/main.{c[vl]d,inc} |
|
6 |
+ConditionPathExistsGlob=@DBDIR@/daily.{c[vl]d,inc} |
|
7 |
+ |
|
8 |
+[Service] |
|
9 |
+ExecStart=@prefix@/sbin/clamd --foreground=true |
|
10 |
+# Reload the database |
|
11 |
+ExecReload=/bin/kill -USR2 $MAINPID |
|
12 |
+StandardOutput=syslog |
|
13 |
+ |
|
14 |
+[Install] |
|
15 |
+WantedBy=multi-user.target |
|
16 |
+Also=clamav-daemon.socket |
0 | 17 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,16 @@ |
0 |
+[Unit] |
|
1 |
+Description=Socket for Clam AntiVirus userspace daemon |
|
2 |
+Documentation=man:clamd(8) man:clamd.conf(5) http://www.clamav.net/lang/en/doc/ |
|
3 |
+# Check for database existence |
|
4 |
+ConditionPathExistsGlob=@DBDIR@/main.{c[vl]d,inc} |
|
5 |
+ConditionPathExistsGlob=@DBDIR@/daily.{c[vl]d,inc} |
|
6 |
+ |
|
7 |
+[Socket] |
|
8 |
+ListenStream=/run/clamav/clamd.ctl |
|
9 |
+#ListenStream=127.0.0.1:1024 |
|
10 |
+SocketUser=clamav |
|
11 |
+SocketGroup=clamav |
|
12 |
+RemoveOnStop=True |
|
13 |
+ |
|
14 |
+[Install] |
|
15 |
+WantedBy=sockets.target |
... | ... |
@@ -73,7 +73,7 @@ |
73 | 73 |
#include "scanner.h" |
74 | 74 |
|
75 | 75 |
short debug_mode = 0, logok = 0; |
76 |
-short foreground = 0; |
|
76 |
+short foreground = -1; |
|
77 | 77 |
char hostid[37]; |
78 | 78 |
|
79 | 79 |
char *get_hostid(void *cbdata); |
... | ... |
@@ -125,7 +125,9 @@ int main(int argc, char **argv) |
125 | 125 |
int *lsockets=NULL; |
126 | 126 |
unsigned int nlsockets = 0; |
127 | 127 |
unsigned int dboptions = 0; |
128 |
- unsigned int i; |
|
128 |
+ unsigned int i; |
|
129 |
+ int j; |
|
130 |
+ int num_fd; |
|
129 | 131 |
#ifdef C_LINUX |
130 | 132 |
STATBUF sb; |
131 | 133 |
#endif |
... | ... |
@@ -161,6 +163,30 @@ int main(int argc, char **argv) |
161 | 161 |
debug_mode = 1; |
162 | 162 |
} |
163 | 163 |
|
164 |
+ /* check foreground option from command line to override config file */ |
|
165 |
+ for(j = 0; j < argc; j += 1) |
|
166 |
+ { |
|
167 |
+ if ((memcmp(argv[j], "--foreground", 12) == 0) || (memcmp(argv[j], "-F", 2) == 0)) |
|
168 |
+ { |
|
169 |
+ /* found */ |
|
170 |
+ break; |
|
171 |
+ } |
|
172 |
+ } |
|
173 |
+ |
|
174 |
+ if (j < argc) |
|
175 |
+ { |
|
176 |
+ if(optget(opts, "Foreground")->enabled) |
|
177 |
+ { |
|
178 |
+ foreground = 1; |
|
179 |
+ } |
|
180 |
+ else |
|
181 |
+ { |
|
182 |
+ foreground = 0; |
|
183 |
+ } |
|
184 |
+ } |
|
185 |
+ |
|
186 |
+ num_fd = sd_listen_fds(0); |
|
187 |
+ |
|
164 | 188 |
/* parse the config file */ |
165 | 189 |
cfgfile = optget(opts, "config-file")->strarg; |
166 | 190 |
pt = strdup(cfgfile); |
... | ... |
@@ -300,7 +326,9 @@ int main(int argc, char **argv) |
300 | 300 |
if(optget(opts, "LocalSocket")->enabled) |
301 | 301 |
localsock = 1; |
302 | 302 |
|
303 |
- if(!tcpsock && !localsock) { |
|
303 |
+ logg("#Received %d file descriptor(s) from systemd.\n", num_fd); |
|
304 |
+ |
|
305 |
+ if(!tcpsock && !localsock && num_fd == 0) { |
|
304 | 306 |
logg("!Please define server type (local and/or TCP).\n"); |
305 | 307 |
ret = 1; |
306 | 308 |
break; |
... | ... |
@@ -607,7 +635,9 @@ int main(int argc, char **argv) |
607 | 607 |
break; |
608 | 608 |
} |
609 | 609 |
|
610 |
- if(tcpsock) { |
|
610 |
+ if(tcpsock || num_fd > 0) { |
|
611 |
+ int *t; |
|
612 |
+ |
|
611 | 613 |
opt = optget(opts, "TCPAddr"); |
612 | 614 |
if (opt->enabled) { |
613 | 615 |
int breakout = 0; |
... | ... |
@@ -634,7 +664,7 @@ int main(int argc, char **argv) |
634 | 634 |
} |
635 | 635 |
} |
636 | 636 |
#ifndef _WIN32 |
637 |
- if(localsock) { |
|
637 |
+ if(localsock && num_fd == 0) { |
|
638 | 638 |
int *t; |
639 | 639 |
mode_t sock_mode, umsk = umask(0777); /* socket is created with 000 to avoid races */ |
640 | 640 |
|
... | ... |
@@ -696,8 +726,43 @@ int main(int argc, char **argv) |
696 | 696 |
nlsockets++; |
697 | 697 |
} |
698 | 698 |
|
699 |
+ /* check for local sockets passed by systemd */ |
|
700 |
+ if (num_fd > 0) |
|
701 |
+ { |
|
702 |
+ int *t; |
|
703 |
+ t = realloc(lsockets, sizeof(int) * (nlsockets + 1)); |
|
704 |
+ if (!(t)) { |
|
705 |
+ ret = 1; |
|
706 |
+ break; |
|
707 |
+ } |
|
708 |
+ lsockets = t; |
|
709 |
+ |
|
710 |
+ lsockets[nlsockets] = localserver(opts); |
|
711 |
+ if (lsockets[nlsockets] == -1) |
|
712 |
+ { |
|
713 |
+ ret = 1; |
|
714 |
+ break; |
|
715 |
+ } |
|
716 |
+ else if (lsockets[nlsockets] > 0) |
|
717 |
+ { |
|
718 |
+ nlsockets++; |
|
719 |
+ } |
|
720 |
+ } |
|
721 |
+ |
|
699 | 722 |
/* fork into background */ |
700 |
- if(!optget(opts, "Foreground")->enabled) { |
|
723 |
+ if (foreground == -1) |
|
724 |
+ { |
|
725 |
+ if (optget(opts, "Foreground")->enabled) |
|
726 |
+ { |
|
727 |
+ foreground = 1; |
|
728 |
+ } |
|
729 |
+ else |
|
730 |
+ { |
|
731 |
+ foreground = 0; |
|
732 |
+ } |
|
733 |
+ } |
|
734 |
+ if(foreground == 0) |
|
735 |
+ { |
|
701 | 736 |
#ifdef C_BSD |
702 | 737 |
/* workaround for OpenBSD bug, see https://wwws.clamav.net/bugzilla/show_bug.cgi?id=885 */ |
703 | 738 |
for(ret=0;(unsigned int)ret<nlsockets;ret++) { |
... | ... |
@@ -731,8 +796,6 @@ int main(int argc, char **argv) |
731 | 731 |
if(chdir("/") == -1) |
732 | 732 |
logg("^Can't change current working directory to root\n"); |
733 | 733 |
|
734 |
- } else { |
|
735 |
- foreground = 1; |
|
736 | 734 |
} |
737 | 735 |
#endif |
738 | 736 |
|
... | ... |
@@ -746,22 +809,24 @@ int main(int argc, char **argv) |
746 | 746 |
|
747 | 747 |
} while (0); |
748 | 748 |
|
749 |
- logg("*Closing the main socket%s.\n", (nlsockets > 1) ? "s" : ""); |
|
750 |
- |
|
751 |
- for (i = 0; i < nlsockets; i++) { |
|
752 |
- closesocket(lsockets[i]); |
|
753 |
- } |
|
749 |
+ if (num_fd == 0) |
|
750 |
+ { |
|
751 |
+ logg("*Closing the main socket%s.\n", (nlsockets > 1) ? "s" : ""); |
|
754 | 752 |
|
753 |
+ for (i = 0; i < nlsockets; i++) { |
|
754 |
+ closesocket(lsockets[i]); |
|
755 |
+ } |
|
755 | 756 |
#ifndef _WIN32 |
756 |
- if(nlsockets && localsock) { |
|
757 |
- opt = optget(opts, "LocalSocket"); |
|
757 |
+ if(nlsockets && localsock) { |
|
758 |
+ opt = optget(opts, "LocalSocket"); |
|
758 | 759 |
|
759 |
- if(unlink(opt->strarg) == -1) |
|
760 |
- logg("!Can't unlink the socket file %s\n", opt->strarg); |
|
761 |
- else |
|
762 |
- logg("Socket file removed.\n"); |
|
763 |
- } |
|
760 |
+ if(unlink(opt->strarg) == -1) |
|
761 |
+ logg("!Can't unlink the socket file %s\n", opt->strarg); |
|
762 |
+ else |
|
763 |
+ logg("Socket file removed.\n"); |
|
764 |
+ } |
|
764 | 765 |
#endif |
766 |
+ } |
|
765 | 767 |
|
766 | 768 |
free(lsockets); |
767 | 769 |
|
... | ... |
@@ -40,6 +40,7 @@ |
40 | 40 |
|
41 | 41 |
#include "shared/optparser.h" |
42 | 42 |
#include "shared/output.h" |
43 |
+#include "shared/misc.h" |
|
43 | 44 |
|
44 | 45 |
#include "others.h" |
45 | 46 |
#include "server.h" |
... | ... |
@@ -61,6 +62,39 @@ int localserver(const struct optstruct *opts) |
61 | 61 |
STATBUF foo; |
62 | 62 |
char *estr; |
63 | 63 |
|
64 |
+ int num_fd = sd_listen_fds(0); |
|
65 |
+ if (num_fd > 2) |
|
66 |
+ { |
|
67 |
+ logg("!LOCAL: Received more than two file descriptors from systemd.\n"); |
|
68 |
+ return -1; |
|
69 |
+ } |
|
70 |
+ else if (num_fd > 0) |
|
71 |
+ { |
|
72 |
+ /* use socket passed by systemd */ |
|
73 |
+ int i; |
|
74 |
+ for(i = 0; i < num_fd; i += 1) |
|
75 |
+ { |
|
76 |
+ sockfd = SD_LISTEN_FDS_START + i; |
|
77 |
+ if (sd_is_socket(sockfd, AF_UNIX, SOCK_STREAM, 1) == 1) |
|
78 |
+ { |
|
79 |
+ /* correct socket */ |
|
80 |
+ break; |
|
81 |
+ } |
|
82 |
+ else |
|
83 |
+ { |
|
84 |
+ /* wrong socket */ |
|
85 |
+ sockfd = -2; |
|
86 |
+ } |
|
87 |
+ } |
|
88 |
+ if (sockfd == -2) |
|
89 |
+ { |
|
90 |
+ logg("#LOCAL: No local AF_UNIX SOCK_STREAM socket received from systemd.\n"); |
|
91 |
+ return -2; |
|
92 |
+ } |
|
93 |
+ logg("#LOCAL: Received AF_UNIX SOCK_STREAM socket from systemd.\n"); |
|
94 |
+ return sockfd; |
|
95 |
+ } |
|
96 |
+ /* create socket */ |
|
64 | 97 |
memset((char *) &server, 0, sizeof(server)); |
65 | 98 |
server.sun_family = AF_UNIX; |
66 | 99 |
strncpy(server.sun_path, optget(opts, "LocalSocket")->strarg, sizeof(server.sun_path)); |
... | ... |
@@ -49,6 +49,7 @@ |
49 | 49 |
|
50 | 50 |
#include "shared/output.h" |
51 | 51 |
#include "shared/optparser.h" |
52 |
+#include "shared/misc.h" |
|
52 | 53 |
|
53 | 54 |
#include "onaccess_fan.h" |
54 | 55 |
#include "server.h" |
... | ... |
@@ -455,13 +456,19 @@ static void *acceptloop_th(void *arg) |
455 | 455 |
} |
456 | 456 |
pthread_mutex_unlock(fds->buf_mutex); |
457 | 457 |
|
458 |
- for (i=0;i < fds->nfds; i++) { |
|
459 |
- if (fds->buf[i].fd == -1) |
|
460 |
- continue; |
|
461 |
- logg("$Shutdown: closed fd %d\n", fds->buf[i].fd); |
|
462 |
- shutdown(fds->buf[i].fd, 2); |
|
463 |
- closesocket(fds->buf[i].fd); |
|
458 |
+ if (sd_listen_fds(0) == 0) |
|
459 |
+ { |
|
460 |
+ /* only close the sockets, when not using systemd socket activation */ |
|
461 |
+ for (i=0;i < fds->nfds; i++) |
|
462 |
+ { |
|
463 |
+ if (fds->buf[i].fd == -1) |
|
464 |
+ continue; |
|
465 |
+ logg("$Shutdown: closed fd %d\n", fds->buf[i].fd); |
|
466 |
+ shutdown(fds->buf[i].fd, 2); |
|
467 |
+ closesocket(fds->buf[i].fd); |
|
468 |
+ } |
|
464 | 469 |
} |
470 |
+ |
|
465 | 471 |
fds_free(fds); |
466 | 472 |
pthread_mutex_destroy(fds->buf_mutex); |
467 | 473 |
pthread_mutex_lock(&exit_mutex); |
... | ... |
@@ -1396,16 +1403,22 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi |
1396 | 1396 |
if (progexit) { |
1397 | 1397 |
pthread_mutex_unlock(&exit_mutex); |
1398 | 1398 |
pthread_mutex_lock(fds->buf_mutex); |
1399 |
- for (i=0;i < fds->nfds; i++) { |
|
1400 |
- if (fds->buf[i].fd == -1) |
|
1401 |
- continue; |
|
1402 |
- thrmgr_group_terminate(fds->buf[i].group); |
|
1403 |
- if (thrmgr_group_finished(fds->buf[i].group, EXIT_ERROR)) { |
|
1404 |
- logg("$Shutdown closed fd %d\n", fds->buf[i].fd); |
|
1405 |
- shutdown(fds->buf[i].fd, 2); |
|
1406 |
- closesocket(fds->buf[i].fd); |
|
1407 |
- fds->buf[i].fd = -1; |
|
1408 |
- } |
|
1399 |
+ if (sd_listen_fds(0) == 0) |
|
1400 |
+ { |
|
1401 |
+ /* only close the sockets, when not using systemd socket activation */ |
|
1402 |
+ for (i=0;i < fds->nfds; i++) |
|
1403 |
+ { |
|
1404 |
+ if (fds->buf[i].fd == -1) |
|
1405 |
+ continue; |
|
1406 |
+ thrmgr_group_terminate(fds->buf[i].group); |
|
1407 |
+ if (thrmgr_group_finished(fds->buf[i].group, EXIT_ERROR)) |
|
1408 |
+ { |
|
1409 |
+ logg("$Shutdown closed fd %d\n", fds->buf[i].fd); |
|
1410 |
+ shutdown(fds->buf[i].fd, 2); |
|
1411 |
+ closesocket(fds->buf[i].fd); |
|
1412 |
+ fds->buf[i].fd = -1; |
|
1413 |
+ } |
|
1414 |
+ } |
|
1409 | 1415 |
} |
1410 | 1416 |
pthread_mutex_unlock(fds->buf_mutex); |
1411 | 1417 |
break; |
... | ... |
@@ -1506,9 +1519,13 @@ int recvloop_th(int *socketds, unsigned nsockets, struct cl_engine *engine, unsi |
1506 | 1506 |
#endif |
1507 | 1507 |
if(dbstat.entries) |
1508 | 1508 |
cl_statfree(&dbstat); |
1509 |
- logg("*Shutting down the main socket%s.\n", (nsockets > 1) ? "s" : ""); |
|
1510 |
- for (i = 0; i < nsockets; i++) |
|
1511 |
- shutdown(socketds[i], 2); |
|
1509 |
+ if (sd_listen_fds(0) == 0) |
|
1510 |
+ { |
|
1511 |
+ /* only close the sockets, when not using systemd socket activation */ |
|
1512 |
+ logg("*Shutting down the main socket%s.\n", (nsockets > 1) ? "s" : ""); |
|
1513 |
+ for (i = 0; i < nsockets; i++) |
|
1514 |
+ shutdown(socketds[i], 2); |
|
1515 |
+ } |
|
1512 | 1516 |
|
1513 | 1517 |
if((opt = optget(opts, "PidFile"))->enabled) { |
1514 | 1518 |
if(unlink(opt->strarg) == -1) |
... | ... |
@@ -58,9 +58,60 @@ int tcpserver(int **lsockets, unsigned int *nlsockets, char *ipaddr, const struc |
58 | 58 |
int yes = 1; |
59 | 59 |
int res; |
60 | 60 |
unsigned int i=0; |
61 |
+ int num_fd; |
|
61 | 62 |
|
62 | 63 |
sockets = *lsockets; |
63 | 64 |
|
65 |
+ num_fd = sd_listen_fds(0); |
|
66 |
+ if (num_fd > 2) |
|
67 |
+ { |
|
68 |
+ logg("!TCP: Received more than two file descriptors from systemd.\n"); |
|
69 |
+ return -1; |
|
70 |
+ } |
|
71 |
+ else if (num_fd > 0) |
|
72 |
+ { |
|
73 |
+ /* use socket passed by systemd */ |
|
74 |
+ int i; |
|
75 |
+ for(i = 0; i < num_fd; i += 1) |
|
76 |
+ { |
|
77 |
+ sockfd = SD_LISTEN_FDS_START + i; |
|
78 |
+ if (sd_is_socket(sockfd, AF_INET, SOCK_STREAM, 1) == 1) |
|
79 |
+ { |
|
80 |
+ /* correct socket */ |
|
81 |
+ logg("#TCP: Received AF_INET SOCK_STREAM socket from systemd.\n"); |
|
82 |
+ break; |
|
83 |
+ } |
|
84 |
+ else if (sd_is_socket(sockfd, AF_INET6, SOCK_STREAM, 1) == 1) |
|
85 |
+ { |
|
86 |
+ /* correct socket */ |
|
87 |
+ logg("#TCP: Received AF_INET6 SOCK_STREAM socket from systemd.\n"); |
|
88 |
+ break; |
|
89 |
+ } |
|
90 |
+ else |
|
91 |
+ { |
|
92 |
+ /* wrong socket */ |
|
93 |
+ sockfd = -2; |
|
94 |
+ } |
|
95 |
+ } |
|
96 |
+ if (sockfd == -2) |
|
97 |
+ { |
|
98 |
+ logg("#TCP: No tcp AF_INET/AF_INET6 SOCK_STREAM socket received from systemd.\n"); |
|
99 |
+ return -2; |
|
100 |
+ } |
|
101 |
+ |
|
102 |
+ t = realloc(sockets, sizeof(int) * (*nlsockets + 1)); |
|
103 |
+ if (!(t)) { |
|
104 |
+ return -1; |
|
105 |
+ } |
|
106 |
+ sockets = t; |
|
107 |
+ |
|
108 |
+ sockets[*nlsockets] = sockfd; |
|
109 |
+ (*nlsockets)++; |
|
110 |
+ *lsockets = sockets; |
|
111 |
+ return 0; |
|
112 |
+ } |
|
113 |
+ |
|
114 |
+ /* create socket */ |
|
64 | 115 |
snprintf(port, sizeof(port), "%lld", optget(opts, "TCPSocket")->numarg); |
65 | 116 |
|
66 | 117 |
memset(&hints, 0x00, sizeof(struct addrinfo)); |
... | ... |
@@ -87,6 +87,7 @@ AM_MAINTAINER_MODE |
87 | 87 |
m4_include([m4/reorganization/libs/libz.m4]) |
88 | 88 |
m4_include([m4/reorganization/libs/bzip.m4]) |
89 | 89 |
m4_include([m4/reorganization/libs/unrar.m4]) |
90 |
+m4_include([m4/reorganization/libs/systemd.m4]) |
|
90 | 91 |
m4_include([m4/reorganization/code_checks/ipv6.m4]) |
91 | 92 |
m4_include([m4/reorganization/code_checks/dns.m4]) |
92 | 93 |
m4_include([m4/reorganization/code_checks/fanotify.m4]) |
... | ... |
@@ -139,9 +140,12 @@ clamscan/Makefile |
139 | 139 |
database/Makefile |
140 | 140 |
docs/Makefile |
141 | 141 |
clamd/Makefile |
142 |
+clamd/clamav-daemon.service |
|
143 |
+clamd/clamav-daemon.socket |
|
142 | 144 |
clamdscan/Makefile |
143 | 145 |
clamsubmit/Makefile |
144 | 146 |
clamav-milter/Makefile |
147 |
+freshclam/clamav-freshclam.service |
|
145 | 148 |
freshclam/Makefile |
146 | 149 |
sigtool/Makefile |
147 | 150 |
clamconf/Makefile |
... | ... |
@@ -49,6 +49,10 @@ freshclam_SOURCES = \ |
49 | 49 |
mirman.c \ |
50 | 50 |
mirman.h |
51 | 51 |
|
52 |
+if INSTALL_SYSTEMD_UNITS |
|
53 |
+systemdsystemunit_DATA = clamav-freshclam.service |
|
54 |
+endif |
|
55 |
+ |
|
52 | 56 |
AM_CFLAGS=@WERR_CFLAGS@ |
53 | 57 |
DEFS = @DEFS@ -DCL_NOTHREADS |
54 | 58 |
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/shared -I$(top_srcdir)/libclamav @SSL_CPPFLAGS@ @FRESHCLAM_CPPFLAGS@ @JSON_CPPFLAGS@ @PCRE_CPPFLAGS@ |
55 | 59 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,12 @@ |
0 |
+[Unit] |
|
1 |
+Description=ClamAV virus database updater |
|
2 |
+Documentation=man:freshclam(1) man:freshclam.conf(5) http://www.clamav.net/lang/en/doc/ |
|
3 |
+# If user wants it run from cron, don't start the daemon. |
|
4 |
+ConditionPathExists=!/etc/cron.d/clamav-freshclam |
|
5 |
+ |
|
6 |
+[Service] |
|
7 |
+ExecStart=@prefix@/bin/freshclam -d --foreground=true |
|
8 |
+StandardOutput=syslog |
|
9 |
+ |
|
10 |
+[Install] |
|
11 |
+WantedBy=multi-user.target |
... | ... |
@@ -64,7 +64,7 @@ |
64 | 64 |
static short terminate = 0; |
65 | 65 |
extern int active_children; |
66 | 66 |
|
67 |
-static short foreground = 1; |
|
67 |
+static short foreground = -1; |
|
68 | 68 |
char updtmpdir[512], dbdir[512]; |
69 | 69 |
int sigchld_wait = 1; |
70 | 70 |
const char *pidfile = NULL; |
... | ... |
@@ -117,7 +117,7 @@ sighandler (int sig) |
117 | 117 |
if (pidfile) |
118 | 118 |
unlink (pidfile); |
119 | 119 |
logg ("Update process terminated\n"); |
120 |
- exit (2); |
|
120 |
+ exit (0); |
|
121 | 121 |
} |
122 | 122 |
|
123 | 123 |
return; |
... | ... |
@@ -298,6 +298,7 @@ main (int argc, char **argv) |
298 | 298 |
#endif |
299 | 299 |
STATBUF statbuf; |
300 | 300 |
struct mirdat mdat; |
301 |
+ int j; |
|
301 | 302 |
|
302 | 303 |
if (check_flevel ()) |
303 | 304 |
exit (FCE_INIT); |
... | ... |
@@ -322,6 +323,25 @@ main (int argc, char **argv) |
322 | 322 |
return 0; |
323 | 323 |
} |
324 | 324 |
|
325 |
+ /* check foreground option from command line to override config file */ |
|
326 |
+ for(j = 0; j < argc; j += 1) |
|
327 |
+ { |
|
328 |
+ if ((memcmp(argv[j], "--foreground", 12) == 0) || (memcmp(argv[j], "-F", 2) == 0)) |
|
329 |
+ { |
|
330 |
+ /* found */ |
|
331 |
+ break; |
|
332 |
+ } |
|
333 |
+ } |
|
334 |
+ |
|
335 |
+ if (j < argc) { |
|
336 |
+ if(optget(opts, "Foreground")->enabled) { |
|
337 |
+ foreground = 1; |
|
338 |
+ } |
|
339 |
+ else { |
|
340 |
+ foreground = 0; |
|
341 |
+ } |
|
342 |
+ } |
|
343 |
+ |
|
325 | 344 |
/* parse the config file */ |
326 | 345 |
cfgfile = optget (opts, "config-file")->strarg; |
327 | 346 |
pt = strdup (cfgfile); |
... | ... |
@@ -638,7 +658,19 @@ main (int argc, char **argv) |
638 | 638 |
bigsleep = 24 * 3600 / checks; |
639 | 639 |
|
640 | 640 |
#ifndef _WIN32 |
641 |
- if (!optget (opts, "Foreground")->enabled) |
|
641 |
+ /* fork into background */ |
|
642 |
+ if (foreground == -1) |
|
643 |
+ { |
|
644 |
+ if (optget(opts, "Foreground")->enabled) |
|
645 |
+ { |
|
646 |
+ foreground = 1; |
|
647 |
+ } |
|
648 |
+ else |
|
649 |
+ { |
|
650 |
+ foreground = 0; |
|
651 |
+ } |
|
652 |
+ } |
|
653 |
+ if(foreground == 0) |
|
642 | 654 |
{ |
643 | 655 |
if (daemonize () == -1) |
644 | 656 |
{ |
... | ... |
@@ -646,7 +678,6 @@ main (int argc, char **argv) |
646 | 646 |
optfree (opts); |
647 | 647 |
return FCE_FAILEDUPDATE; |
648 | 648 |
} |
649 |
- foreground = 0; |
|
650 | 649 |
mprintf_disabled = 1; |
651 | 650 |
} |
652 | 651 |
#endif |
653 | 652 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,19 @@ |
0 |
+dnl Check for systemd-daemon |
|
1 |
+PKG_CHECK_MODULES(SYSTEMD, [libsystemd], [AC_DEFINE([HAVE_SYSTEMD],,[systemd is supported])], |
|
2 |
+ [PKG_CHECK_MODULES(SYSTEMD, [libsystemd-daemon], [AC_DEFINE([HAVE_SYSTEMD],,[systemd-daemon is supported])], [AC_MSG_RESULT([systemd is not supported])])]) |
|
3 |
+CLAMD_LIBS="$CLAMD_LIBS $SYSTEMD_LIBS" |
|
4 |
+CFLAGS="$CFLAGS $SYSTEMD_CFLAGS" |
|
5 |
+ |
|
6 |
+dnl Check for systemd system unit installation directory (see man 7 daemon) |
|
7 |
+AC_ARG_WITH([systemdsystemunitdir], AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files]),, [with_systemdsystemunitdir=auto]) |
|
8 |
+AS_IF([test "x$with_systemdsystemunitdir" = "xyes" -o "x$with_systemdsystemunitdir" = "xauto"], [ |
|
9 |
+ def_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd) |
|
10 |
+ AS_IF([test "x$def_systemdsystemunitdir" = "x"], |
|
11 |
+ [AS_IF([test "x$with_systemdsystemunitdir" = "xyes"], [AC_MSG_ERROR([systemd support requested but pkg-config unable to query systemd package])]) |
|
12 |
+ with_systemdsystemunitdir=no], |
|
13 |
+ [with_systemdsystemunitdir=$def_systemdsystemunitdir])]) |
|
14 |
+AS_IF([test "x$with_systemdsystemunitdir" != "xno"], |
|
15 |
+ [AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])]) |
|
16 |
+AM_CONDITIONAL(INSTALL_SYSTEMD_UNITS, [test "x$with_systemdsystemunitdir" != "xno"]) |
|
17 |
+AC_MSG_RESULT([checking for systemd system unit installation directory... $with_systemdsystemunitdir]) |
|
18 |
+ |
... | ... |
@@ -38,6 +38,14 @@ |
38 | 38 |
# endif |
39 | 39 |
#endif |
40 | 40 |
|
41 |
+#ifdef HAVE_SYSTEMD |
|
42 |
+# include <systemd/sd-daemon.h> |
|
43 |
+#else |
|
44 |
+# define sd_listen_fds(u) 0 |
|
45 |
+# define SD_LISTEN_FDS_START 3 |
|
46 |
+# define sd_is_socket(f, a, s, l) 1 |
|
47 |
+#endif |
|
48 |
+ |
|
41 | 49 |
#include <limits.h> |
42 | 50 |
|
43 | 51 |
#ifndef PATH_MAX |
... | ... |
@@ -276,7 +276,7 @@ const struct clam_option __clam_options[] = { |
276 | 276 |
|
277 | 277 |
{ "AllowAllMatchScan", NULL, 0, CLOPT_TYPE_BOOL, MATCH_BOOL, 1, NULL, 0, OPT_CLAMD, "Permit use of the ALLMATCHSCAN command.", "yes" }, |
278 | 278 |
|
279 |
- { "Foreground", NULL, 0, CLOPT_TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER, "Don't fork into background.", "no" }, |
|
279 |
+ { "Foreground", "foreground", 'F', CLOPT_TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM | OPT_MILTER, "Don't fork into background.", "no" }, |
|
280 | 280 |
|
281 | 281 |
{ "Debug", NULL, 0, CLOPT_TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMD | OPT_FRESHCLAM, "Enable debug messages in libclamav.", "no" }, |
282 | 282 |
|