Module: check_mk
Branch: master
Commit: bd07f94ea7c38ebe3193fe20937653a9fd5b181f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=bd07f94ea7c38e…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Fri Sep 28 13:58:56 2018 +0200
6410 FIX Determine the parent process more reliably
Previously, the parent process was determined by parsing
/proc/{PID}/stat and columns where assumed to be separated by space.
This was unreliable because the filename in the second
column may contain a space as well. If omd was issued e.g. from tmux
the process name "tmux: server" was used. This resulted in a traceback
during e.g. omd rm. Now the psutil module is used to determine the
parent process.
Change-Id: If0a52723a2d95f961973912a4ee3418de90fbef2
---
.werks/6410 | 16 ++++++++++++++++
omd/packages/omd/omd | 9 +++++----
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/.werks/6410 b/.werks/6410
new file mode 100644
index 0000000..367276c
--- /dev/null
+++ b/.werks/6410
@@ -0,0 +1,16 @@
+Title: Determine the parent process more reliably
+Level: 1
+Component: omd
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1538138123
+Class: fix
+
+Previously, the parent process was determined by parsing
+/proc/{PID}/stat and columns where assumed to be separated by space.
+This was unreliable because the filename in the second
+column may contain a space as well. If omd was issued e.g. from tmux
+the process name "tmux: server" was used. This resulted in a traceback
+during e.g. omd rm. Now the psutil module is used to determine the
+parent process.
diff --git a/omd/packages/omd/omd b/omd/packages/omd/omd
index 280a4f6..56c68b2 100644
--- a/omd/packages/omd/omd
+++ b/omd/packages/omd/omd
@@ -66,6 +66,7 @@ import errno
import fcntl
import shlex
import pprint
+import psutil
import random
import shutil
import socket
@@ -3967,10 +3968,10 @@ def kill_site_user_processes(exclude_current_and_parents=False):
def get_current_and_parent_pids():
"""Return list of PIDs of the current process and parent process tree
till pid 0"""
pids = []
- pid = os.getpid()
- while pid != 0:
- pids.append(pid)
- pid = int(file("/proc/%d/stat" % pid).read().split(" ")[3])
+ process = psutil.Process()
+ while process and process.pid != 0:
+ pids.append(process.pid)
+ process = process.parent()
return pids