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)
Hi Andy, On Dec 8, 2014, at 7:07 PM, Andy Juniper <ajuniper at freeuk.com> wrote:> It adds a signal handler for the USR1 signal, which simply triggers it to abort the current sleep and log the requested now.I will admit that I'm not an expert on how signals interrupt system calls on all systems, but for what it's worth, the code looks good to me. Is it correct to assume that you are using this on Linux?> 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).Agreed, that sounds very useful. I don't think we have a standard format for documenting the signals that the various NUT components respond to. However, I wouldn't want this feature to remain undocumented. Would you mind writing up a paragraph for the man page, in docs/man/upslog.txt? We currently describe how the sleep(3) times are approximate, but this could go in there as well. Thanks, -- Charles Lepple clepple at gmail
Hi Charles, On 10/12/14 14:27, Charles Lepple wrote:> Hi Andy, > > On Dec 8, 2014, at 7:07 PM, Andy Juniper <ajuniper at freeuk.com> wrote: > >> It adds a signal handler for the USR1 signal, which simply triggers it to abort the current sleep and log the requested now. > I will admit that I'm not an expert on how signals interrupt system calls on all systems, but for what it's worth, the code looks good to me. Is it correct to assume that you are using this on Linux?Yes, I've been running this on an ancient RedHat 9 system for a few years, and I'm just in the process of moving it to EL6. Certainly on Linux, the signal interrupts the sleep which returns with (quoting from the manual page): RETURN VALUE Zero if the requested time has elapsed, or the number of seconds left to sleep, if the call was interrupted by a signal handler.>> 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). > Agreed, that sounds very useful. > > I don't think we have a standard format for documenting the signals that the various NUT components respond to. However, I wouldn't want this feature to remain undocumented. Would you mind writing up a paragraph for the man page, in docs/man/upslog.txt? We currently describe how the sleep(3) times are approximate, but this could go in there as well.Try this - I couldn't see the file you reference but here's a paragraph for the manual page - probably fits in after service delays or log rotation. ON DEMAND LOGGING Sending a USR1 signal to a running 'upslog' process makes it wake from the current sleep and log immediately. This is useful when triggered from a upssched event trigger (e.g. AT ONBATT or AT ONLINE) to ensure that an entry always exists, even if the power goes away for a period of time shorter than that specified by the -i argument. Andy> > Thanks, >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.alioth.debian.org/pipermail/nut-upsdev/attachments/20141210/680fdfab/attachment.html>
On 2014-12-09 01:07, Andy Juniper wrote:> Hi > > + sa.sa_handler = set_print_now_flag; > + if (sigaction(SIGUSR1, &sa, NULL) < 0) > + fatal_with_errno(EXIT_FAILURE, "Can't install SIGTERM handler"); > + > }Minor typo there, should be SIGUSR1 =)