[nut/f17] add support for foreground mode

Michal Hlavinka mhlavink at fedoraproject.org
Tue Sep 11 16:00:01 UTC 2012


commit fd2dceda3bba4ba15d4f47ba04bac59717db4a0c
Author: Michal Hlavinka <mhlavink at redhat.com>
Date:   Tue Sep 11 17:59:57 2012 +0200

    add support for foreground mode

 nut-2.6.5-foreground.patch |  129 ++++++++++++++++++++++++++++++++++++++++++++
 nut.spec                   |    7 ++-
 2 files changed, 135 insertions(+), 1 deletions(-)
---
diff --git a/nut-2.6.5-foreground.patch b/nut-2.6.5-foreground.patch
new file mode 100644
index 0000000..639cc54
--- /dev/null
+++ b/nut-2.6.5-foreground.patch
@@ -0,0 +1,129 @@
+diff -up nut-2.6.5/clients/upsmon.c.foreground nut-2.6.5/clients/upsmon.c
+--- nut-2.6.5/clients/upsmon.c.foreground	2012-07-31 19:38:58.000000000 +0200
++++ nut-2.6.5/clients/upsmon.c	2012-09-11 17:54:55.109343036 +0200
+@@ -1659,6 +1659,7 @@ static void help(const char *progname)
+ 	printf("		 - reload: reread configuration\n");
+ 	printf("		 - stop: stop monitoring and exit\n");
+ 	printf("  -D		raise debugging level\n");
++	printf("  -F		run in foreground, do not daemonize\n");
+ 	printf("  -h		display this help\n");
+ 	printf("  -K		checks POWERDOWNFLAG, sets exit code to 0 if set\n");
+ 	printf("  -p		always run privileged (disable privileged parent)\n");
+@@ -1873,7 +1874,7 @@ static void check_parent(void)
+ int main(int argc, char *argv[])  
+ {
+ 	const char	*prog = xbasename(argv[0]);
+-	int	i, cmd = 0, checking_flag = 0;
++	int	i, cmd = 0, checking_flag = 0, foreground = 0;
+ 
+ 	printf("Network UPS Tools %s %s\n", prog, UPS_VERSION);
+ 
+@@ -1884,7 +1885,7 @@ int main(int argc, char *argv[])
+ 
+ 	run_as_user = xstrdup(RUN_AS_USER);
+ 
+-	while ((i = getopt(argc, argv, "+Dhic:f:pu:VK46")) != -1) {
++	while ((i = getopt(argc, argv, "+DFhic:f:pu:VK46")) != -1) {
+ 		switch (i) {
+ 			case 'c':
+ 				if (!strncmp(optarg, "fsd", strlen(optarg)))
+@@ -1901,6 +1902,9 @@ int main(int argc, char *argv[])
+ 			case 'D':
+ 				nut_debug_level++;
+ 				break;
++			case 'F':
++				foreground = 1;
++				break;
+ 			case 'f':
+ 				free(configfile);
+ 				configfile = xstrdup(optarg);
+@@ -1976,9 +1980,9 @@ int main(int argc, char *argv[])
+ 		exit(EXIT_FAILURE);
+ 	}
+ 
+-	if (nut_debug_level < 1) {
++	if (!foreground && nut_debug_level < 1) {
+ 		background();
+-	} else {
++	} else if (nut_debug_level >= 1) {
+ 		upsdebugx(1, "debug level is '%d'", nut_debug_level);
+ 	}
+ 	
+diff -up nut-2.6.5/scripts/systemd/nut-monitor.service.in.foreground nut-2.6.5/scripts/systemd/nut-monitor.service.in
+--- nut-2.6.5/scripts/systemd/nut-monitor.service.in.foreground	2012-09-11 17:56:05.037920175 +0200
++++ nut-2.6.5/scripts/systemd/nut-monitor.service.in	2012-09-11 17:56:05.038920183 +0200
+@@ -4,9 +4,8 @@ After=local-fs.target network.target nut
+ 
+ [Service]
+ ExecStartPre=-/usr/bin/systemd-tmpfiles --create /etc/tmpfiles.d/nut-client.conf
+-ExecStart=@SBINDIR@/upsmon
+-PIDFile=@PIDPATH@/upsmon.pid
+-Type=forking
++ExecStart=@SBINDIR@/upsmon -F
++Type=simple
+ 
+ [Install]
+ WantedBy=multi-user.target
+diff -up nut-2.6.5/scripts/systemd/nut-server.service.in.foreground nut-2.6.5/scripts/systemd/nut-server.service.in
+--- nut-2.6.5/scripts/systemd/nut-server.service.in.foreground	2012-09-11 17:56:19.850042294 +0200
++++ nut-2.6.5/scripts/systemd/nut-server.service.in	2012-09-11 17:56:19.851042303 +0200
+@@ -5,8 +5,8 @@ Requires=nut-driver.service
+ Before=nut-monitor.service
+ 
+ [Service]
+-ExecStart=@SBINDIR@/upsd 
+-Type=forking
++ExecStart=@SBINDIR@/upsd -F
++Type=simple
+ 
+ [Install]
+ WantedBy=multi-user.target
+diff -up nut-2.6.5/server/upsd.c.foreground nut-2.6.5/server/upsd.c
+--- nut-2.6.5/server/upsd.c.foreground	2012-07-31 19:38:58.000000000 +0200
++++ nut-2.6.5/server/upsd.c	2012-09-11 17:54:55.109343036 +0200
+@@ -819,6 +819,7 @@ static void help(const char *progname)
+ 	printf("		 - reload: reread configuration files\n");
+ 	printf("		 - stop: stop process and exit\n");
+ 	printf("  -D		raise debugging level\n");
++	printf("  -F		run in foreground, do not daemonize\n");
+ 	printf("  -h		display this help\n");
+ 	printf("  -r <dir>	chroots to <dir>\n");
+ 	printf("  -q		raise log level threshold\n");
+@@ -882,7 +883,7 @@ void check_perms(const char *fn)
+ 
+ int main(int argc, char **argv)
+ {
+-	int	i, cmd = 0;
++	int	i, cmd = 0, foreground = 0;
+ 	char	*chroot_path = NULL;
+ 	const char	*user = RUN_AS_USER;
+ 	struct passwd	*new_uid = NULL;
+@@ -898,7 +899,7 @@ int main(int argc, char **argv)
+ 
+ 	printf("Network UPS Tools %s %s\n", progname, UPS_VERSION);
+ 
+-	while ((i = getopt(argc, argv, "+h46p:qr:i:fu:Vc:D")) != -1) {
++	while ((i = getopt(argc, argv, "+hF46p:qr:i:fu:Vc:D")) != -1) {
+ 		switch (i) {
+ 			case 'h':
+ 				help(progname);
+@@ -936,6 +937,10 @@ int main(int argc, char **argv)
+ 				nut_debug_level++;
+ 				break;
+ 
++			case 'F':
++				foreground = 1;
++				break;
++
+ 			case '4':
+ 				opt_af = AF_INET;
+ 				break;
+@@ -1023,7 +1028,7 @@ int main(int argc, char **argv)
+ 	/* handle upsd.users */
+ 	user_load();
+ 
+-	if (!nut_debug_level) {
++	if (!nut_debug_level && !foreground) {
+ 		background();
+ 		writepid(pidfn);
+ 	} else {
diff --git a/nut.spec b/nut.spec
index 53a19ab..06ec136 100644
--- a/nut.spec
+++ b/nut.spec
@@ -14,7 +14,7 @@
 Summary: Network UPS Tools
 Name: nut
 Version: 2.6.5
-Release: 3%{?dist}
+Release: 4%{?dist}
 Group: Applications/System
 License: GPLv2+
 Url: http://www.networkupstools.org/
@@ -27,6 +27,7 @@ Patch1: nut-2.6.3-tmpfiles.patch
 Patch3: nut-2.6.5-quickfix.patch
 Patch5: nut-2.6.5-dlfix.patch
 Patch6: nut-2.6.5-pthreadfix.patch
+Patch7: nut-2.6.5-foreground.patch
 
 Requires(pre): shadow-utils udev
 Requires(post): fileutils chkconfig 
@@ -118,6 +119,7 @@ necessary to develop NUT client applications.
 %patch3 -p1 -b .quickfix
 %patch5 -p1 -b .dlfix
 %patch6 -p1 -b .pthreadfix
+%patch7 -p1 -b .foreground
 
 sed -i 's|=NUT-Monitor|=nut-monitor|'  scripts/python/app/nut-monitor.desktop
 sed -i "s|sys.argv\[0\]|'%{_datadir}/%{name}/nut-monitor/nut-monitor'|" scripts/python/app/NUT-Monitor
@@ -501,6 +503,9 @@ rm -rf %{buildroot}
 %{_libdir}/pkgconfig/libnutscan.pc
 
 %changelog
+* Tue Sep 11 2012 Michal Hlavinka <mhlavink at redhat.com> - 2.6.5-4
+- add support for foreground mode
+
 * Tue Sep 11 2012 Michal Hlavinka <mhlavink at redhat.com> - 2.6.5-3
 - do not forget to restart nut-driver.service in postun
 


More information about the scm-commits mailing list