diff options
author | Stef Walter <stef@memberwebs.com> | 2004-09-23 23:36:46 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2004-09-23 23:36:46 +0000 |
commit | 7d9b8da3c4473b0be8ce6a6bb5afffd9d28dd755 (patch) | |
tree | 57b3b7d2a51ecafecfb6d3b35339b738d5e64e16 | |
parent | 58e0f4b3ee454a6ca561e007901df978ee636a4d (diff) |
PidFile in the config file support
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | common/smtppass.c | 41 | ||||
-rw-r--r-- | common/sppriv.h | 1 | ||||
-rw-r--r-- | doc/clamsmtpd.conf.5 | 11 |
4 files changed, 40 insertions, 14 deletions
@@ -1,5 +1,6 @@ 0.9.1 - Fixed problems with the select zeroing out timeouts. + - Added support for setting the PidFile from the config file 0.9 - Don't quit when too many threads created diff --git a/common/smtppass.c b/common/smtppass.c index 468991a..22dc06e 100644 --- a/common/smtppass.c +++ b/common/smtppass.c @@ -142,6 +142,7 @@ spthread_t; #define CFG_TRANSPARENT "TransparentProxy" #define CFG_DIRECTORY "TempDirectory" #define CFG_USER "User" +#define CFG_PIDFILE "PidFile" /* ----------------------------------------------------------------------- * DEFAULT SETTINGS @@ -168,7 +169,7 @@ pthread_mutexattr_t g_mtxattr; static void on_quit(int signal); static void drop_privileges(); -static void pid_file(const char* pidfile, int write); +static void pid_file(int write); static void connection_loop(int sock); static void* thread_main(void* arg); static int smtp_passthru(spctx_t* ctx); @@ -224,6 +225,7 @@ int sp_run(const char* configfile, const char* pidfile, int dbg_level) if(!(dbg_level == -1 || dbg_level <= LOG_DEBUG)) errx(2, "invalid debug log level (must be between 1 and 4)"); g_state.debug_level = dbg_level; + g_state.pidfile = pidfile; /* Now parse the configuration file */ if(parse_config_file(configfile) == -1) @@ -306,15 +308,13 @@ int sp_run(const char* configfile, const char* pidfile, int dbg_level) siginterrupt(SIGINT, 1); siginterrupt(SIGTERM, 1); - if(pidfile) - pid_file(pidfile, 1); + pid_file(1); sp_messagex(NULL, LOG_DEBUG, "accepting connections"); connection_loop(sock); - if(pidfile) - pid_file(pidfile, 0); + pid_file(0); /* Our listen socket */ close(sock); @@ -390,33 +390,36 @@ static void drop_privileges() } -static void pid_file(const char* pidfile, int write) +static void pid_file(int write) { + if(!g_state.pidfile) + return; + if(write) { - FILE* f = fopen(pidfile, "w"); + FILE* f = fopen(g_state.pidfile, "w"); if(f == NULL) { - sp_message(NULL, LOG_ERR, "couldn't open pid file: %s", pidfile); + sp_message(NULL, LOG_ERR, "couldn't open pid file: %s", g_state.pidfile); } else { fprintf(f, "%d\n", (int)getpid()); if(ferror(f)) - sp_message(NULL, LOG_ERR, "couldn't write to pid file: %s", pidfile); + sp_message(NULL, LOG_ERR, "couldn't write to pid file: %s", g_state.pidfile); if(fclose(f) == EOF) - sp_message(NULL, LOG_ERR, "couldn't write to pid file: %s", pidfile); + sp_message(NULL, LOG_ERR, "couldn't write to pid file: %s", g_state.pidfile); } - sp_messagex(NULL, LOG_DEBUG, "wrote pid file: %s", pidfile); + sp_messagex(NULL, LOG_DEBUG, "wrote pid file: %s", g_state.pidfile); } else { - unlink(pidfile); - sp_messagex(NULL, LOG_DEBUG, "removed pid file: %s", pidfile); + unlink(g_state.pidfile); + sp_messagex(NULL, LOG_DEBUG, "removed pid file: %s", g_state.pidfile); } } @@ -1587,6 +1590,18 @@ int sp_parse_option(const char* name, const char* value) ret = 1; } + else if(strcasecmp(CFG_PIDFILE, name) == 0) + { + if(g_state.pidfile != NULL) + sp_messagex(NULL, LOG_WARNING, "ignoring pid file specified on the command line. "); + + if(strlen(value) == 0) + g_state.pidfile = NULL; + else + g_state.pidfile = value; + ret = 1; + } + /* Always pass through to program */ if(cb_parse_option(name, value) == 1) ret = 1; diff --git a/common/sppriv.h b/common/sppriv.h index 30686f9..cc6590a 100644 --- a/common/sppriv.h +++ b/common/sppriv.h @@ -50,6 +50,7 @@ typedef struct spstate int transparent; /* Transparent proxying */ const char* directory; /* The temp directory */ const char* user; /* User to run as */ + const char* pidfile; /* The pid file for daemon */ struct sockaddr_any outaddr; /* The outgoing address */ const char* outname; diff --git a/doc/clamsmtpd.conf.5 b/doc/clamsmtpd.conf.5 index f528eb9..e481af9 100644 --- a/doc/clamsmtpd.conf.5 +++ b/doc/clamsmtpd.conf.5 @@ -86,6 +86,14 @@ on. See syntax of addresses below. The address and port to listen for SMTP connections on. See syntax of addresses below. [ Default: port 10025 on all local IP addresses ] +.It Ar PidFile +Specifies a location for the a process id file to be written to. This file +contains the process id of +.Nm +and can be used to stop the daemon. If the +.Fl p +argument is passed on the command line, then this setting will be ignored. +[ Default: none ] .It Ar Quarantine Quarantine files that contain viruses by leaving them in the .Ar TempDirectory @@ -101,7 +109,7 @@ also needs to be setup to accept at least this number of connections. .It Ar ScanHeader A header to add to scanned messages. Put an empty value to supress adding a header. -[ Default: 'X-AV-Checked: ClamAV using ClamSMTP' ] +[ Default: 'X-Virus-Scanned: ClamAV using ClamSMTP' ] .It Ar OutAddress The address of the SMTP server to send email to once it's been scanned. See syntax of addreses below. @@ -133,6 +141,7 @@ This is a command to run when a virus is found. See the VIRUS ACTION section in .Xr clamsmtpd 8 for a discussion of this option. +[ Default: off ] .El .Sh ADDRESSES Addresses can be specified in multiple formats: |