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

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