Implement -P to invoke a program as pre-hook before killing a process#348
Implement -P to invoke a program as pre-hook before killing a process#348manuelafm wants to merge 1 commit intorfjakob:masterfrom
Conversation
|
This is a follow-up to what we talked about in a previous merge-request about reading from the environment of the process. I am not very happy with the delay, because of the reasons explained in the README (not very elegant, arbitrary length, adding stress to a stressed system, etc). But of course, the program has to have some time to inspect the running process and gather information not available with the I though about sending SIGSTOP or similar to the would-be-victim, to at least stop a memory-hog program to cause further harm in the (small) delay, but then it prevents the process to react to SIGTERM in those cases, IIUC. But I hope that at least you find it useful for further discussion. |
This implements an option to invoke an external program, analog to the existing "-N" (which runs a program after killing a process), but being executed before sending signals to the process, with purposes such as gathering some specific info of the running process.
b3aa49c to
3867dd7
Compare
| kill_process_prehook(args, victim); | ||
|
|
||
| warn("sleeping for %ums to allow the prehook to act\n", PREHOOK_STARTUP_SLEEP_MS); | ||
| usleep(PREHOOK_STARTUP_SLEEP_MS * 1000); |
There was a problem hiding this comment.
Instead of a set sleep here, this should probably be a waitpid( <pre-hook-pid> ) call with a timeout.
That also allows an error to be printed for cases where the pre-hook timed out. And avoid any output if everything behaved as expected.
There was a problem hiding this comment.
Agreed for both.
Do you have a suggestion for the wait with timeout? https://man7.org/linux/man-pages/man2/signalfd.2.html ?
There was a problem hiding this comment.
I’m not familiar with what environment earlyoom needs to compile against. But if we can assume a Linux kernel > 5.3 I think the simplest and most robust approach would be:
There was a problem hiding this comment.
Almost three years since 30f968b , I think pidfd_open is ok.
This will allow us to properly check the exit code of the pre-notify script ( #348 ) which would not be possible when ignoring SIGCHLD. Ignoring SIGCHLD causes the kernel to auto-reap children and we cannot access the exit code.
|
Merged and added the waitpid-with-timeout as 8913fb2 on top. Thanks. |
Thanks to you! 🙏 As a side question, are you planning to tag a release soonish? Not critical here, but since the last one happened more than 1 year ago, it would be nice for distros to pick-up some of these new features and fixes (most of them rarely use the tip of master/main branches). |
|
Right, released v1.9.0 |
That's great, thanks! |
This implements an option to invoke an external program, analog to the existing "-N" (which runs a program after killing a process), but being executed before sending signals to the process, with purposes such as gathering some specific info of the running process.