[master] Introducing a proper syslog daemon allows us to remove the syslogd stub we have.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 backend.py                 |    7 +--
 backend_log.py             |   61 ++++++++++++++++++++++++++
 command-stubs/syslogd-stub |   34 --------------
 scripts/upd-instroot       |    1 -
 syslogd.py                 |  104 --------------------------------------------
 5 files changed, 64 insertions(+), 143 deletions(-)
 create mode 100644 backend_log.py
 delete mode 100755 command-stubs/syslogd-stub
 delete mode 100644 syslogd.py

diff --git a/backend.py b/backend.py
index 5ddeb8c..cdccc78 100644
--- a/backend.py
+++ b/backend.py
@@ -25,7 +25,7 @@ import shutil
 import iutil
 import os, sys
 import logging
-from syslogd import syslog
+import backend_log
 from constants import *
 
 import isys
@@ -105,9 +105,8 @@ class AnacondaBackend:
             shutil.copytree(d, "/root/" + os.path.basename(d))
 
         storage.writeEscrowPackets(anaconda)
-
         sys.stdout.flush()
-        syslog.stop()
+        backend_log.log.stop()
 
     def doInstall(self, anaconda):
         log.warning("doInstall not implemented for backend!")
@@ -137,7 +136,7 @@ class AnacondaBackend:
             shutil.rmtree (syslogname)
         except OSError:
             pass
-        syslog.start (instPath, syslogname)
+        backend_log.log.start(instPath, syslogname)
 
         if upgrade:
             self.modeText = _("Upgrading %s\n")
diff --git a/backend_log.py b/backend_log.py
new file mode 100644
index 0000000..d30281f
--- /dev/null
+++ b/backend_log.py
@@ -0,0 +1,61 @@
+import commands
+import logging
+import os
+import shutil
+import signal
+
+SYSLOG_PATH           = '/sbin/rsyslogd'
+SYSLOG_PIDFILE        = '/var/run/syslogd.pid'
+SYSLOG_CFGFILE        = '/etc/rsyslog.conf'
+SYSLOG_CFGFILE_BACKUP = '/etc/rsyslog.conf~'
+
+CFG_TEMPLATE = """
+$InputUnixListenSocketHostName sysimage
+$AddUnixListenSocket %(socket)s
++sysimage
+*.* %(logfile)s;RSYSLOG_TraditionalFileFormat
+"""
+
+global_log = logging.getLogger("anaconda")
+class BackendSyslog:
+    def __init__(self):
+        pass
+    
+    def build_cfg(self, root, log):
+        socket = "%s/dev/log" % (root, )
+        cfg = CFG_TEMPLATE % {
+            'socket'  : socket,
+            'logfile' : log
+            }
+        with open(SYSLOG_CFGFILE, 'a') as cfg_file:
+            cfg_file.write(cfg)
+
+    def save_cfg(self):
+        shutil.copy(SYSLOG_CFGFILE, SYSLOG_CFGFILE_BACKUP)
+        
+    def sighup(self):
+        pid = 0
+        with open(SYSLOG_PIDFILE, 'r') as pid_file:
+            pid = int(pid_file.read())
+        if pid != 0:
+            try:
+                os.kill(pid, signal.SIGHUP)
+            except OSError:
+                # syslogd might be dead but that shouldn't stop us
+                global_log.error("Syslog daemon is not running. Backend log won't work")
+
+    def start(self, root, log):
+        self.save_cfg()
+        self.build_cfg(root, log)
+        self.sighup()
+        global_log.info("Backend log started.")
+    
+    def restore_cfg(self):
+        shutil.copy(SYSLOG_CFGFILE_BACKUP, SYSLOG_CFGFILE)
+    
+    def stop(self):
+        self.restore_cfg()
+        self.sighup()
+        global_log.info("Backend log stopped.")
+
+log = BackendSyslog()
diff --git a/command-stubs/syslogd-stub b/command-stubs/syslogd-stub
deleted file mode 100755
index 2f3af92..0000000
--- a/command-stubs/syslogd-stub
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/usr/bin/python
-#
-# syslogd-stub
-#
-# Copyright (C) 2007  Red Hat, Inc.  All rights reserved.
-#
-# This program is free software; you can redistribute it and/or modify
-# it 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.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-#
-
-import sys
-sys.path.append('/usr/lib/anaconda')
-
-def usage():
-    sys.stderr.write("syslogd [root] [output file]")
-
-if __name__ == "__main__":
-    from syslogd import Syslogd
-    if len(sys.argv) != 3:
-        usage()
-        sys.exit(1)
-    root = sys.argv[1]
-    output = sys.argv[2]
-    syslog = Syslogd (root, open (output, "a"))
diff --git a/scripts/upd-instroot b/scripts/upd-instroot
index 551bd11..e111c58 100755
--- a/scripts/upd-instroot
+++ b/scripts/upd-instroot
@@ -996,7 +996,6 @@ cp $DEST/usr/lib/anaconda/losetup-stub $DEST/usr/bin/losetup
 cp $DEST/usr/lib/anaconda/list-harddrives-stub $DEST/usr/bin/list-harddrives
 cp $DEST/usr/lib/anaconda/loadkeys-stub $DEST/usr/bin/loadkeys
 cp $DEST/usr/lib/anaconda/mknod-stub $DEST/usr/bin/mknod
-cp $DEST/usr/lib/anaconda/syslogd-stub $DEST/usr/bin/syslogd
 mv $DEST/usr/sbin/anaconda $DEST/usr/bin/anaconda
 mv $DEST/usr/lib/anaconda-runtime/lib* $DEST/usr/$LIBDIR 2>/dev/null
 
diff --git a/syslogd.py b/syslogd.py
deleted file mode 100644
index 267b7fd..0000000
--- a/syslogd.py
+++ /dev/null
@@ -1,104 +0,0 @@
-#
-# syslogd.py - a simple syslogd implementation and wrapper for launching it
-#
-# Copyright (C) 1999, 2000, 2001  Red Hat, Inc.  All rights reserved.
-#
-# This program is free software; you can redistribute it and/or modify
-# it 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.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-#
-# Author(s): Erik Troan <ewt@xxxxxxxxxx>
-#
-
-import sys, os
-import string
-from socket import *
-from select import select
-
-import logging
-log = logging.getLogger("anaconda")
-
-class Syslogd:
-    def goSyslog(self, output, sockName):
-	sock = socket(AF_UNIX, SOCK_STREAM)
-
-	try:
-	    os.unlink(sockName)
-	except os.error:
-	    pass
-
-	sock.bind(sockName)
-	acceptedFds = []
-	sock.listen(5)
-
-	while (1):
-	    list = acceptedFds + [ sock ]
-	    list = select(list, [], [])[0]
-	    try:
-		list.remove(sock)
-		(fd, remoteAddr) = sock.accept()
-		acceptedFds.append(fd)
-	    except ValueError:
-		pass
-
-	    for fd in list:
-		msg = fd.recv(50)
-                msg = string.replace(msg, chr(0), "\n")
-		if (msg):
-		    output.write(msg)
-                    output.flush()
-		else:
-		    acceptedFds.remove(fd)
-		    fd.close()
-
-    def __init__(self, root = "", output = sys.stdout, socket = "/dev/log"):
-	filename = root + socket;
-        self.goSyslog(output, filename)
-
-class InstSyslog:
-    def __init__ (self):
-        self.pid = -1;
-
-    def start (self, root, log):
-        # don't run in the "install from livecd" case
-        if not os.path.exists("/usr/bin/syslogd"): 
-            return
-        self.pid = os.fork ()
-        if not self.pid:
-            # look on PYTHONPATH first, so we use updated anaconda
-            path = "/usr/bin/syslogd"
-            if os.environ.has_key('PYTHONPATH'):
-                for f in string.split(os.environ['PYTHONPATH'], ":"):
-                    if os.access (f+"/syslogd", os.X_OK):
-                        path = f+"/syslogd"
-                        break
-
-            if os.path.exists(path):
-                os.execv (path, ("syslogd", root, log))
-
-    def stop(self):
-        if self.pid == -1:
-            log.warn("syslogd not running to kill!")
-            return
-        try:
-            os.kill (self.pid, 15)
-        except OSError as e:
-            log.error("killing syslogd failed: %s %s" %(e.errno, e.strerror))
-	
-        try:
-	    os.waitpid (self.pid, 0)
-        except OSError as e:
-            log.error("exception from waitpid in syslogd::stop: %s %s" % (e.errno, e.strerror))
-
-        self.pid = -1
-
-syslog = InstSyslog()
-- 
1.6.2.5

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux