]> mj.ucw.cz Git - libucw.git/commitdiff
Let setproctitle() recalculate program_invocation_name
authorMartin Mares <mj@ucw.cz>
Fri, 19 Aug 2011 15:17:45 +0000 (17:17 +0200)
committerMartin Mares <mj@ucw.cz>
Fri, 19 Aug 2011 15:17:45 +0000 (17:17 +0200)
Otherwise, syslog() and other functions which try to log the name
of the current programs are confused.

ucw/proctitle.c

index 30e8c05d1b89915fb6020eab98bbc3528771b246..c1f8ff78c00e1ee74d7367a8b6846285582f5bf3 100644 (file)
@@ -13,6 +13,7 @@
 #include <string.h>
 #include <stdarg.h>
 #include <unistd.h>
+#include <errno.h>
 
 static char **spt_argv;
 static char *spt_start, *spt_end;
@@ -50,6 +51,15 @@ setproctitle_init(int argc, char **argv)
   for (i=0; oldenv[i]; i++)
     if (spt_end+1 == oldenv[i])
       spt_end = oldenv[i] + strlen(oldenv[i]);
+
+  /* Recalculate program_invocation_name, otherwise syslog() will be confused. */
+  char *name = xstrdup(argv[0]);
+  program_invocation_name = name;
+  char *p = strrchr(name, '/');
+  if (p)
+    program_invocation_short_name = p + 1;
+  else
+    program_invocation_short_name = name;
 #endif
 }