]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
Implement sendmail semantics for setproctitle()
authorGuillem Jover <guillem@hadrons.org>
Tue, 27 Nov 2012 13:24:13 +0000 (14:24 +0100)
committerGuillem Jover <guillem@hadrons.org>
Mon, 27 May 2013 01:24:20 +0000 (03:24 +0200)
Prefix the title with "progname: ", and skip it if the format string
starts with '-' (which gets skipped on output too).

src/setproctitle.c

index 18177399879c9110d418e1ab2b65285a23c86dc7..969f2665ebb8f6e3ecce351b83f1253dc64c54ab 100644 (file)
@@ -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);