Bug#614959: libbsd: please implement setproctitle
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. ;-)
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 [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 [hurd]
It's nicely documented in sendmail/README.
inn2 is under the ISC license.
setproctitle and setproctitle_init are defined in lib/setproctitle.c.
- HAVE_PSTAT [hpux]
- everyone else.
In the "everyone else" case, it simply overwrites the area from
&argv to &argv[argc-1][strlen(argv[argc-1])]. The only trick is
to start with "- " as a way of prepending the program name.
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 to
&envp[envlen-1][strlen(envp[envlen-1])]. Nice and clean.
"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.
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 = "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, uses null bytes for padding on Linux,
AIX, svr4, and Darwin, spaces elsewhere.
/* On Linux this sets the top visible "comm", but not necessarily
the name visible in ps. */
Like postgresql, but calls prctl like liberty on top of that.
Hope that helps,