[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#614959: libbsd: please implement setproctitle

Package: libbsd
Version: 0.2.0-1
Severity: wishlist
Tags: upstream


In libbsd, we find:

 setproctitle(const char *fmt, ...)
	/* Stub so that we can implement it later on and programs will
	 * automatically benefit from it, w/o needing to recompile. */

I would like to see a standard and clean implementation so Bug#24148
can be fixed more easily.  So here is a summary of existing practice.

Herbert mentioned sendmail, inn, and netstd as sample programs
implementing it.  I'd suggest grabbing the implementation from
postgresql, but maybe making it less portable and stripping out
some comments. ;-)

sendmail strategy
setproctitle and an init function are defined in sendmail/conf.c.

Compile-time parameter: SPT_TYPE.  Possible values:

 SPT_REUSEARGV		overwrite command line at argv[0] [e.g. linux, kfreebsd]
			move environ out of the way to make room
			pad with null bytes
 SPT_BUILTIN		call setproctitle() from libc [newish bsd]
 SPT_PSTAT		call pstat() from libc [hpux]
 SPT_PSSTRINGS		set PS_STRINGS->ps_argvstr [4.4bsd, old mac os x]
 SPT_SYSMIPS		call sysmips() from libc [sony news]
 SPT_SCO		write to u-area structure in kernel memory [sco?]
 SPT_CHANGEARGV		assign pointer to argv[0] [hurd]

It's nicely documented in sendmail/README.

inn2 strategy
inn2 is under the ISC license.

setproctitle and setproctitle_init are defined in lib/setproctitle.c.
Supported configurations:

 - HAVE_PSTAT [hpux]
 - everyone else.

In the "everyone else" case, it simply overwrites the area from
&argv[0][0] to &argv[argc-1][strlen(argv[argc-1])].  The only trick is
to start with "- " as a way of prepending the program name.

rdist strategy
In rdist 7.0.0-alpha10, it has a 3-clause BSD-style license from
MagniComp and 4-clause BSD-style license from UCB.  Presumably the
latter falls under the scope of the grand license change, but
someone would have to check.

setargs_settup and setproctitle are defined in src/setargs.c.

It first makes room for a longer command line by copying environ
and then overwrites the area from &argv[0][0] to
&envp[envlen-1][strlen(envp[envlen-1])].  Nice and clean.

linux-ftpd strategy
"Stolen from sendmail 8.7.4 and bashed around by David A. Holland"
Has a 4-clause BSD license from Allman and UCB.

Just like rdist's.  A little cleaner.

postgresql strategy
Very simple license (halfway between ISC and BSD-style)

 PS_USE_SETPROCTITLE	call setproctitle() from libc [newish bsd]
 PS_USE_PSTAT		call pstat(PSTAT_SETCMD, ) [hpux]
 PS_USE_PS_STRINGS	assign PS_STRINGS->ps_argvstr = "str" [some bsd]
 PS_USE_CHANGE_ARGV	assign argv[0] = "str" [hurd, other bsd]
 PS_USE_CLOBBER_ARGV	write over argv and environment area [linux, most sysv-like]
 PS_USE_WIN32		... blah blah ...

When clobbering at argv[0], uses null bytes for padding on Linux,
AIX, svr4, and Darwin, spaces elsewhere.

libiberty strategy
/* On Linux this sets the top visible "comm", but not necessarily
   the name visible in ps. */
prctl(PR_SET_NAME, "string");

python-setproctitle strategy
Like postgresql, but calls prctl like liberty on top of that.

Hope that helps,

Reply to: