<br><br><div class="gmail_quote">2009/5/17 Daniel O&#39;Connor <span dir="ltr">&lt;<a href="mailto:doconnor@gsoft.com.au" target="_blank">doconnor@gsoft.com.au</a>&gt;</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>
&gt; &gt; Sounds good to me.<br>
&gt; &gt; I was also thinking of an option to use syslog, that way upslog can<br>
&gt; &gt; run as whatever user and not have to worry about file perms.<br>
&gt;<br>
&gt; 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 &quot;timehead.h&quot;<br>
 #include &quot;upslog.h&quot;<br>
<br>
+#include &lt;syslog.h&gt;<br>
+#include &lt;stdarg.h&gt;<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, &quot;logging to syslog&quot;);<br>
+               return;<br>
+       }<br>
+<br>
        if (logfile == stdout) {<br>
                upslogx(LOG_INFO, &quot;logging to stdout&quot;);<br>
                return;<br>
@@ -108,7 +116,7 @@<br>
        printf(&quot;  -f &lt;format&gt;   - Log format.  See below for details.\n&quot;);<br>
<div>        printf(&quot;                - Use -f \&quot;&lt;format&gt;\&quot; so your shell doesn&#39;t break it up.\n&quot;);<br>
        printf(&quot;  -i &lt;interval&gt; - Time between updates, in seconds\n&quot;);<br>
-       printf(&quot;  -l &lt;logfile&gt;  - Log file name, or - for stdout\n&quot;);<br>
</div>+       printf(&quot;  -l &lt;logfile&gt;  - Log file name (- for stdout, syslog for syslog)\n&quot;);<br>
<div>        printf(&quot;  -s &lt;ups&gt;      - Monitor UPS &lt;ups&gt; - &lt;upsname&gt;@&lt;host&gt;[:&lt;port&gt;]\n&quot;);<br>
        printf(&quot;                - Example: -s myups@server\n&quot;);<br>
        printf(&quot;  -u &lt;user&gt;     - Switch to &lt;user&gt; if started as root\n&quot;);<br>
</div>@@ -354,9 +362,12 @@<br>
                tmp = tmp-&gt;next;<br>
        }<br>
<br>
-       fprintf(logfile, &quot;%s\n&quot;, logbuffer);<br>
-       fflush(logfile);<br>
-}<br>
+       if (logfile == NULL)<br>
+               syslog(LOG_INFO, &quot;%s&quot;, logbuffer);<br>
+       else {<br>
+               fprintf(logfile, &quot;%s\n&quot;, logbuffer);<br>
+               fflush(logfile);<br>
+       }<br>
<br>
        /* -s &lt;monhost&gt;<br>
         * -l &lt;log file&gt;<br>
@@ -364,6 +375,7 @@<br>
         * -f &lt;format&gt;<br>
         * -u &lt;username&gt;<br>
         */<br>
+}<br>
<br>
 int main(int argc, char **argv)<br>
 {<br>
@@ -458,21 +470,28 @@<br>
                fprintf(stderr, &quot;Warning: initial connect failed: %s\n&quot;,<br>
                        upscli_strerror(&amp;ups));<br>
<br>
-       if (strcmp(logfn, &quot;-&quot;) == 0)<br>
-               logfile = stdout;<br>
-       else<br>
-               logfile = fopen(logfn, &quot;a&quot;);<br>
-<br>
-       if (logfile == NULL)<br>
-               fatal_with_errno(EXIT_FAILURE, &quot;could not open logfile %s&quot;, logfn);<br>
-<br>
+       if (strcmp(logfn, &quot;syslog&quot;)) {<br>
+               openlog(&quot;upslog&quot;, LOG_PID, LOG_DAEMON);<br>
+               logfile = NULL;<br>
+       } else {<br>
+               if (strcmp(logfn, &quot;-&quot;) == 0)<br>
+                       logfile = stdout;<br>
+               else<br>
+                       logfile = fopen(logfn, &quot;a&quot;);<br>
+<br>
+               if (logfile == NULL)<br>
+                       fatal_with_errno(EXIT_FAILURE, &quot;could not open logfile %s&quot;, 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 &gt;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 &quot;show copying&quot; to see the conditions.<br>
There is absolutely no warranty for GDB.  Type &quot;show warranty&quot; for details.<br>
This GDB was configured as &quot;amd64-marcel-freebsd&quot;...<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 &quot;libupsclient.so.1&quot; not found, required by &quot;upslog&quot;<br>
<br>
Program exited with code 01.<br>
(gdb) %                                                                                                         [cain<br>
19:29] ~/projects/nut-2.4.1 &gt;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&#39; 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&#39;t just install it because this is on a production system.<br>
</blockquote><div><br>adding &quot;/usr/local/Genesis/home/doconnor/projects/nut-2.4.1/.libs/&quot; 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&#39;s already busted, but &quot;-l -&quot; doesn&#39;t<br>
keep it in the foreground..<br>
</blockquote></div><br>still working in a vanilla trunk.<br>I&#39;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, &quot;syslog&quot;)) {<br>
which I guess should be<br>+       if (strcmp(logfn, &quot;syslog&quot;) == 0) {<br><br>btw, use the unified format for diffing (ie diff -ru ...).<br><br>Arnaud<br>