From: Guillem Jover Date: Tue, 27 Nov 2012 13:24:13 +0000 (+0100) Subject: Implement sendmail semantics for setproctitle() X-Git-Tag: 0.5.0~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c984dacd65920b2f48cf0f4e579030488799f496;p=thirdparty%2Flibbsd.git Implement sendmail semantics for setproctitle() Prefix the title with "progname: ", and skip it if the format string starts with '-' (which gets skipped on output too). --- diff --git a/src/setproctitle.c b/src/setproctitle.c index 1817739..969f266 100644 --- a/src/setproctitle.c +++ b/src/setproctitle.c @@ -203,8 +203,18 @@ setproctitle(const char *fmt, ...) return; if (fmt) { + if (fmt[0] == '-') { + /* Skip program name prefix. */ + fmt++; + len = 0; + } else { + /* Print program name heading for grep. */ + snprintf(buf, sizeof(buf), "%s: ", getprogname()); + len = strlen(buf); + } + va_start(ap, fmt); - len = vsnprintf(buf, sizeof(buf), fmt, ap); + len += vsnprintf(buf + len, sizeof(buf) - len, fmt, ap); va_end(ap); } else { len = snprintf(buf, sizeof(buf), "%s", SPT.arg0);