FreeBSD Bugzilla – Attachment 236030 Details for
Bug 265963
sysutils/nut: add possibility to log status of several UPSes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
The concept I had in mind
patch-clients_upslog.c (text/plain), 3.07 KB, created by
Cy Schubert
on 2022-08-21 05:10:15 UTC
(
hide
)
Description:
The concept I had in mind
Filename:
MIME Type:
Creator:
Cy Schubert
Created:
2022-08-21 05:10:15 UTC
Size:
3.07 KB
patch
obsolete
>--- clients/upslog.c.orig 2022-08-20 17:43:30.860772000 -0700 >+++ clients/upslog.c 2022-08-20 22:00:44.566658000 -0700 >@@ -32,6 +32,8 @@ > */ > > #include "common.h" >+#include <unistd.h> >+#include <sys/wait.h> > #include "nut_platform.h" > #include "upsclient.h" > >@@ -41,16 +43,28 @@ > #include "upslog.h" > > static int reopen_flag = 0, exit_flag = 0; >+ static int wait_status, num_monhosts = 0; > static uint16_t port; > static char *upsname, *hostname; > static UPSCONN_t ups; > > static FILE *logfile; >- static const char *logfn, *monhost; >+ static char *logfn, *monhost; > static sigset_t nut_upslog_sigmask; > static char logbuffer[LARGEBUF], *logformat; > > static flist_t *fhead = NULL; >+ struct monhost_child { >+ char *monhost; >+ char *logfn; >+ char *pidfilebase; >+ pid_t pid; >+ struct monhost_child *next; >+ }; >+ static struct monhost_child *monhost_child_anchor = NULL; >+ static struct monhost_child *monhost_child_current; >+ static struct monhost_child *monhost_child_prev = NULL; >+ static char *m_arg; > > #define DEFAULT_LOGFORMAT "%TIME @Y@m@d @H@M@S% %VAR battery.charge% " \ > "%VAR input.voltage% %VAR ups.load% [%VAR ups.status%] " \ >@@ -396,18 +410,19 @@ > int main(int argc, char **argv) > { > int interval = 30, i, foreground = -1; >+ size_t monhost_len; > const char *prog = xbasename(argv[0]); > time_t now, nextpoll = 0; > const char *user = NULL; > struct passwd *new_uid = NULL; >- const char *pidfilebase = prog; >+ char *pidfilebase = prog; > > logformat = DEFAULT_LOGFORMAT; > user = RUN_AS_USER; > > printf("Network UPS Tools %s %s\n", prog, UPS_VERSION); > >- while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:FB")) != -1) { >+ while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:FBm:")) != -1) { > switch(i) { > case 'h': > help(prog); >@@ -415,6 +430,19 @@ > break; > #endif > >+ case 'm': >+ monhost_child_prev = monhost_child_current; >+ monhost_child_current = malloc(sizeof(struct monhost_child)); >+ if (monhost_child_anchor == NULL) >+ monhost_child_anchor = monhost_child_current; >+ else >+ monhost_child_prev->next = monhost_child_current; >+ monhost_child_current->next = NULL; >+ m_arg = optarg; >+ monhost_child_current->monhost = strsep(&m_arg, ":"); >+ monhost_child_current->logfn = strsep(&m_arg, ":"); >+ monhost_child_current->pidfilebase = strsep(&m_arg, ":"); >+ break; > case 's': > monhost = optarg; > break; >@@ -478,6 +506,23 @@ > for (i = 3; i < argc; i++) > snprintfcat(logformat, LARGEBUF, "%s ", argv[i]); > } >+ >+ if (monhost_child_anchor != NULL) { >+ for (monhost_child_current = monhost_child_anchor; >+ monhost_child_current != NULL; >+ monhost_child_current = monhost_child_current->next) { >+ if ((monhost_child_current->pid = fork()) == 0) { >+ monhost = monhost_child_current->monhost; >+ logfn = monhost_child_current->logfn; >+ pidfilebase = monhost_child_current->pidfilebase; >+ break; >+ } >+ } >+ if (monhost_child_anchor->pid) >+ exit(EXIT_SUCCESS); >+ } >+ >+ /* When num_monhosts == 1 monhost remains the only argument */ > > if (!monhost) > fatalx(EXIT_FAILURE, "No UPS defined for monitoring - use -s <system>");
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 265963
:
236026
|
236030
|
236045
|
236049
|
236051
|
236052
|
236072
|
236073
|
236121
|
236127
|
236128
|
236132
|
236194
|
236219
|
236238
|
236243