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