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

Collapse All | Expand All

(-)b/sysutils/nut-devel/files/patch-clients_upslog.c (-6 / +20 lines)
Lines 1-5 Link Here
1
--- clients/upslog.c.orig	2022-08-26 15:25:26.539215000 -0700
1
--- clients/upslog.c.orig	2022-08-28 22:34:12.351696000 -0700
2
+++ clients/upslog.c	2022-08-26 15:26:10.909994000 -0700
2
+++ clients/upslog.c	2022-08-28 22:35:54.626531000 -0700
3
@@ -32,6 +32,10 @@
3
@@ -32,6 +32,10 @@
4
  */
4
  */
5
 
5
 
Lines 85-98 Link Here
85
 	printf("Network UPS Tools %s %s\n", prog, UPS_VERSION);
85
 	printf("Network UPS Tools %s %s\n", prog, UPS_VERSION);
86
 
86
 
87
-	while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:FB")) != -1) {
87
-	while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:FB")) != -1) {
88
+	while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:FBm:")) != -1) {
88
+	while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:FBm:D")) != -1) {
89
 		switch(i) {
89
 		switch(i) {
90
 			case 'h':
90
 			case 'h':
91
 				help(prog);
91
 				help(prog);
92
@@ -415,6 +452,33 @@
92
@@ -415,6 +452,36 @@
93
 				break;
93
 				break;
94
 #endif
94
 #endif
95
 
95
 
96
+			case 'D':
97
+				nut_debug_level++;
98
+				break;
96
+			case 'm': { /* var scope */
99
+			case 'm': { /* var scope */
97
+				char *m_arg, *s;
100
+				char *m_arg, *s;
98
+
101
+
Lines 123-129 Link Here
123
 			case 's':
126
 			case 's':
124
 				monhost = optarg;
127
 				monhost = optarg;
125
 				break;
128
 				break;
126
@@ -477,6 +541,41 @@
129
@@ -477,6 +544,52 @@
127
 
130
 
128
 		for (i = 3; i < argc; i++)
131
 		for (i = 3; i < argc; i++)
129
 			snprintfcat(logformat, LARGEBUF, "%s ", argv[i]);
132
 			snprintfcat(logformat, LARGEBUF, "%s ", argv[i]);
Lines 135-151 Link Here
135
+		else
138
+		else
136
+			daemon_pid = fork();
139
+			daemon_pid = fork();
137
+		if (!daemon_pid) {
140
+		if (!daemon_pid) {
141
+			pid_t child_pid;
138
+			upsdebugx(1,"Forking to log %" PRIuSIZE " devices", monhost_len);
142
+			upsdebugx(1,"Forking to log %" PRIuSIZE " devices", monhost_len);
139
+			for (monhost_child_current = monhost_child_anchor;
143
+			for (monhost_child_current = monhost_child_anchor;
140
+			     monhost_child_current != NULL;
144
+			     monhost_child_current != NULL;
141
+			     monhost_child_current = monhost_child_current->next) {
145
+			     monhost_child_current = monhost_child_current->next) {
142
+				if ((monhost_child_current->pid = fork()) == 0) {
146
+				if ((child_pid = fork()) == 0) {
147
+					upsdebugx(1,"Forking to device");
143
+					monhost = monhost_child_current->monhost;
148
+					monhost = monhost_child_current->monhost;
144
+					logfn = monhost_child_current->logfn;
149
+					logfn = monhost_child_current->logfn;
145
+					pidfilebase = monhost_child_current->pidfilebase;
150
+					pidfilebase = monhost_child_current->pidfilebase;
146
+					foreground = 1;
151
+					foreground = 1;
147
+					break;
152
+					break;
148
+				}
153
+				}
154
+				if (child_pid < 0)
155
+					upslog_with_errno(LOG_ERR, "Fork to device failed");
156
+				else
157
+					monhost_child_current->pid = child_pid;
149
+			}
158
+			}
150
+			if (monhost_child_anchor->pid) {	/* parent */
159
+			if (monhost_child_anchor->pid) {	/* parent */
151
+				for (mh = 0; mh < sizeof(trapped_signals)/sizeof(trapped_signals[0]); mh++) {
160
+				for (mh = 0; mh < sizeof(trapped_signals)/sizeof(trapped_signals[0]); mh++) {
Lines 154-165 Link Here
154
+					upslog_sigaction.sa_flags = SA_NOCLDSTOP | SA_NOCLDWAIT;
163
+					upslog_sigaction.sa_flags = SA_NOCLDSTOP | SA_NOCLDWAIT;
155
+					sigaction(trapped_signals[mh], &upslog_sigaction, NULL);
164
+					sigaction(trapped_signals[mh], &upslog_sigaction, NULL);
156
+				}
165
+				}
166
+				upsdebugx(1,"Waiting for children");
157
+				become_user(get_user_pwent(user));
167
+				become_user(get_user_pwent(user));
158
+				writepid(pidfilebase);
168
+				writepid(pidfilebase);
159
+				while(wait(&wait_status) > 0);
169
+				while(wait(&wait_status) > 0);
170
+				upsdebugx(1,"Wait complete");
160
+				exit(EXIT_SUCCESS);
171
+				exit(EXIT_SUCCESS);
161
+			}
172
+			}
173
+		} else if (daemon_pid < 0) {
174
+			upslog_with_errno(LOG_ERR, "gethostname failed");
162
+		} else {
175
+		} else {
176
+			upsdebugx(1,"Initial parent terminated");
163
+			exit(EXIT_SUCCESS);
177
+			exit(EXIT_SUCCESS);
164
+		}
178
+		}
165
 	}
179
 	}
(-)b/sysutils/nut/files/patch-clients_upslog.c (-6 / +21 lines)
Lines 1-5 Link Here
1
--- clients/upslog.c.orig	2022-08-26 15:25:00.233023000 -0700
1
--- clients/upslog.c.orig	2022-08-28 22:33:49.935888000 -0700
2
+++ clients/upslog.c	2022-08-26 15:26:30.983822000 -0700
2
+++ clients/upslog.c	2022-08-28 22:36:29.395001000 -0700
3
@@ -32,6 +32,10 @@
3
@@ -32,6 +32,10 @@
4
  */
4
  */
5
 
5
 
Lines 85-98 Link Here
85
 	printf("Network UPS Tools %s %s\n", prog, UPS_VERSION);
85
 	printf("Network UPS Tools %s %s\n", prog, UPS_VERSION);
86
 
86
 
87
-	while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:FB")) != -1) {
87
-	while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:FB")) != -1) {
88
+	while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:FBm:")) != -1) {
88
+	while ((i = getopt(argc, argv, "+hs:l:i:f:u:Vp:FBm:D")) != -1) {
89
 		switch(i) {
89
 		switch(i) {
90
 			case 'h':
90
 			case 'h':
91
 				help(prog);
91
 				help(prog);
92
@@ -415,6 +452,33 @@
92
@@ -415,6 +452,36 @@
93
 				break;
93
 				break;
94
 #endif
94
 #endif
95
 
95
 
96
+			case 'D':
97
+				nut_debug_level++;
98
+				break;
96
+			case 'm': { /* var scope */
99
+			case 'm': { /* var scope */
97
+				char *m_arg, *s;
100
+				char *m_arg, *s;
98
+
101
+
Lines 123-129 Link Here
123
 			case 's':
126
 			case 's':
124
 				monhost = optarg;
127
 				monhost = optarg;
125
 				break;
128
 				break;
126
@@ -477,6 +541,40 @@
129
@@ -477,6 +544,52 @@
127
 
130
 
128
 		for (i = 3; i < argc; i++)
131
 		for (i = 3; i < argc; i++)
129
 			snprintfcat(logformat, LARGEBUF, "%s ", argv[i]);
132
 			snprintfcat(logformat, LARGEBUF, "%s ", argv[i]);
Lines 135-150 Link Here
135
+		else
138
+		else
136
+			daemon_pid = fork();
139
+			daemon_pid = fork();
137
+		if (!daemon_pid) {
140
+		if (!daemon_pid) {
141
+			pid_t child_pid;
142
+			upsdebugx(1,"Forking to log %" PRIuSIZE " devices", monhost_len);
138
+			for (monhost_child_current = monhost_child_anchor;
143
+			for (monhost_child_current = monhost_child_anchor;
139
+			     monhost_child_current != NULL;
144
+			     monhost_child_current != NULL;
140
+			     monhost_child_current = monhost_child_current->next) {
145
+			     monhost_child_current = monhost_child_current->next) {
141
+				if ((monhost_child_current->pid = fork()) == 0) {
146
+				if ((child_pid = fork()) == 0) {
147
+					upsdebugx(1,"Forking to device");
142
+					monhost = monhost_child_current->monhost;
148
+					monhost = monhost_child_current->monhost;
143
+					logfn = monhost_child_current->logfn;
149
+					logfn = monhost_child_current->logfn;
144
+					pidfilebase = monhost_child_current->pidfilebase;
150
+					pidfilebase = monhost_child_current->pidfilebase;
145
+					foreground = 1;
151
+					foreground = 1;
146
+					break;
152
+					break;
147
+				}
153
+				}
154
+				if (child_pid < 0)
155
+					upslog_with_errno(LOG_ERR, "Fork to device failed");
156
+				else
157
+					monhost_child_current->pid = child_pid;
148
+			}
158
+			}
149
+			if (monhost_child_anchor->pid) {	/* parent */
159
+			if (monhost_child_anchor->pid) {	/* parent */
150
+				for (mh = 0; mh < sizeof(trapped_signals)/sizeof(trapped_signals[0]); mh++) {
160
+				for (mh = 0; mh < sizeof(trapped_signals)/sizeof(trapped_signals[0]); mh++) {
Lines 153-164 Link Here
153
+					upslog_sigaction.sa_flags = SA_NOCLDSTOP | SA_NOCLDWAIT;
163
+					upslog_sigaction.sa_flags = SA_NOCLDSTOP | SA_NOCLDWAIT;
154
+					sigaction(trapped_signals[mh], &upslog_sigaction, NULL);
164
+					sigaction(trapped_signals[mh], &upslog_sigaction, NULL);
155
+				}
165
+				}
166
+				upsdebugx(1,"Waiting for children");
156
+				become_user(get_user_pwent(user));
167
+				become_user(get_user_pwent(user));
157
+				writepid(pidfilebase);
168
+				writepid(pidfilebase);
158
+				while(wait(&wait_status) > 0);
169
+				while(wait(&wait_status) > 0);
170
+				upsdebugx(1,"Wait complete");
159
+				exit(EXIT_SUCCESS);
171
+				exit(EXIT_SUCCESS);
160
+			}
172
+			}
173
+		} else if (daemon_pid < 0) {
174
+			upslog_with_errno(LOG_ERR, "gethostname failed");
161
+		} else {
175
+		} else {
176
+			upsdebugx(1,"Initial parent terminated");
162
+			exit(EXIT_SUCCESS);
177
+			exit(EXIT_SUCCESS);
163
+		}
178
+		}
164
 	}
179
 	}

Return to bug 265963