[Nut-upsdev] [nut-commits] svn commit r1837 - trunk/clients
Daniel O'Connor
doconnor at gsoft.com.au
Sun May 17 10:00:34 UTC 2009
On Sun, 17 May 2009, Arnaud Quette wrote:
> > Sounds good to me.
> > I was also thinking of an option to use syslog, that way upslog can
> > run as whatever user and not have to worry about file perms.
>
> can you propose a patch for that?
Well I have this..
diff -r c79ce7440a78 clients/upslog.c
--- a/clients/upslog.c Sun May 17 18:09:51 2009 +0930
+++ b/clients/upslog.c Sun May 17 19:28:15 2009 +0930
@@ -38,6 +38,9 @@
#include "timehead.h"
#include "upslog.h"
+#include <syslog.h>
+#include <stdarg.h>
+
static int port, reopen_flag = 0, exit_flag = 0;
static char *upsname, *hostname;
static UPSCONN_t ups;
@@ -55,6 +58,11 @@
static void reopen_log(void)
{
+ if (logfile == NULL) {
+ upslogx(LOG_INFO, "logging to syslog");
+ return;
+ }
+
if (logfile == stdout) {
upslogx(LOG_INFO, "logging to stdout");
return;
@@ -108,7 +116,7 @@
printf(" -f <format> - Log format. See below for details.\n");
printf(" - Use -f \"<format>\" so your shell doesn't break it up.\n");
printf(" -i <interval> - Time between updates, in seconds\n");
- printf(" -l <logfile> - Log file name, or - for stdout\n");
+ printf(" -l <logfile> - Log file name (- for stdout, syslog for syslog)\n");
printf(" -s <ups> - Monitor UPS <ups> - <upsname>@<host>[:<port>]\n");
printf(" - Example: -s myups at server\n");
printf(" -u <user> - Switch to <user> if started as root\n");
@@ -354,9 +362,12 @@
tmp = tmp->next;
}
- fprintf(logfile, "%s\n", logbuffer);
- fflush(logfile);
-}
+ if (logfile == NULL)
+ syslog(LOG_INFO, "%s", logbuffer);
+ else {
+ fprintf(logfile, "%s\n", logbuffer);
+ fflush(logfile);
+ }
/* -s <monhost>
* -l <log file>
@@ -364,6 +375,7 @@
* -f <format>
* -u <username>
*/
+}
int main(int argc, char **argv)
{
@@ -458,21 +470,28 @@
fprintf(stderr, "Warning: initial connect failed: %s\n",
upscli_strerror(&ups));
- if (strcmp(logfn, "-") == 0)
- logfile = stdout;
- else
- logfile = fopen(logfn, "a");
-
- if (logfile == NULL)
- fatal_with_errno(EXIT_FAILURE, "could not open logfile %s", logfn);
-
+ if (strcmp(logfn, "syslog")) {
+ openlog("upslog", LOG_PID, LOG_DAEMON);
+ logfile = NULL;
+ } else {
+ if (strcmp(logfn, "-") == 0)
+ logfile = stdout;
+ else
+ logfile = fopen(logfn, "a");
+
+ if (logfile == NULL)
+ fatal_with_errno(EXIT_FAILURE, "could not open logfile %s", logfn);
+ }
+
/* now drop root if we have it */
new_uid = get_user_pwent(user);
But I am having trouble debugging it because libtool is being a right pain in the arse.
[cain 19:28] ~/projects/nut-2.4.1 >gdb ./clients/.libs/upslog GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...
(gdb) run
Starting program: /usr/local/Genesis/home/doconnor/projects/nut-2.4.1/clients/.libs/upslog
/libexec/ld-elf.so.1: Shared object "libupsclient.so.1" not found, required by "upslog"
Program exited with code 01.
(gdb) % [cain
19:29] ~/projects/nut-2.4.1 >libtool --mode=execute gdb clients/upslog
clients/upslog: Xclients/upslog: not found
clients/upslog: /usr/local/bin/libtool: error: `/usr/local/Genesis/home/doconnor/projects/nut-2.4.1/.libs/upslog' does
not exist: not found
This script is just a wrapper for upslog.: not found
See the libtool documentation for more information.
I can't just install it because this is on a production system.
Also, either my changes broke it or it's already busted, but "-l -" doesn't
keep it in the foreground..
--
Daniel O'Connor software and network engineer
for Genesis Software - http://www.gsoft.com.au
"The nice thing about standards is that there
are so many of them to choose from."
-- Andrew Tanenbaum
GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 188 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.alioth.debian.org/pipermail/nut-upsdev/attachments/20090517/d3b3bd63/attachment.pgp>
More information about the Nut-upsdev
mailing list