<br><br><div class="gmail_quote">2009/5/17 Daniel O'Connor <span dir="ltr"><<a href="mailto:doconnor@gsoft.com.au" target="_blank">doconnor@gsoft.com.au</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>On Sun, 17 May 2009, Arnaud Quette wrote:<br>
> > Sounds good to me.<br>
> > I was also thinking of an option to use syslog, that way upslog can<br>
> > run as whatever user and not have to worry about file perms.<br>
><br>
> can you propose a patch for that?<br>
<br>
</div>Well I have this..<br>
diff -r c79ce7440a78 clients/upslog.c<br>
--- a/clients/upslog.c Sun May 17 18:09:51 2009 +0930<br>
+++ b/clients/upslog.c Sun May 17 19:28:15 2009 +0930<br>
@@ -38,6 +38,9 @@<br>
#include "timehead.h"<br>
#include "upslog.h"<br>
<br>
+#include <syslog.h><br>
+#include <stdarg.h><br>
+<br>
static int port, reopen_flag = 0, exit_flag = 0;<br>
static char *upsname, *hostname;<br>
static UPSCONN_t ups;<br>
@@ -55,6 +58,11 @@<br>
<br>
static void reopen_log(void)<br>
{<br>
+ if (logfile == NULL) {<br>
+ upslogx(LOG_INFO, "logging to syslog");<br>
+ return;<br>
+ }<br>
+<br>
if (logfile == stdout) {<br>
upslogx(LOG_INFO, "logging to stdout");<br>
return;<br>
@@ -108,7 +116,7 @@<br>
printf(" -f <format> - Log format. See below for details.\n");<br>
<div> printf(" - Use -f \"<format>\" so your shell doesn't break it up.\n");<br>
printf(" -i <interval> - Time between updates, in seconds\n");<br>
- printf(" -l <logfile> - Log file name, or - for stdout\n");<br>
</div>+ printf(" -l <logfile> - Log file name (- for stdout, syslog for syslog)\n");<br>
<div> printf(" -s <ups> - Monitor UPS <ups> - <upsname>@<host>[:<port>]\n");<br>
printf(" - Example: -s myups@server\n");<br>
printf(" -u <user> - Switch to <user> if started as root\n");<br>
</div>@@ -354,9 +362,12 @@<br>
tmp = tmp->next;<br>
}<br>
<br>
- fprintf(logfile, "%s\n", logbuffer);<br>
- fflush(logfile);<br>
-}<br>
+ if (logfile == NULL)<br>
+ syslog(LOG_INFO, "%s", logbuffer);<br>
+ else {<br>
+ fprintf(logfile, "%s\n", logbuffer);<br>
+ fflush(logfile);<br>
+ }<br>
<br>
/* -s <monhost><br>
* -l <log file><br>
@@ -364,6 +375,7 @@<br>
* -f <format><br>
* -u <username><br>
*/<br>
+}<br>
<br>
int main(int argc, char **argv)<br>
{<br>
@@ -458,21 +470,28 @@<br>
fprintf(stderr, "Warning: initial connect failed: %s\n",<br>
upscli_strerror(&ups));<br>
<br>
- if (strcmp(logfn, "-") == 0)<br>
- logfile = stdout;<br>
- else<br>
- logfile = fopen(logfn, "a");<br>
-<br>
- if (logfile == NULL)<br>
- fatal_with_errno(EXIT_FAILURE, "could not open logfile %s", logfn);<br>
-<br>
+ if (strcmp(logfn, "syslog")) {<br>
+ openlog("upslog", LOG_PID, LOG_DAEMON);<br>
+ logfile = NULL;<br>
+ } else {<br>
+ if (strcmp(logfn, "-") == 0)<br>
+ logfile = stdout;<br>
+ else<br>
+ logfile = fopen(logfn, "a");<br>
+<br>
+ if (logfile == NULL)<br>
+ fatal_with_errno(EXIT_FAILURE, "could not open logfile %s", logfn);<br>
+ }<br>
+<br>
/* now drop root if we have it */<br>
new_uid = get_user_pwent(user);<br>
<br>
But I am having trouble debugging it because libtool is being a right pain in the arse.<br>
[cain 19:28] ~/projects/nut-2.4.1 >gdb ./clients/.libs/upslog GNU gdb 6.1.1 [FreeBSD]<br>
Copyright 2004 Free Software Foundation, Inc.<br>
GDB is free software, covered by the GNU General Public License, and you are<br>
welcome to change it and/or distribute copies of it under certain conditions.<br>
Type "show copying" to see the conditions.<br>
There is absolutely no warranty for GDB. Type "show warranty" for details.<br>
This GDB was configured as "amd64-marcel-freebsd"...<br>
(gdb) run<br>
Starting program: /usr/local/Genesis/home/doconnor/projects/nut-2.4.1/clients/.libs/upslog<br>
/libexec/ld-elf.so.1: Shared object "libupsclient.so.1" not found, required by "upslog"<br>
<br>
Program exited with code 01.<br>
(gdb) % [cain<br>
19:29] ~/projects/nut-2.4.1 >libtool --mode=execute gdb clients/upslog<br>
clients/upslog: Xclients/upslog: not found<br>
clients/upslog: /usr/local/bin/libtool: error: `/usr/local/Genesis/home/doconnor/projects/nut-2.4.1/.libs/upslog' does<br>
not exist: not found<br>
This script is just a wrapper for upslog.: not found<br>
See the libtool documentation for more information.<br>
<br>
I can't just install it because this is on a production system.<br>
</blockquote><div><br>adding "/usr/local/Genesis/home/doconnor/projects/nut-2.4.1/.libs/" to $LD_LIBRARY_PATH might help you there.<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Also, either my changes broke it or it's already busted, but "-l -" doesn't<br>
keep it in the foreground..<br>
</blockquote></div><br>still working in a vanilla trunk.<br>I've not tried your patch (failing to apply, and not much time to apply by hand), but it seems fine apart of:<br>+ if (strcmp(logfn, "syslog")) {<br>
which I guess should be<br>+ if (strcmp(logfn, "syslog") == 0) {<br><br>btw, use the unified format for diffing (ie diff -ru ...).<br><br>Arnaud<br>