diff --git a/usr.sbin/daemon/daemon.8.ORI b/usr.sbin/daemon/daemon.8 --- a/usr.sbin/daemon/daemon.8.ORI +++ b/usr.sbin/daemon/daemon.8 @@ -35,6 +35,7 @@ .Op Fl cfHrS .Op Fl p Ar child_pidfile .Op Fl P Ar supervisor_pidfile +.Op Fl x Ar command_pidfile .Op Fl t Ar title .Op Fl u Ar user .Op Fl m Ar output_mask @@ -156,6 +157,21 @@ locked and removes it after the process exits. The .Ar child_pidfile +owner is the user who runs the +.Nm +regardless of whether the +.Fl -user +option is used or not. +.It Fl x , Fl -command-pidfile Ar command_pidfile +Write the ID of the executed command into the +.Ar command_pidfile +using the +.Xr pidfile 3 +functionality. This is similar to the +.Fl -child-pidfile +option but without its +supervisor functionality. The +.Ar command_pidfile owner is the user who runs the .Nm regardless of whether the diff --git a/usr.sbin/daemon/daemon.c.ORI b/usr.sbin/daemon/daemon.c --- a/usr.sbin/daemon/daemon.c.ORI +++ b/usr.sbin/daemon/daemon.c @@ -114,7 +114,7 @@ static bool daemon_is_child_dead(struct daemon_state *); static void daemon_set_child_pipe(struct daemon_state *); -static const char shortopts[] = "+cfHSp:P:ru:o:s:l:t:m:R:T:C:h"; +static const char shortopts[] = "+cfHSp:P:ru:o:s:l:t:m:R:T:C:x:h"; static const struct option longopts[] = { { "change-dir", no_argument, NULL, 'c' }, @@ -125,6 +125,7 @@ { "output-mask", required_argument, NULL, 'm' }, { "child-pidfile", required_argument, NULL, 'p' }, { "supervisor-pidfile", required_argument, NULL, 'P' }, + { "command-pidfile", required_argument, NULL, 'x' }, { "restart", no_argument, NULL, 'r' }, { "restart-count", required_argument, NULL, 'C' }, { "restart-delay", required_argument, NULL, 'R' }, @@ -142,7 +143,7 @@ { (void)fprintf(stderr, "usage: daemon [-cfHrS] [-p child_pidfile] [-P supervisor_pidfile]\n" - " [-u user] [-o output_file] [-t title]\n" + " [-x command_pidfile ] [-u user] [-o output_file] [-t title]\n" " [-l syslog_facility] [-s syslog_priority]\n" " [-T syslog_tag] [-m output_mask] [-R restart_delay_secs]\n" " [-C restart_count]\n" @@ -158,6 +159,7 @@ " 1=stdout, 2=stderr, 3=both\n" " --child-pidfile -p Write PID of the child process to file\n" " --supervisor-pidfile -P Write PID of the supervisor process to file\n" + " --command-pidfile -x Write PID of the executed command to file\n" " --restart -r Restart child if it terminates (1 sec delay)\n" " --restart-count -C Restart child at most N times, then exit\n" " --restart-delay -R Restart child if it terminates after N sec\n" @@ -186,6 +188,8 @@ /* * Supervision mode is enabled if one of the following options are used: + * --syslog-facility -l + * --output-file -o * --child-pidfile -p * --supervisor-pidfile -P * --restart -r / --restart-delay -R @@ -288,6 +292,9 @@ break; case 'u': state.user = optarg; + break; + case 'x': + state.child_pidfile = optarg; break; case 'h': usage(0);