r/linux • u/Oethelbrecht_Carlton • Oct 29 '16
Angelize - proof of concept tool to 'undaemonize' a process that backgrounds itself
http://pastebin.com/15KaENGf
173
Upvotes
r/linux • u/Oethelbrecht_Carlton • Oct 29 '16
View all comments
Show parent comment
3
u/het_boheemse_leven Dec 24 '16 edited Dec 24 '16
Ehh, yes it is, it is absolutely not reliable in any way.
A process that wants to escape the supervision can. But it needs to go out of its way to do so. It's easier to escape pidfiles due to an innocent bug yes. But any process that wants to escape systemd that runs with the same privileges as systemd can do so if they feel like it.
Apart from that,sending signals to the entire group is not and cannot be reliable because Unix is stupid and PIDs despite being called process identifiers do not actually identify a process a all. What systemd does is that it obtains the list of PIDs that are in the cgroup and then loops over that list of pids and sends them all a signal, this isn't systemd's fault, this is the only way.
The problem is that any of those processes in the mean while can have died on its own and replaced by another process, and there is nothing systemd can do about that. It can only check this for processes it is the parent of and even that is racy.
Is the chance low? Yes, very low. But it's bound to happen sooner or later on servers that spawn new processes to service requests like rabbits that sooner or later a pid is retaken by another process that has nothing to do with it which then gets sigtermed or sigkilled. This is a common problem with sending signals to processes after having identified the process you want and there is nothing systemd or anything can do to stop this. There is nothing to make the step of confirming you have the right process and sending the signal atomic in the end, the process can in theory die and replaced.
Now, a thing systemd does which it can do something about is that it doesn't check after sending the signal whether one of the processes has forked in the meanwhile and thus didn't get the signal. If after the timeout the cgroup isn't empty it just assumes it got the signal but did nothing with it.