]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
Warn when setproctitle() gets called before initialization
authorGuillem Jover <guillem@hadrons.org>
Sat, 13 Jul 2013 00:11:20 +0000 (02:11 +0200)
committerGuillem Jover <guillem@hadrons.org>
Sun, 14 Jul 2013 11:34:07 +0000 (13:34 +0200)
Try to give a helpful message in case the program is not initializing
the setproctitle() machinery.

src/setproctitle.c

index 305b563455c0c616622d573839261d5252e22b11..11d8f7ae52ad4731faa889e3dced1c8f4d3582d3 100644 (file)
@@ -28,6 +28,7 @@
 #include <stdbool.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <err.h>
 #include <unistd.h>
 #include <string.h>
 
@@ -41,6 +42,7 @@ static struct {
         /* Pointer to original nul character within base. */
        char *nul;
 
+       bool warned;
        bool reset;
        int error;
 } SPT;
@@ -228,8 +230,14 @@ setproctitle_impl(const char *fmt, ...)
        char *nul;
        int len;
 
-       if (SPT.base == NULL)
+       if (SPT.base == NULL) {
+               if (!SPT.warned) {
+                       warnx("setproctitle not initialized, please either call "
+                             "setproctitle_init() or link against libbsd-ctor.");
+                       SPT.warned = true;
+               }
                return;
+       }
 
        if (fmt) {
                if (fmt[0] == '-') {