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 /common | |
parent | 58e0f4b3ee454a6ca561e007901df978ee636a4d (diff) |
PidFile in the config file support
Diffstat (limited to 'common')
-rw-r--r-- | common/smtppass.c | 41 | ||||
-rw-r--r-- | common/sppriv.h | 1 |
2 files changed, 29 insertions, 13 deletions
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; |