Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 2 Mar 2016 19:10:40 +0000 (UTC)
From:      "Conrad E. Meyer" <cem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r296321 - head/usr.sbin/daemon
Message-ID:  <201603021910.u22JAe6F016954@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: cem
Date: Wed Mar  2 19:10:39 2016
New Revision: 296321
URL: https://svnweb.freebsd.org/changeset/base/296321

Log:
  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

Modified:
  head/usr.sbin/daemon/daemon.8
  head/usr.sbin/daemon/daemon.c

Modified: head/usr.sbin/daemon/daemon.8
==============================================================================
--- head/usr.sbin/daemon/daemon.8	Wed Mar  2 18:46:17 2016	(r296320)
+++ head/usr.sbin/daemon/daemon.8	Wed Mar  2 19:10:39 2016	(r296321)
@@ -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

Modified: head/usr.sbin/daemon/daemon.c
==============================================================================
--- head/usr.sbin/daemon/daemon.c	Wed Mar  2 18:46:17 2016	(r296320)
+++ head/usr.sbin/daemon/daemon.c	Wed Mar  2 19:10:39 2016	(r296321)
@@ -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 @@ restart:
 		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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201603021910.u22JAe6F016954>