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;
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:
"-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;
}
init_signals (&signals, sig_handler);
-
if (write_pid (rspamd) == -1) {
msg_err ("main: cannot write pid file %s", rspamd->cfg->pid_file);
exit (-errno);
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) {
* 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;
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;
}