Skip to content

Commit

Permalink
orphanskill: log command line arguments of the terminated process
Browse files Browse the repository at this point in the history
  • Loading branch information
praiskup committed Dec 12, 2023
1 parent 806998b commit 3db85f8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mock/integration-tests/daemontest.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
*/

Expand Down
15 changes: 14 additions & 1 deletion mock/py/mockbuild/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ def file_dev_ino(path):
return ret
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):
Expand All @@ -176,8 +188,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:
Expand Down
5 changes: 5 additions & 0 deletions releng/release-notes-next/better-orphankill-report.feature
Original file line number Diff line number Diff line change
@@ -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`

0 comments on commit 3db85f8

Please sign in to comment.