From 8b81cb559b3c06de1d44a2ebacab223dff57d818 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Mon, 13 Nov 2023 17:08:24 +0100 Subject: [PATCH] orphanskill: log command line arguments of the terminated process Closes: #1255 Closes: #1268 --- mock/integration-tests/daemontest.c | 2 +- mock/py/mockbuild/util.py | 17 ++++++++++++++++- .../better-orphankill-report.feature | 5 +++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 releng/release-notes-next/better-orphankill-report.feature diff --git a/mock/integration-tests/daemontest.c b/mock/integration-tests/daemontest.c index a05fd2550..e9023ddd9 100644 --- a/mock/integration-tests/daemontest.c +++ b/mock/integration-tests/daemontest.c @@ -8,7 +8,7 @@ * INFO: mock.py version 0.8.0 starting... * State Changed: start * State Changed: init - * WARNING: Process ID 12180 still running in chroot. Killing... + * WARNING: Leftover process 1331205 is being killed with signal 15: /builddir/a.out * */ diff --git a/mock/py/mockbuild/util.py b/mock/py/mockbuild/util.py index f435c79ae..a8cdd0f39 100644 --- a/mock/py/mockbuild/util.py +++ b/mock/py/mockbuild/util.py @@ -157,6 +157,20 @@ def file_dev_ino(path): return file_dev_ino(path1) == file_dev_ino(path2) +def get_pid_cmdline(pid): + """ + For given PID return the command-line arguments from /proc/PID/cmdline + """ + cmd_file = f"/proc/{pid}/cmdline" + try: + with open(cmd_file, "rb") as cmdline_file: + cmdline = cmdline_file.read().decode('utf-8').split('\0') + cmdline.pop() # last string is always empty in 0-terminated file + return ' '.join([shlex.quote(x) for x in cmdline]) + except OSError as e: + return f"ERROR: Can not read {pid} file {e}" + + @traceLog() def orphansKill(rootToKill, manual_forced=False): """ @@ -176,8 +190,9 @@ def orphansKill(rootToKill, manual_forced=False): try: root = os.readlink("/proc/%s/root" % fn) if compare_two_paths_cached(root, rootToKill, path_cache): - getLog().warning("Process ID %s still running in chroot. Killing with %s...", fn, killsig) pid = int(fn, 10) + getLog().warning("Leftover process %s is being killed with signal %s: %s", + pid, killsig, get_pid_cmdline(pid)) os.kill(pid, killsig) os.waitpid(pid, 0) except OSError: diff --git a/releng/release-notes-next/better-orphankill-report.feature b/releng/release-notes-next/better-orphankill-report.feature new file mode 100644 index 000000000..fb18686c1 --- /dev/null +++ b/releng/release-notes-next/better-orphankill-report.feature @@ -0,0 +1,5 @@ +The automatic killing feature for orphan processes within the chroot environment +[was][PR#1255] [improved][PR#1268] to also provide the user with information +about the command-line arguments of the terminated process: + +`WARNING: Leftover process 1331205 is being killed with signal 15: daemon --with-arg`