From 368951712ad586084debbc87525fe658ad98eb6f Mon Sep 17 00:00:00 2001 From: Christian Wiese Date: Wed, 15 Aug 2012 10:06:42 +0200 Subject: [PATCH] nut: added patch for upsd to not detach from the controlling tty --- monitor/nut/nut-2.6.5-upsd-foreground.patch | 80 +++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 monitor/nut/nut-2.6.5-upsd-foreground.patch diff --git a/monitor/nut/nut-2.6.5-upsd-foreground.patch b/monitor/nut/nut-2.6.5-upsd-foreground.patch new file mode 100644 index 000000000..7ca3849bb --- /dev/null +++ b/monitor/nut/nut-2.6.5-upsd-foreground.patch @@ -0,0 +1,80 @@ +# --- SDE-COPYRIGHT-NOTE-BEGIN --- +# This copyright note is auto-generated by ./scripts/Create-CopyPatch. +# +# Filename: package/.../nut/nut-2.6.5-upsd-foreground.patch +# Copyright (C) 2012 The OpenSDE Project +# +# More information can be found in the files COPYING and README. +# +# This patch file is dual-licensed. It is available under the license the +# patched project is licensed under, as long as it is an OpenSource license +# as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms +# of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# --- SDE-COPYRIGHT-NOTE-END --- + +Description: Add option upsd to not detach from the controlling tty + +This is needed to run upsd by a supervise service like daemontools, +runit. + +The original default behavoir, which detaches from the controlling tty +and running in background has been preserved. +To run upsd in foreground you have to use the -f command option. + +diff -ruN nut-2.6.5-orig/common/common.c nut-2.6.5/common/common.c +--- nut-2.6.5-orig/common/common.c 2012-07-31 19:38:58.000000000 +0200 ++++ nut-2.6.5/common/common.c 2012-08-15 09:07:43.949002650 +0200 +@@ -32,6 +32,7 @@ + #include "nut_version.h" + const char *UPS_VERSION = NUT_VERSION_MACRO; + ++ int foreground = 0; + int nut_debug_level = 0; + int nut_log_level = 0; + static int upslog_flags = UPSLOG_STDERR; +diff -ruN nut-2.6.5-orig/include/common.h nut-2.6.5/include/common.h +--- nut-2.6.5-orig/include/common.h 2012-07-31 19:38:56.000000000 +0200 ++++ nut-2.6.5/include/common.h 2012-08-15 09:14:10.999949407 +0200 +@@ -52,6 +52,9 @@ + /* close ttys and become a daemon */ + void background(void); + ++/* do not detach from controlling tty and run in foreground */ ++extern int foreground; ++ + /* do this here to keep pwd/grp stuff out of the main files */ + struct passwd *get_user_pwent(const char *name); + +diff -ruN nut-2.6.5-orig/server/upsd.c nut-2.6.5/server/upsd.c +--- nut-2.6.5-orig/server/upsd.c 2012-07-31 19:38:58.000000000 +0200 ++++ nut-2.6.5/server/upsd.c 2012-08-15 09:07:43.949002650 +0200 +@@ -819,6 +819,7 @@ + printf(" - reload: reread configuration files\n"); + printf(" - stop: stop process and exit\n"); + printf(" -D raise debugging level\n"); ++ printf(" -f run in foreground\n"); + printf(" -h display this help\n"); + printf(" -r chroots to \n"); + printf(" -q raise log level threshold\n"); +@@ -936,6 +937,10 @@ + nut_debug_level++; + break; + ++ case 'f': ++ foreground = 1; ++ break; ++ + case '4': + opt_af = AF_INET; + break; +@@ -1023,7 +1028,7 @@ + /* handle upsd.users */ + user_load(); + +- if (!nut_debug_level) { ++ if ((!nut_debug_level) && (!foreground)) { + background(); + writepid(pidfn); + } else {