summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-12-21 19:21:37 +0300
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-12-21 19:21:37 +0300
commita079dac866ac4e166a8d6e40f978af74e8398583 (patch)
treed5cf47d5b7bf9414748c11d313251644dacc3be0
parentc6e6ea88a2e03609b0be013d2df0de1c6062712f (diff)
downloadrspamd-a079dac866ac4e166a8d6e40f978af74e8398583.tar.gz
rspamd-a079dac866ac4e166a8d6e40f978af74e8398583.zip
* Add ability to specify pid file from command line (for rc scripts)
* Do not use flock directly in pidfile handling
-rw-r--r--src/cfg_file.y5
-rw-r--r--src/main.c14
-rw-r--r--src/util.c8
3 files changed, 21 insertions, 6 deletions
diff --git a/src/cfg_file.y b/src/cfg_file.y
index a4f7034d0..91c40a734 100644
--- a/src/cfg_file.y
+++ b/src/cfg_file.y
@@ -122,7 +122,10 @@ tempdir :
pidfile :
PIDFILE EQSIGN QUOTEDSTRING {
- cfg->pid_file = $3;
+ if (cfg->pid_file == NULL) {
+ /* Allow override this value from command line */
+ cfg->pid_file = $3;
+ }
}
;
diff --git a/src/main.c b/src/main.c
index dd17b98d1..fa861b86f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -157,7 +157,7 @@ static void
read_cmd_line (int argc, char **argv, struct config_file *cfg)
{
int ch;
- while ((ch = getopt (argc, argv, "tVChfc:u:g:")) != -1) {
+ while ((ch = getopt (argc, argv, "tVChfc:u:g:p:")) != -1) {
switch (ch) {
case 'f':
cfg->no_fork = 1;
@@ -186,6 +186,11 @@ read_cmd_line (int argc, char **argv, struct config_file *cfg)
cfg->rspamd_group = memory_pool_strdup (cfg->cfg_pool, optarg);
}
break;
+ case 'p':
+ if (optarg) {
+ cfg->pid_file = memory_pool_strdup (cfg->cfg_pool, optarg);
+ }
+ break;
case 'h':
case '?':
default:
@@ -197,7 +202,11 @@ read_cmd_line (int argc, char **argv, struct config_file *cfg)
"-C: Dump symbols cache stats and exit\n"
"-V Print all rspamd variables and exit\n"
"-f: Do not daemonize main process\n"
- "-c: Specify config file (./rspamd.conf is used by default)\n" "-u: User to run rspamd as\n" "-g: Group to run rspamd as\n");
+ "-c: Specify config file (./rspamd.conf is used by default)\n"
+ "-u: User to run rspamd as\n"
+ "-g: Group to run rspamd as\n"
+ "-p: Path to pidfile\n"
+ );
exit (0);
break;
}
@@ -753,7 +762,6 @@ main (int argc, char **argv, char **env)
init_signals (&signals, sig_handler);
-
if (write_pid (rspamd) == -1) {
msg_err ("main: cannot write pid file %s", rspamd->cfg->pid_file);
exit (-errno);
diff --git a/src/util.c b/src/util.c
index b3e4f7e68..5c16fa917 100644
--- a/src/util.c
+++ b/src/util.c
@@ -296,6 +296,10 @@ int
write_pid (struct rspamd_main *main)
{
pid_t pid;
+
+ if (main->cfg->pid_file == NULL) {
+ return -1;
+ }
main->pfh = pidfile_open (main->cfg->pid_file, 0644, &pid);
if (main->pfh == NULL) {
@@ -568,7 +572,7 @@ pidfile_open (const char *path, mode_t mode, pid_t * pidptr)
* pidfile_write() can be called multiple times.
*/
fd = open (pfh->pf_path, O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, mode);
- flock (fd, LOCK_EX | LOCK_NB);
+ lock_file (fd, TRUE);
if (fd == -1) {
count = 0;
rqtp.tv_sec = 0;
@@ -682,7 +686,7 @@ _pidfile_remove (struct pidfh *pfh, int freeit)
if (unlink (pfh->pf_path) == -1)
error = errno;
- if (flock (pfh->pf_fd, LOCK_UN) == -1) {
+ if (! unlock_file (pfh->pf_fd, FALSE)) {
if (error == 0)
error = errno;
}