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/nut_upslog.sample (+52 lines)
Added Link Here
1
#!/bin/sh
2
3
# Authored by vvd@unislabs.com.
4
5
# PROVIDE: nut_upslog
6
# REQUIRE: NETWORKING nut
7
# BEFORE: LOGIN
8
# KEYWORD: shutdown
9
10
. /etc/rc.subr
11
12
case $0 in
13
/etc/rc*)
14
	# during boot (shutdown) $0 is /etc/rc (/etc/rc.shutdown),
15
	# so get the name of the script from $_file
16
	name=$_file
17
	;;
18
*)
19
	name=$0
20
	;;
21
esac
22
23
name=${name##*/}
24
rcvar=${name}_enable
25
26
load_rc_config "${name}"
27
28
# Define these nut_upslog* variables in one of these files:
29
#       /etc/rc.conf
30
#       /etc/rc.conf.local
31
#       /etc/rc.conf.d/nut_upslog
32
#
33
# If you want to log several different UPSes:
34
# ln -s nut_upslog /usr/local/etc/rc.d/NAME
35
# then set variables NAME_enable, NAME_ups, NAME_pidbase, NAME_logfile and etc.
36
#
37
# DO NOT CHANGE THESE DEFAULT VALUES HERE
38
#
39
eval "${rcvar}=\${${rcvar}:-'NO'}"
40
eval "_prefix=\${${name}_prefix:-'/usr/local'}"
41
eval "_logfile=\${${name}_logfile:-'/var/log/nut/ups.log'}"
42
eval "_interval=\${${name}_interval:-'300'}"
43
eval "_ups=\${${name}_ups:-'myups@localhost'}"
44
eval "_pidbase=\${${name}_pidbase:-'upslog'}"
45
eval "_format=\${${name}_format:+-f \${${name}_format}}"
46
eval "${name}_flags=\${${name}_flags:-'-s ${_ups} -l ${_logfile} -i ${_interval} -p ${_pidbase} ${_format}'}"
47
48
required_dirs="%%STATEDIR%%"
49
pidfile="%%STATEDIR%%/${_pidbase}.pid"
50
command="${_prefix}/bin/upslog"
51
52
run_rc_command "$1"
(-)b/sysutils/nut-devel/files/patch-clients_upslog.c (+133 lines)
Added Link Here
1
--- clients/upslog.c.orig	2022-08-21 09:28:11.630024000 -0700
2
+++ clients/upslog.c	2022-08-21 10:23:05.691271000 -0700
3
@@ -32,6 +32,10 @@
4
  */
5
 
6
 #include "common.h"
7
+#include <signal.h>
8
+#include <unistd.h>
9
+#include <sys/types.h>
10
+#include <sys/wait.h>
11
 #include "nut_platform.h"
12
 #include "upsclient.h"
13
 
14
@@ -41,17 +45,32 @@
15
 #include "upslog.h"
16
 
17
 	static	int	reopen_flag = 0, exit_flag = 0;
18
+	static  int	wait_status, child_pid;
19
 	static	uint16_t	port;
20
 	static	char	*upsname, *hostname;
21
 	static	UPSCONN_t	ups;
22
 
23
 	static	FILE	*logfile;
24
-	static	const	char *logfn, *monhost;
25
+	static	char *logfn, *monhost;
26
 	static	sigset_t	nut_upslog_sigmask;
27
 	static	char	logbuffer[LARGEBUF], *logformat;
28
 
29
 	static	flist_t	*fhead = NULL;
30
+	struct 	monhost_child {
31
+		char	*monhost;
32
+		char	*logfn;
33
+		char	*pidfilebase;
34
+		pid_t	pid;
35
+		struct	monhost_child	*next;
36
+	};
37
+	static	struct	monhost_child *monhost_child_anchor = NULL;
38
+	static	struct	monhost_child *monhost_child_current;
39
+	static	struct	monhost_child *monhost_child_prev = NULL;
40
+	static	char	*m_arg;
41
+	static	struct	sigaction upslog_sigaction;
42
+	static	int	trapped_signals[] = { SIGINT, SIGTERM, SIGCHLD };
43
 
44
+
45
 #define DEFAULT_LOGFORMAT "%TIME @Y@m@d @H@M@S% %VAR battery.charge% " \
46
 		"%VAR input.voltage% %VAR ups.load% [%VAR ups.status%] " \
47
 		"%VAR ups.temperature% %VAR input.frequency%"
48
@@ -393,21 +412,33 @@
49
 	 * -u <username>
50
 	 */
51
 
52
+static void term_handler(int signo)
53
+{
54
+	if (signo != SIGCHLD && monhost_child_anchor != NULL) {
55
+		for (monhost_child_current = monhost_child_anchor;
56
+		     monhost_child_current != NULL;
57
+		     monhost_child_current = monhost_child_current->next)
58
+			kill(monhost_child_current->pid, signo);
59
+		exit(signo);
60
+	}
61
+}
62
+
63
 int main(int argc, char **argv)
64
 {
65
 	int	interval = 30, i, foreground = -1;
66
+	size_t	monhost_len;
67
 	const char	*prog = xbasename(argv[0]);
68
 	time_t	now, nextpoll = 0;
69
 	const char	*user = NULL;
70
 	struct passwd	*new_uid = NULL;
71
-	const char	*pidfilebase = prog;
72
+	char	*pidfilebase = prog;
73
 
74
 	logformat = DEFAULT_LOGFORMAT;
75
 	user = RUN_AS_USER;
76
 
77
 	printf("Network UPS Tools %s %s\n", prog, UPS_VERSION);
78
 
79
-	while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:FB")) != -1) {
80
+	while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:FBm:")) != -1) {
81
 		switch(i) {
82
 			case 'h':
83
 				help(prog);
84
@@ -415,6 +446,19 @@
85
 				break;
86
 #endif
87
 
88
+			case 'm':
89
+				monhost_child_prev = monhost_child_current;
90
+				monhost_child_current = malloc(sizeof(struct monhost_child));
91
+				if (monhost_child_anchor == NULL)
92
+					monhost_child_anchor = monhost_child_current;
93
+				else
94
+					monhost_child_prev->next = monhost_child_current;
95
+				monhost_child_current->next = NULL;
96
+				m_arg = optarg;
97
+				monhost_child_current->monhost = strsep(&m_arg, ":");
98
+				monhost_child_current->logfn = strsep(&m_arg, ":");
99
+				monhost_child_current->pidfilebase = strsep(&m_arg, ":");
100
+				break;
101
 			case 's':
102
 				monhost = optarg;
103
 				break;
104
@@ -477,6 +521,29 @@
105
 
106
 		for (i = 3; i < argc; i++)
107
 			snprintfcat(logformat, LARGEBUF, "%s ", argv[i]);
108
+	}
109
+
110
+	if (monhost_child_anchor != NULL) {
111
+		for (monhost_child_current = monhost_child_anchor;
112
+		     monhost_child_current != NULL;
113
+		     monhost_child_current = monhost_child_current->next) {
114
+			if ((monhost_child_current->pid = fork()) == 0) {
115
+				monhost = monhost_child_current->monhost;
116
+				logfn = monhost_child_current->logfn;
117
+				pidfilebase = monhost_child_current->pidfilebase;
118
+				break;
119
+			}
120
+		}
121
+		if (monhost_child_anchor->pid) {
122
+			for (i = 0; i++; i < sizeof(trapped_signals)/sizeof(int)) {
123
+				upslog_sigaction.sa_handler = &term_handler;
124
+				sigfillset(&upslog_sigaction.sa_mask);
125
+				upslog_sigaction.sa_flags = SA_NOCLDSTOP | SA_NOCLDWAIT;
126
+				sigaction(trapped_signals[i], &upslog_sigaction, NULL);			}
127
+			writepid(pidfilebase);
128
+			while(wait(wait_status));
129
+			exit(EXIT_SUCCESS);
130
+		}
131
 	}
132
 
133
 	if (!monhost)
(-)b/sysutils/nut-devel/pkg-plist (+1 lines)
Lines 18-23 Link Here
18
@sample %%ETCDIR%%/upsmon.conf.sample
18
@sample %%ETCDIR%%/upsmon.conf.sample
19
@sample %%ETCDIR%%/upssched.conf.sample
19
@sample %%ETCDIR%%/upssched.conf.sample
20
@sample %%EXAMPLESDIR%%/newsyslog.sample etc/newsyslog.conf.d/nut.conf
20
@sample %%EXAMPLESDIR%%/newsyslog.sample etc/newsyslog.conf.d/nut.conf
21
@sample %%EXAMPLESDIR%%/nut_upslog.sample etc/syslog.d/nut
21
@sample %%EXAMPLESDIR%%/syslog.sample etc/syslog.d/nut
22
@sample %%EXAMPLESDIR%%/syslog.sample etc/syslog.d/nut
22
%%USB%%etc/devd/nut-usb.conf
23
%%USB%%etc/devd/nut-usb.conf
23
bin/nut-scanner
24
bin/nut-scanner
(-)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/nut_upslog.sample (+52 lines)
Added Link Here
1
#!/bin/sh
2
3
# Authored by vvd@unislabs.com.
4
5
# PROVIDE: nut_upslog
6
# REQUIRE: NETWORKING nut
7
# BEFORE: LOGIN
8
# KEYWORD: shutdown
9
10
. /etc/rc.subr
11
12
case $0 in
13
/etc/rc*)
14
	# during boot (shutdown) $0 is /etc/rc (/etc/rc.shutdown),
15
	# so get the name of the script from $_file
16
	name=$_file
17
	;;
18
*)
19
	name=$0
20
	;;
21
esac
22
23
name=${name##*/}
24
rcvar=${name}_enable
25
26
load_rc_config "${name}"
27
28
# Define these nut_upslog* variables in one of these files:
29
#       /etc/rc.conf
30
#       /etc/rc.conf.local
31
#       /etc/rc.conf.d/nut_upslog
32
#
33
# If you want to log several different UPSes:
34
# ln -s nut_upslog /usr/local/etc/rc.d/NAME
35
# then set variables NAME_enable, NAME_ups, NAME_pidbase, NAME_logfile and etc.
36
#
37
# DO NOT CHANGE THESE DEFAULT VALUES HERE
38
#
39
eval "${rcvar}=\${${rcvar}:-'NO'}"
40
eval "_prefix=\${${name}_prefix:-'/usr/local'}"
41
eval "_logfile=\${${name}_logfile:-'/var/log/nut/ups.log'}"
42
eval "_interval=\${${name}_interval:-'300'}"
43
eval "_ups=\${${name}_ups:-'myups@localhost'}"
44
eval "_pidbase=\${${name}_pidbase:-'upslog'}"
45
eval "_format=\${${name}_format:+-f \${${name}_format}}"
46
eval "${name}_flags=\${${name}_flags:-'-s ${_ups} -l ${_logfile} -i ${_interval} -p ${_pidbase} ${_format}'}"
47
48
required_dirs="%%STATEDIR%%"
49
pidfile="%%STATEDIR%%/${_pidbase}.pid"
50
command="${_prefix}/bin/upslog"
51
52
run_rc_command "$1"
(-)b/sysutils/nut/files/patch-clients_upslog.c (+133 lines)
Added Link Here
1
--- clients/upslog.c.orig	2022-08-21 09:28:11.630024000 -0700
2
+++ clients/upslog.c	2022-08-21 10:23:05.691271000 -0700
3
@@ -32,6 +32,10 @@
4
  */
5
 
6
 #include "common.h"
7
+#include <signal.h>
8
+#include <unistd.h>
9
+#include <sys/types.h>
10
+#include <sys/wait.h>
11
 #include "nut_platform.h"
12
 #include "upsclient.h"
13
 
14
@@ -41,17 +45,32 @@
15
 #include "upslog.h"
16
 
17
 	static	int	reopen_flag = 0, exit_flag = 0;
18
+	static  int	wait_status, child_pid;
19
 	static	uint16_t	port;
20
 	static	char	*upsname, *hostname;
21
 	static	UPSCONN_t	ups;
22
 
23
 	static	FILE	*logfile;
24
-	static	const	char *logfn, *monhost;
25
+	static	char *logfn, *monhost;
26
 	static	sigset_t	nut_upslog_sigmask;
27
 	static	char	logbuffer[LARGEBUF], *logformat;
28
 
29
 	static	flist_t	*fhead = NULL;
30
+	struct 	monhost_child {
31
+		char	*monhost;
32
+		char	*logfn;
33
+		char	*pidfilebase;
34
+		pid_t	pid;
35
+		struct	monhost_child	*next;
36
+	};
37
+	static	struct	monhost_child *monhost_child_anchor = NULL;
38
+	static	struct	monhost_child *monhost_child_current;
39
+	static	struct	monhost_child *monhost_child_prev = NULL;
40
+	static	char	*m_arg;
41
+	static	struct	sigaction upslog_sigaction;
42
+	static	int	trapped_signals[] = { SIGINT, SIGTERM, SIGCHLD };
43
 
44
+
45
 #define DEFAULT_LOGFORMAT "%TIME @Y@m@d @H@M@S% %VAR battery.charge% " \
46
 		"%VAR input.voltage% %VAR ups.load% [%VAR ups.status%] " \
47
 		"%VAR ups.temperature% %VAR input.frequency%"
48
@@ -393,21 +412,33 @@
49
 	 * -u <username>
50
 	 */
51
 
52
+static void term_handler(int signo)
53
+{
54
+	if (signo != SIGCHLD && monhost_child_anchor != NULL) {
55
+		for (monhost_child_current = monhost_child_anchor;
56
+		     monhost_child_current != NULL;
57
+		     monhost_child_current = monhost_child_current->next)
58
+			kill(monhost_child_current->pid, signo);
59
+		exit(signo);
60
+	}
61
+}
62
+
63
 int main(int argc, char **argv)
64
 {
65
 	int	interval = 30, i, foreground = -1;
66
+	size_t	monhost_len;
67
 	const char	*prog = xbasename(argv[0]);
68
 	time_t	now, nextpoll = 0;
69
 	const char	*user = NULL;
70
 	struct passwd	*new_uid = NULL;
71
-	const char	*pidfilebase = prog;
72
+	char	*pidfilebase = prog;
73
 
74
 	logformat = DEFAULT_LOGFORMAT;
75
 	user = RUN_AS_USER;
76
 
77
 	printf("Network UPS Tools %s %s\n", prog, UPS_VERSION);
78
 
79
-	while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:FB")) != -1) {
80
+	while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:FBm:")) != -1) {
81
 		switch(i) {
82
 			case 'h':
83
 				help(prog);
84
@@ -415,6 +446,19 @@
85
 				break;
86
 #endif
87
 
88
+			case 'm':
89
+				monhost_child_prev = monhost_child_current;
90
+				monhost_child_current = malloc(sizeof(struct monhost_child));
91
+				if (monhost_child_anchor == NULL)
92
+					monhost_child_anchor = monhost_child_current;
93
+				else
94
+					monhost_child_prev->next = monhost_child_current;
95
+				monhost_child_current->next = NULL;
96
+				m_arg = optarg;
97
+				monhost_child_current->monhost = strsep(&m_arg, ":");
98
+				monhost_child_current->logfn = strsep(&m_arg, ":");
99
+				monhost_child_current->pidfilebase = strsep(&m_arg, ":");
100
+				break;
101
 			case 's':
102
 				monhost = optarg;
103
 				break;
104
@@ -477,6 +521,29 @@
105
 
106
 		for (i = 3; i < argc; i++)
107
 			snprintfcat(logformat, LARGEBUF, "%s ", argv[i]);
108
+	}
109
+
110
+	if (monhost_child_anchor != NULL) {
111
+		for (monhost_child_current = monhost_child_anchor;
112
+		     monhost_child_current != NULL;
113
+		     monhost_child_current = monhost_child_current->next) {
114
+			if ((monhost_child_current->pid = fork()) == 0) {
115
+				monhost = monhost_child_current->monhost;
116
+				logfn = monhost_child_current->logfn;
117
+				pidfilebase = monhost_child_current->pidfilebase;
118
+				break;
119
+			}
120
+		}
121
+		if (monhost_child_anchor->pid) {
122
+			for (i = 0; i++; i < sizeof(trapped_signals)/sizeof(int)) {
123
+				upslog_sigaction.sa_handler = &term_handler;
124
+				sigfillset(&upslog_sigaction.sa_mask);
125
+				upslog_sigaction.sa_flags = SA_NOCLDSTOP | SA_NOCLDWAIT;
126
+				sigaction(trapped_signals[i], &upslog_sigaction, NULL);			}
127
+			writepid(pidfilebase);
128
+			while(wait(wait_status));
129
+			exit(EXIT_SUCCESS);
130
+		}
131
 	}
132
 
133
 	if (!monhost)
(-)b/sysutils/nut/pkg-plist (-1 / +1 lines)
Lines 18-23 Link Here
18
@sample %%ETCDIR%%/upsmon.conf.sample
18
@sample %%ETCDIR%%/upsmon.conf.sample
19
@sample %%ETCDIR%%/upssched.conf.sample
19
@sample %%ETCDIR%%/upssched.conf.sample
20
@sample %%EXAMPLESDIR%%/newsyslog.sample etc/newsyslog.conf.d/nut.conf
20
@sample %%EXAMPLESDIR%%/newsyslog.sample etc/newsyslog.conf.d/nut.conf
21
@sample %%EXAMPLESDIR%%/nut_upslog.sample etc/syslog.d/nut
21
@sample %%EXAMPLESDIR%%/syslog.sample etc/syslog.d/nut
22
@sample %%EXAMPLESDIR%%/syslog.sample etc/syslog.d/nut
22
%%USB%%etc/devd/nut-usb.conf
23
%%USB%%etc/devd/nut-usb.conf
23
bin/nut-scanner
24
bin/nut-scanner
24
- 

Return to bug 265963