daemon(8): Add -t option to set process title

The default process title is taken from the argv[0] value (any
particular hardlink name).  Add a -t option to override the default.

PR:		205016
Submitted by:	Yuri <yuri@rawbw.com>
No objection from:	freebsd-current@
Sponsored by:	EMC / Isilon Storage Division
This commit is contained in:
Conrad Meyer 2016-03-02 19:10:39 +00:00
parent 5db9ed8062
commit 112bfcf5e4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=296321
2 changed files with 16 additions and 6 deletions

View File

@ -26,7 +26,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd September 13, 2013
.Dd March 2, 2016
.Dt DAEMON 8
.Os
.Sh NAME
@ -37,6 +37,7 @@
.Op Fl cfr
.Op Fl p Ar child_pidfile
.Op Fl P Ar supervisor_pidfile
.Op Fl t Ar title
.Op Fl u Ar user
.Ar command arguments ...
.Sh DESCRIPTION
@ -94,6 +95,8 @@ regardless of whether the
option is used or not.
.It Fl r
Supervise and restart the program if it has been terminated.
.It Fl t Ar title
Process title for the daemon to make it easily identifiable.
.It Fl u Ar user
Login name of the user to execute the program under.
Requires adequate superuser privileges.
@ -123,7 +126,8 @@ option is useful combined with the
option as
.Ar supervisor_pidfile
contains the ID of the supervisor
not the child. This is especially important if you use
not the child.
This is especially important if you use
.Fl r
in an rc script as the
.Fl p

View File

@ -56,13 +56,13 @@ main(int argc, char *argv[])
struct pidfh *ppfh, *pfh;
sigset_t mask, oldmask;
int ch, nochdir, noclose, restart, serrno;
const char *pidfile, *ppidfile, *user;
const char *pidfile, *ppidfile, *title, *user;
pid_t otherpid, pid;
nochdir = noclose = 1;
restart = 0;
ppidfile = pidfile = user = NULL;
while ((ch = getopt(argc, argv, "cfp:P:ru:")) != -1) {
ppidfile = pidfile = title = user = NULL;
while ((ch = getopt(argc, argv, "cfp:P:rt:u:")) != -1) {
switch (ch) {
case 'c':
nochdir = 0;
@ -79,6 +79,9 @@ main(int argc, char *argv[])
case 'r':
restart = 1;
break;
case 't':
title = optarg;
break;
case 'u':
user = optarg;
break;
@ -204,7 +207,10 @@ main(int argc, char *argv[])
err(1, "%s", argv[0]);
}
setproctitle("%s[%d]", argv[0], pid);
if (title != NULL)
setproctitle("%s[%d]", title, pid);
else
setproctitle("%s[%d]", argv[0], pid);
if (wait_child(pid, &mask) == 0 && restart) {
sleep(1);
goto restart;