View | Details | Raw Unified | Return to bug 265963 | Differences between
and this patch

Collapse All | Expand All

(-)b/sysutils/nut-devel/Makefile (+1 lines)
Lines 1-5 Link Here
1
PORTNAME=	nut
1
PORTNAME=	nut
2
PORTVERSION=	${NUT_COMMIT_DATE}
2
PORTVERSION=	${NUT_COMMIT_DATE}
3
PORTREVISION=	1
3
CATEGORIES=	sysutils
4
CATEGORIES=	sysutils
4
PKGNAMESUFFIX=	-devel
5
PKGNAMESUFFIX=	-devel
5
# MASTER_SITES=	http://www.networkupstools.org/source/${PORTVERSION:R}/
6
# MASTER_SITES=	http://www.networkupstools.org/source/${PORTVERSION:R}/
(-)b/sysutils/nut-devel/files/patch-clients_upslog.c (+107 lines)
Added Link Here
1
--- clients/upslog.c.orig	2022-08-20 17:43:30.860772000 -0700
2
+++ clients/upslog.c	2022-08-20 22:00:44.566658000 -0700
3
@@ -32,6 +32,8 @@
4
  */
5
 
6
 #include "common.h"
7
+#include <unistd.h>
8
+#include <sys/wait.h>
9
 #include "nut_platform.h"
10
 #include "upsclient.h"
11
 
12
@@ -41,16 +43,28 @@
13
 #include "upslog.h"
14
 
15
 	static	int	reopen_flag = 0, exit_flag = 0;
16
+	static  int	wait_status, num_monhosts = 0;
17
 	static	uint16_t	port;
18
 	static	char	*upsname, *hostname;
19
 	static	UPSCONN_t	ups;
20
 
21
 	static	FILE	*logfile;
22
-	static	const	char *logfn, *monhost;
23
+	static	char *logfn, *monhost;
24
 	static	sigset_t	nut_upslog_sigmask;
25
 	static	char	logbuffer[LARGEBUF], *logformat;
26
 
27
 	static	flist_t	*fhead = NULL;
28
+	struct 	monhost_child {
29
+		char	*monhost;
30
+		char	*logfn;
31
+		char	*pidfilebase;
32
+		pid_t	pid;
33
+		struct	monhost_child	*next;
34
+	};
35
+	static	struct	monhost_child *monhost_child_anchor = NULL;
36
+	static	struct	monhost_child *monhost_child_current;
37
+	static	struct	monhost_child *monhost_child_prev = NULL;
38
+	static	char	*m_arg;
39
 
40
 #define DEFAULT_LOGFORMAT "%TIME @Y@m@d @H@M@S% %VAR battery.charge% " \
41
 		"%VAR input.voltage% %VAR ups.load% [%VAR ups.status%] " \
42
@@ -396,18 +410,19 @@
43
 int main(int argc, char **argv)
44
 {
45
 	int	interval = 30, i, foreground = -1;
46
+	size_t	monhost_len;
47
 	const char	*prog = xbasename(argv[0]);
48
 	time_t	now, nextpoll = 0;
49
 	const char	*user = NULL;
50
 	struct passwd	*new_uid = NULL;
51
-	const char	*pidfilebase = prog;
52
+	char	*pidfilebase = prog;
53
 
54
 	logformat = DEFAULT_LOGFORMAT;
55
 	user = RUN_AS_USER;
56
 
57
 	printf("Network UPS Tools %s %s\n", prog, UPS_VERSION);
58
 
59
-	while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:FB")) != -1) {
60
+	while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:FBm:")) != -1) {
61
 		switch(i) {
62
 			case 'h':
63
 				help(prog);
64
@@ -415,6 +430,19 @@
65
 				break;
66
 #endif
67
 
68
+			case 'm':
69
+				monhost_child_prev = monhost_child_current;
70
+				monhost_child_current = malloc(sizeof(struct monhost_child));
71
+				if (monhost_child_anchor == NULL)
72
+					monhost_child_anchor = monhost_child_current;
73
+				else
74
+					monhost_child_prev->next = monhost_child_current;
75
+				monhost_child_current->next = NULL;
76
+				m_arg = optarg;
77
+				monhost_child_current->monhost = strsep(&m_arg, ":");
78
+				monhost_child_current->logfn = strsep(&m_arg, ":");
79
+				monhost_child_current->pidfilebase = strsep(&m_arg, ":");
80
+				break;
81
 			case 's':
82
 				monhost = optarg;
83
 				break;
84
@@ -478,6 +506,23 @@
85
 		for (i = 3; i < argc; i++)
86
 			snprintfcat(logformat, LARGEBUF, "%s ", argv[i]);
87
 	}
88
+
89
+	if (monhost_child_anchor != NULL) {
90
+		for (monhost_child_current = monhost_child_anchor;
91
+		     monhost_child_current != NULL;
92
+		     monhost_child_current = monhost_child_current->next) {
93
+			if ((monhost_child_current->pid = fork()) == 0) {
94
+				monhost = monhost_child_current->monhost;
95
+				logfn = monhost_child_current->logfn;
96
+				pidfilebase = monhost_child_current->pidfilebase;
97
+				break;
98
+			}
99
+		}
100
+		if (monhost_child_anchor->pid)
101
+			exit(EXIT_SUCCESS);
102
+	}
103
+
104
+	/* When num_monhosts == 1 monhost remains the only argument */
105
 
106
 	if (!monhost)
107
 		fatalx(EXIT_FAILURE, "No UPS defined for monitoring - use -s <system>");
(-)b/sysutils/nut/Makefile (-1 / +1 lines)
Lines 1-6 Link Here
1
PORTNAME=	nut
1
PORTNAME=	nut
2
PORTVERSION=	2.8.0
2
PORTVERSION=	2.8.0
3
PORTREVISION=	6
3
PORTREVISION=	7
4
CATEGORIES=	sysutils
4
CATEGORIES=	sysutils
5
MASTER_SITES=	http://www.networkupstools.org/source/${PORTVERSION:R}/
5
MASTER_SITES=	http://www.networkupstools.org/source/${PORTVERSION:R}/
6
6
(-)b/sysutils/nut/files/patch-clients_upslog.c (-1 / +107 lines)
Added Link Here
0
- 
1
--- clients/upslog.c.orig	2022-08-20 17:43:30.860772000 -0700
2
+++ clients/upslog.c	2022-08-20 22:00:44.566658000 -0700
3
@@ -32,6 +32,8 @@
4
  */
5
 
6
 #include "common.h"
7
+#include <unistd.h>
8
+#include <sys/wait.h>
9
 #include "nut_platform.h"
10
 #include "upsclient.h"
11
 
12
@@ -41,16 +43,28 @@
13
 #include "upslog.h"
14
 
15
 	static	int	reopen_flag = 0, exit_flag = 0;
16
+	static  int	wait_status, num_monhosts = 0;
17
 	static	uint16_t	port;
18
 	static	char	*upsname, *hostname;
19
 	static	UPSCONN_t	ups;
20
 
21
 	static	FILE	*logfile;
22
-	static	const	char *logfn, *monhost;
23
+	static	char *logfn, *monhost;
24
 	static	sigset_t	nut_upslog_sigmask;
25
 	static	char	logbuffer[LARGEBUF], *logformat;
26
 
27
 	static	flist_t	*fhead = NULL;
28
+	struct 	monhost_child {
29
+		char	*monhost;
30
+		char	*logfn;
31
+		char	*pidfilebase;
32
+		pid_t	pid;
33
+		struct	monhost_child	*next;
34
+	};
35
+	static	struct	monhost_child *monhost_child_anchor = NULL;
36
+	static	struct	monhost_child *monhost_child_current;
37
+	static	struct	monhost_child *monhost_child_prev = NULL;
38
+	static	char	*m_arg;
39
 
40
 #define DEFAULT_LOGFORMAT "%TIME @Y@m@d @H@M@S% %VAR battery.charge% " \
41
 		"%VAR input.voltage% %VAR ups.load% [%VAR ups.status%] " \
42
@@ -396,18 +410,19 @@
43
 int main(int argc, char **argv)
44
 {
45
 	int	interval = 30, i, foreground = -1;
46
+	size_t	monhost_len;
47
 	const char	*prog = xbasename(argv[0]);
48
 	time_t	now, nextpoll = 0;
49
 	const char	*user = NULL;
50
 	struct passwd	*new_uid = NULL;
51
-	const char	*pidfilebase = prog;
52
+	char	*pidfilebase = prog;
53
 
54
 	logformat = DEFAULT_LOGFORMAT;
55
 	user = RUN_AS_USER;
56
 
57
 	printf("Network UPS Tools %s %s\n", prog, UPS_VERSION);
58
 
59
-	while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:FB")) != -1) {
60
+	while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:FBm:")) != -1) {
61
 		switch(i) {
62
 			case 'h':
63
 				help(prog);
64
@@ -415,6 +430,19 @@
65
 				break;
66
 #endif
67
 
68
+			case 'm':
69
+				monhost_child_prev = monhost_child_current;
70
+				monhost_child_current = malloc(sizeof(struct monhost_child));
71
+				if (monhost_child_anchor == NULL)
72
+					monhost_child_anchor = monhost_child_current;
73
+				else
74
+					monhost_child_prev->next = monhost_child_current;
75
+				monhost_child_current->next = NULL;
76
+				m_arg = optarg;
77
+				monhost_child_current->monhost = strsep(&m_arg, ":");
78
+				monhost_child_current->logfn = strsep(&m_arg, ":");
79
+				monhost_child_current->pidfilebase = strsep(&m_arg, ":");
80
+				break;
81
 			case 's':
82
 				monhost = optarg;
83
 				break;
84
@@ -478,6 +506,23 @@
85
 		for (i = 3; i < argc; i++)
86
 			snprintfcat(logformat, LARGEBUF, "%s ", argv[i]);
87
 	}
88
+
89
+	if (monhost_child_anchor != NULL) {
90
+		for (monhost_child_current = monhost_child_anchor;
91
+		     monhost_child_current != NULL;
92
+		     monhost_child_current = monhost_child_current->next) {
93
+			if ((monhost_child_current->pid = fork()) == 0) {
94
+				monhost = monhost_child_current->monhost;
95
+				logfn = monhost_child_current->logfn;
96
+				pidfilebase = monhost_child_current->pidfilebase;
97
+				break;
98
+			}
99
+		}
100
+		if (monhost_child_anchor->pid)
101
+			exit(EXIT_SUCCESS);
102
+	}
103
+
104
+	/* When num_monhosts == 1 monhost remains the only argument */
105
 
106
 	if (!monhost)
107
 		fatalx(EXIT_FAILURE, "No UPS defined for monitoring - use -s <system>");

Return to bug 265963