From b9454e9f1c3522dbb5e1aa87ccde4f0bd745007a Mon Sep 17 00:00:00 2001 From: Georg Pfuetzenreuter Date: Fri, 22 Apr 2022 08:07:45 +0000 Subject: [PATCH] Repair setproctitle (libbsd) Signed-off-by: Georg Pfuetzenreuter --- daemon.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/daemon.c b/daemon.c index 665a4f7..6dcb17a 100644 --- a/daemon.c +++ b/daemon.c @@ -40,6 +40,8 @@ #include #include #include +#include +#include #include "daemon.h" @@ -212,13 +214,14 @@ static void setTitle(void) { for (size_t i = 0; i < services.len; ++i) { if (services.ptr[i].state == Start) started++; } - // throws warning about missing setproctitle_init, even if linked against libbsd-ctor - //setproctitle("%zu/%zu services", started, services.len); + // this works now, but breaks syslog identifier + //setproctitle("%zu/%zu cats", started, services.len); } -int main(int argc, char *argv[]) { +int main(int argc, char *argv[], char *envp[]) { int error; openlog(getprogname(), LOG_NDELAY | LOG_PID | LOG_PERROR, LOG_DAEMON); + syslog(LOG_NOTICE, "Starting %s ...", getprogname()); bool daemonize = true; setAdd(&stopExits, EX_USAGE); @@ -276,6 +279,8 @@ int main(int argc, char *argv[]) { setgid(serviceGID); setuid(serviceUID); + setproctitle_init(argc, argv, envp); + int len = asprintf(&serviceEnviron[USER], "USER=%s", user->pw_name); if (len < 0) err(EX_OSERR, "asprintf"); @@ -465,8 +470,7 @@ shutdown: close(fifo); unlink(fifoPath); - // same as with previous occurance - //setproctitle("stopping"); + setproctitle("stopping"); size_t count = 0; for (size_t i = 0; i < services.len; ++i) { serviceStop(&services.ptr[i]);