[Nut-upsdev] Tiny suggestion for upslog.c
Andy Juniper
ajuniper at freeuk.com
Tue Dec 9 00:07:32 UTC 2014
Hi
Thanks for a very nice piece of software.
I have a tiny suggestion for upslog.c.
It adds a signal handler for the USR1 signal, which simply triggers it
to abort the current sleep and log the requested now.
I find it useful because my upssched-cmd can then killall -USR1 upslog
to ensure that there is an entry in the log for brief power dropouts
which would otherwise be unrecorded (because the power is only off for a
few seconds).
I think that the patch is still valid against the latest source in GIT
but was originally coded against 2.2.x.
thanks
Andy
--- nut-2.6.5/clients/upslog.c 2014-12-08 23:23:33.274059582 +0000
+++ nut-2.6.5/clients/upslog.c 2014-12-08 23:24:02.906586228 +0000
@@ -76,6 +76,11 @@
exit_flag = sig;
}
+static void set_print_now_flag(int sig)
+{
+ /* no need to do anything, the signal will cause sleep to be
interrupted */
+}
+
/* handlers: reload on HUP, exit on INT/QUIT/TERM */
static void setup_signals(void)
{
@@ -96,6 +101,11 @@
fatal_with_errno(EXIT_FAILURE, "Can't install SIGQUIT handler");
if (sigaction(SIGTERM, &sa, NULL) < 0)
fatal_with_errno(EXIT_FAILURE, "Can't install SIGTERM handler");
+
+ sa.sa_handler = set_print_now_flag;
+ if (sigaction(SIGUSR1, &sa, NULL) < 0)
+ fatal_with_errno(EXIT_FAILURE, "Can't install SIGTERM handler");
+
}
static void help(const char *prog)
More information about the Nut-upsdev
mailing list