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

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