Warn when setproctitle() gets called before initialization

Try to give a helpful message in case the program is not initializing
the setproctitle() machinery.
This commit is contained in:
Guillem Jover 2013-07-13 02:11:20 +02:00
parent c5b9590287
commit 948bcf1db8

View File

@ -28,6 +28,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <err.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
@ -41,6 +42,7 @@ static struct {
/* Pointer to original nul character within base. */ /* Pointer to original nul character within base. */
char *nul; char *nul;
bool warned;
bool reset; bool reset;
int error; int error;
} SPT; } SPT;
@ -228,8 +230,14 @@ setproctitle_impl(const char *fmt, ...)
char *nul; char *nul;
int len; 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; return;
}
if (fmt) { if (fmt) {
if (fmt[0] == '-') { if (fmt[0] == '-') {