While looking into Laurent Lesage's problem with upssched, I noticed something in exec_cmd(): http://boxster.ghz.cc/projects/nut/browser/trunk/clients/upssched.c#L79 In the man pages for system(3) on both OS X and Linux (Debian sarge), I do not see any mention of errno being set. The error code is returned by system, and I am wondering if the "file not found" error that Laurent saw was actually masking another problem. I personally don't use upssched in production (if the power goes out, chances are that the notification would not get through to me until after the power returns), so are there any developers who would be willing to help test some modifications to upssched? I'm thinking that the return code should be tested with WIFEXITED, etc. instead of using errno, which may not have been updated by the C library when system() returned. -- - Charles Lepple
On Wed, 17 May 2006, Charles Lepple wrote:> In the man pages for system(3) on both OS X and Linux (Debian sarge), > I do not see any mention of errno being set....> I'm thinking that the return code should be tested with WIFEXITED, > etc. instead of using errno, which may not have been updated by the C > library when system() returned.More correctly, errno was set by the C library in another process's context. If that process did not encode errno in the return status then the value is lost. Often programs will use errno in an error string they send to stderr, and then exit some fixed non-zero value. So, yes, you shouldn't expect errno to be useful when system returns. -- Charlie A: Because we read from top to bottom, left to right. Q: Why should i start my reply below the quoted text?
Can someone with access to a non-Linux system and/or a working upssched script test the attached patch? The basic idea is to log nothing if it exits cleanly (as the code did before; you can always add logging in your script), log non-zero exit codes at LOG_INFO level, and note termination by signal at LOG_WARNING. In particular, I'm curious if Solaris implements all of the necessary macros. -- - Charles Lepple -------------- next part -------------- A non-text attachment was scrubbed... Name: upssched.patch Type: application/octet-stream Size: 857 bytes Desc: not available Url : http://lists.alioth.debian.org/pipermail/nut-upsdev/attachments/20060517/6e0a45f0/upssched.obj