Bug 39303 - please implement setproctitle
Summary: please implement setproctitle
Status: RESOLVED FIXED
Alias: None
Product: libbsd
Classification: Unclassified
Component: libbsd (show other bugs)
Version: unspecified
Hardware: All Linux (All)
: medium enhancement
Assignee: Guillem Jover
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-17 05:55 UTC by Malte S. Stretz
Modified: 2013-05-27 19:18 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Malte S. Stretz 2011-07-17 05:55:40 UTC
This was originally reported to the Debian bug tracker by Jonathan Nieder at <http://bugs.debian.org/614959>; I just copy and paste his research here.  (The referenced bug 24148 is a request to add setproctitle to libc <http://bugs.debian.org/24148>.)

-------------------------------------------------------------------

Hi,

In libbsd, we find:

 void
 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 ...
 PS_USE_NONE

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,
Jonathan
Comment 2 Guillem Jover 2012-11-28 14:45:42 UTC
(In reply to comment #1)
> Related downstream bugs:
> http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=614959
> https://bugs.launchpad.net/ubuntu/+source/libbsd/+bug/1058123
> http://bugs.winehq.org/show_bug.cgi?id=26550

I've imported now locally what seems like a suitable implementation. Will be included in libbsd 0.5.x.
Comment 3 Guillem Jover 2013-05-27 19:18:47 UTC
Fixed in libbsd 0.5.0, although there seems to be some issues on some systems, but that will be tracked in bug 65029.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.