Blame SOURCES/0041-Ticket-49157-ds-logpipe.py-crashes-for-non-existing-.patch

74ca47
From a842e43becb9312574071b1460bfa835bfecc47b Mon Sep 17 00:00:00 2001
74ca47
From: Mark Reynolds <mreynolds@redhat.com>
74ca47
Date: Mon, 8 May 2017 14:12:53 -0400
74ca47
Subject: [PATCH] Ticket 49157 -  ds-logpipe.py crashes for non-existing users
74ca47
74ca47
Description:  Remove all "raises", and gracefully exit with a message
74ca47
74ca47
https://pagure.io/389-ds-base/issue/49157
74ca47
74ca47
Reviewed by: firstyear(Thanks!)
74ca47
74ca47
(cherry picked from commit 94ebab36770465a50e3f61590f0f1adec2cc9224)
74ca47
---
74ca47
 ldap/admin/src/scripts/ds-logpipe.py | 18 ++++++++++++------
74ca47
 1 file changed, 12 insertions(+), 6 deletions(-)
74ca47
74ca47
diff --git a/ldap/admin/src/scripts/ds-logpipe.py b/ldap/admin/src/scripts/ds-logpipe.py
74ca47
index dc1856a..13712ea 100644
74ca47
--- a/ldap/admin/src/scripts/ds-logpipe.py
74ca47
+++ b/ldap/admin/src/scripts/ds-logpipe.py
74ca47
@@ -146,7 +146,8 @@ def open_pipe(logfname):
74ca47
             if e.errno == errno.EINTR:
74ca47
                 continue # open was interrupted, try again
74ca47
             else: # hard error
74ca47
-                raise Exception("%s [%d]" % (e.strerror, e.errno))
74ca47
+                print("%s [%d]" % (e.strerror, e.errno))
74ca47
+                sys.exit(1)
74ca47
     return logf
74ca47
 
74ca47
 def is_proc_alive(procpid):
74ca47
@@ -156,7 +157,8 @@ def is_proc_alive(procpid):
74ca47
     except IOError as e:
74ca47
         if e.errno != errno.ENOENT: # may not exist yet - that's ok
74ca47
             # otherwise, probably permissions or other badness
74ca47
-            raise Exception("could not open file %s - %s [%d]" % (procfile, e.strerror, e.errno))
74ca47
+            print("could not open file %s - %s [%d]" % (procfile, e.strerror, e.errno))
74ca47
+            sys.exit(1)
74ca47
     # using /proc/pid failed, try kill
74ca47
     if not retval:
74ca47
         try:
74ca47
@@ -177,7 +179,8 @@ def get_pid_from_file(pidfile):
74ca47
         except IOError as e:
74ca47
             if e.errno != errno.ENOENT: # may not exist yet - that's ok
74ca47
                 # otherwise, probably permissions or other badness
74ca47
-                raise Exception("Could not read pid from file %s - %s [%d]" % (pidfile, e.strerror, e.errno))
74ca47
+                print("Could not read pid from file %s - %s [%d]" % (pidfile, e.strerror, e.errno))
74ca47
+                sys.exit(1)
74ca47
         if line:
74ca47
             procpid = int(line)
74ca47
     return procpid
74ca47
@@ -188,7 +191,8 @@ def write_pid_file(pidfile):
74ca47
         pfd.write("%d\n" % os.getpid())
74ca47
         pfd.close()
74ca47
     except IOError as e:
74ca47
-        raise Exception("Could not write pid to file %s - %s [%d]" % (pidfile, e.strerror, e.errno))
74ca47
+        print("Could not write pid to file %s - %s [%d]" % (pidfile, e.strerror, e.errno))
74ca47
+        sys.exit(1)
74ca47
 
74ca47
 def handle_script_pidfile(scriptpidfile):
74ca47
     scriptpid = get_pid_from_file(scriptpidfile)
74ca47
@@ -216,7 +220,8 @@ def read_and_process_line(logf, plgfuncs):
74ca47
             if e.errno == errno.EINTR:
74ca47
                 continue # read was interrupted, try again
74ca47
             else: # hard error
74ca47
-                raise Exception("%s [%d]" % (e.strerror, e.errno))
74ca47
+                print("%s [%d]" % (e.strerror, e.errno))
74ca47
+                sys.exit(1)
74ca47
     if line: # read something
74ca47
         for plgfunc in plgfuncs:
74ca47
             if not plgfunc(line):
74ca47
@@ -312,7 +317,8 @@ except OSError as e:
74ca47
             print("Failed to create log pipe: " + str(e))
74ca47
             sys.exit(1)
74ca47
     else:
74ca47
-        raise Exception("%s [%d]" % (e.strerror, e.errno))
74ca47
+        print("Failed to create log pipe - %s [error %d]" % (e.strerror, e.errno))
74ca47
+        sys.ext(1)
74ca47
 
74ca47
 if debug:
74ca47
     print("Listening to log pipe", logfname, "number of lines", maxlines)
74ca47
-- 
74ca47
2.9.4
74ca47