From 948bcf1db8aca0b500174d487da3bcf3977838eb Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Sat, 13 Jul 2013 02:11:20 +0200 Subject: [PATCH] Warn when setproctitle() gets called before initialization Try to give a helpful message in case the program is not initializing the setproctitle() machinery. --- src/setproctitle.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/setproctitle.c b/src/setproctitle.c index 305b563..11d8f7a 100644 --- a/src/setproctitle.c +++ b/src/setproctitle.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -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] == '-') { -- 2.47.2