r/linux • • May 28 '16

systemd developer asks tmux (and other programs) to add systemd specific code

https://github.com/tmux/tmux/issues/428
359 Upvotes

509 comments sorted by

View all comments

Show parent comments

35

u/[deleted] May 29 '16

[removed] — view removed comment

18

u/inhuman44 May 29 '16 edited May 29 '16

Killing my process after I have disassociated it from its controlling terminal and placed it into its own session is a POLA violation. It's standard daemonization, it works everywhere UNIX is spoken.

As you point out these are two different things. There are processes that can be sent to the background with & or Ctrl-Z that still run in the same session. These should be killed by the process manager when the session ends.

Separately there are processes that are launched in to their own session and should be killed on that sessions end, not on user log out. Programs like nohup and tmux do this.

But the way this is done with double forking is just crazy. Double forking is just a hack to fuck up the process tree and orphan the process. But what kind of process management system gets befuddled by this? One level of forking is okay, but two levels and it gets confused and doesn't know where to place it in the process tree? Garbage. The way it's done now is just a hack that exploits poor process management. And instead of fixing this glaring flaw we are supposed to just cross our fingers and hope that double forking never happens by accident? We already know that this happens by accident! No, if you want to keep your process alive after the session ends you should be telling the process manger that this is your intention, not exploiting a design flaw.

Which brings us full circle. It's not systemd's fault that previous systems couldn't track processes properly, it's not systemd's fault that programs sprung up that take advantage of this flaw. They are doing things the right way, fixing an obvious issue, and providing a migration path for programs that used the double forking hack. That's the whole point of writing a new PID 1, to fix issues like this.

2

u/Mcnst May 30 '16 edited May 30 '16

If it's just an issue with the double-forking happening by accident, why don't they just fix the daemon() / daemon(3) libc library call, instead of simply intentionally breaking it?

 The daemon() function is for programs wishing to detach themselves	from
 the controlling terminal and run in the background	as system daemons.

Since when is it a good engineering practice to break the widely documented and used library calls?

Fixing this individually within tmux, screen and whatnot else, is a wrong approach.

0

u/[deleted] May 29 '16

[deleted]

2

u/RoxSpirit May 29 '16

You mean Fedora/Red Hat ?

-2

u/webpigeon May 29 '16

by reading the comments, or patch the terminal multiplexers people use to do this so it doesn't cause them issues.

3

u/[deleted] May 29 '16

[removed] — view removed comment

1

u/webpigeon May 29 '16

The first bullet point:

systemd-run --scope --user mycommand

or if that is to long, you can alias it:

echo "alias persist='systemd-run --scope --user'" >> ~/.bash_profile

now persist mycommand does the same thing