[Nut-upsdev] upslog patch

Daniel O'Connor doconnor at gsoft.com.au
Mon Apr 20 03:19:55 UTC 2009


Hi,
I have a system which monitors 2 UPSs, and it runs upslog twice. I had a 
problem with newsyslog rotating the log file because upslog keeps it 
open (arguably a bug IMO), but it also has no way of changing the PID 
file so newsyslog can't HUP it when log rotating.

Attached is a patch which allows you to specify the argument for 
writepid() so you can differentiate them easily.

-- 
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 --------------
--- clients/upslog.c.orig       2009-04-20 03:05:39.000000000 +0000
+++ clients/upslog.c    2009-04-20 03:11:21.000000000 +0000
@@ -109,6 +109,7 @@
        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("  -p <pidbase>  - Base name for PID file (defaults to \"upslog\")\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");
@@ -371,6 +372,7 @@
        char    *prog = NULL;
        const   char    *user = NULL;
        struct  passwd  *new_uid = NULL;
+       const   char    *pidfilebase = "upslog";

        logformat = DEFAULT_LOGFORMAT;
        user = RUN_AS_USER;
@@ -379,7 +381,7 @@

        prog = argv[0];

-       while ((i = getopt(argc, argv, "+hs:l:i:f:u:V")) != -1) {
+       while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:")) != -1) {
                switch(i) {
                        case 'h':
                                help(prog);
@@ -407,6 +409,10 @@

                        case 'V':
                                exit(EXIT_SUCCESS);
+
+                       case 'p':
+                               pidfilebase = optarg;
+                               break;
                }
        }

@@ -476,7 +482,7 @@

        setup_signals();

-       writepid("upslog");
+       writepid(pidfilebase);

        become_user(new_uid);

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.alioth.debian.org/pipermail/nut-upsdev/attachments/20090420/dd3f677e/attachment.pgp>


More information about the Nut-upsdev mailing list