From a09150a061203c3439f2c30ef6ce3cce7ac51c9e Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Thu, 2 Aug 2018 15:37:02 +0200 Subject: [PATCH] Touch PID file on SIGHUP to ACK signal When used with Finit a daemon is expected to acknowledge SIGHUP by touching its PID file. Finit can do this by itself, however, but having native support for this in sysklgod is highly useful. Signed-off-by: Joachim Nilsson --- pidfile.c | 10 ++++++++++ pidfile.h | 7 +++++++ syslogd.c | 7 +++++++ 3 files changed, 24 insertions(+) diff --git a/pidfile.c b/pidfile.c index e0959a0..cf53b49 100644 --- a/pidfile.c +++ b/pidfile.c @@ -118,6 +118,16 @@ int write_pid (char *pidfile) return pid; } +/* touch_pid + * + * Touches the specified pidfile f.ex. when receiving a SIGHUP + * The result from utimensat() is returned + */ +int touch_pid (char *pidfile) +{ + return utimensat(0, pidfile, NULL, 0); +} + /* remove_pid * * Remove the the specified file. The result from unlink(2) diff --git a/pidfile.h b/pidfile.h index 19d19c1..8f1e490 100644 --- a/pidfile.h +++ b/pidfile.h @@ -42,6 +42,13 @@ int check_pid (char *pidfile); */ int write_pid (char *pidfile); +/* touch_pid + * + * Touches the specified pidfile f.ex. when receiving a SIGHUP + * The result from utimensat() is returned + */ +int touch_pid (char *pidfile); + /* remove_pid * * Remove the the specified file. The result from unlink(2) diff --git a/syslogd.c b/syslogd.c index a176371..8553f15 100644 --- a/syslogd.c +++ b/syslogd.c @@ -1161,6 +1161,13 @@ int main(argc, argv) restart = 0; dprintf("\nReceived SIGHUP, reloading syslogd.\n"); init(); + if (check_pid(PidFile)) { + if (touch_pid(PidFile)) + logerror("Not possible to touch pidfile"); + } else { + if (!write_pid(PidFile)) + logerror("Failed to write pidfile"); + } continue; } if (nfds == 0) {