[NoCat] Patch: daemonize-04.patch
Karl Gaissmaier
karl.gaissmaier at kiz.uni-ulm.de
Mon, 28 Jul 2003 23:44:42 +0200
--------------Boundary-00=_IE8R520H6YQ8AGHS6MD7
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 8bit
Name:
daemonize-04.patch
Affected Files:
bin/gateway
lib/NoCat/Firewall.pm
lib/NoCat.pm
libexec/iptables/initialize.fw
Version: Patch against 0.82 or later
Severity:
unimportant, just a better (IMHO) handling going daemon
Description:
If you choose syslogging still some messages are sent to
the terminal, since the authors forgot to close
STDIN, STDOUT, STDERR and logging itself should be polished
in some pieces.
This patch add some code to go daemon as you learn it from
standard unix system programming books.
Additional with this code, the daemon chdir's to '/'
which makes small changes in Modules necessary that depend
on the current working dir of the daemon, like Firewall.pm
and initialize.fw for the throttling part.
--
Karl Gaissmaier KIZ/Infrastructure, University of Ulm, Germany
Email: karl.gaissmaier@kiz.uni-ulm.de Service Group Network
--------------Boundary-00=_IE8R520H6YQ8AGHS6MD7
Content-Type: text/x-diff;
charset="us-ascii";
name="daemonize-04.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="daemonize-04.patch"
diff -Naur NoCatAuth-nightly/bin/gateway NoCatAuth-mod/bin/gateway
--- NoCatAuth-nightly/bin/gateway 2003-03-08 02:56:51.000000000 +0100
+++ NoCatAuth-mod/bin/gateway 2003-07-26 17:06:36.000000000 +0200
@@ -58,7 +58,21 @@
} elsif ( not defined $pid ) {
die "Can't fork: $!";
}
- setsid;
+
+ die "Cannot detach from controlling terminal"
+ unless setsid();
+
+ chdir '/' or die "Can't chdir('/'), $!\n";
+ umask 0;
+
+ # reopen stdin to /dev/null
+ open(STDIN, "</dev/null");
+
+ # reopen stdout, stderr to /dev/null if not needed for logging
+ if ($server->{LogFacility} eq 'syslog') {
+ open(STDOUT, ">/dev/null");
+ open(STDERR, ">&STDOUT");
+ }
}
# Fork a child process and watch it, if we're in debug mode.
diff -Naur NoCatAuth-nightly/lib/NoCat/Firewall.pm NoCatAuth-mod/lib/NoCat/Firewall.pm
--- NoCatAuth-nightly/lib/NoCat/Firewall.pm 2003-02-12 03:56:42.000000000 +0100
+++ NoCatAuth-mod/lib/NoCat/Firewall.pm 2003-07-26 17:11:24.000000000 +0200
@@ -21,6 +21,10 @@
MembersOnly RouteOnly IgnoreMAC
);
+# not in qw() in order to have independent patches
+# put these independent patches together in the next release -- charly
+push @Perform_Export, 'BinPath';
+
# If /proc/net/arp is available, use it. Otherwise, fork /sbin/arp and read
# its output to get ARP cache data. Turns out '/sbin/arp -an' gives the same
# output on both Linux and *BSD. (Thank goodness.)
diff -Naur NoCatAuth-nightly/lib/NoCat.pm NoCatAuth-mod/lib/NoCat.pm
--- NoCatAuth-nightly/lib/NoCat.pm 2003-07-13 12:00:04.000000000 +0200
+++ NoCatAuth-mod/lib/NoCat.pm 2003-07-26 17:08:47.000000000 +0200
@@ -54,6 +54,9 @@
### Where to look for form templates?
DocumentRoot => "$FindBin::Bin/../htdocs",
+ ### Where to look for executables
+ BinPath => "$FindBin::Bin",
+
### Default log level.
Verbosity => 5,
LogFacility => "internal",
diff -Naur NoCatAuth-nightly/libexec/iptables/initialize.fw NoCatAuth-mod/libexec/iptables/initialize.fw
--- NoCatAuth-nightly/libexec/iptables/initialize.fw 2003-03-27 04:21:04.000000000 +0100
+++ NoCatAuth-mod/libexec/iptables/initialize.fw 2003-07-26 17:07:49.000000000 +0200
@@ -235,7 +235,7 @@
#
# chmod +x throttle.fw
#
-[ -x throttle.fw ] && throttle.fw
+[ -x $BinPath/throttle.fw ] && $BinPath/throttle.fw
##
# Add any other local firewall rules below.
--------------Boundary-00=_IE8R520H6YQ8AGHS6MD7--