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

0

u/[deleted] May 28 '16

[deleted] — view deleted comment

72

u/inhuman44 May 29 '16

Except systemd isn't causing a problem.

Ending all of the user's processes when that user's session ends is how it should work. This is in inline with Rule of Least Surprise. These are settings that any rational user would expect: I log out, my programs close.

If for some reason you want to make an except to the general rule and don't want your program to exit on session end there is a mechanism to facilitate that. This too makes perfect sense, most user programs should be exiting on session end; if a process is to be an exception then it should be so explicitly. Defaulting to the exceptional case is just bad design.

Finally there exists a small handful of user programs (like tmux) that always stay alive after user logout. For the sake of convenience, there is a mechanism for these programs to stay alive after session end implicitly.

If the distros and package maintainers want to change the default behaviour for the sake of tradition, or to cater to a certain type of user, or for backwards compatibility, or whatever that is fine. All the power to them. But that is not a reason for the upstream developers to abandon sane defaults.

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] — view deleted comment

2

u/RoxSpirit May 29 '16

You mean Fedora/Red Hat ?

→ More replies (4)

17

u/MertsA May 29 '16

most user programs should be exiting on session end

And to add to this, most user programs that don't exit on session end aren't supposed to do that and they are now hung up and need to be terminated.

1

u/[deleted] May 30 '16 edited May 30 '16

This is in inline with Rule of Least Surprise.

Having the option is fine. Having it on by default is breaking a 30 year old behavior some users rely on. That's bad. That's not even the "least surprise".

Edit: Just imagine Linux changing the result of a system call because the new implementation follows the rule of the least surprise better. And it's of course also safer, faster and more convinient for the average case. It would still break compatibility and cause one hell of a headache. The folks from systemd should learn that they have a similar responsibility to not break userspace.

→ More replies (1)

51

u/slacka123 May 28 '16 edited May 28 '16

I guess you missed the memo. Lennart Poettering is never wrong not the least bit arrogant.

→ More replies (10)

0

u/[deleted] May 29 '16

[deleted] — view deleted comment

0

u/[deleted] May 29 '16

[deleted] — view deleted comment

0

u/[deleted] May 29 '16

[deleted] — view deleted comment

34

u/gnuvince May 29 '16 edited May 29 '16

The only hostility I see is people complaining about changes with little to no technical arguments.

This is the same hostility you see from Linus when a well-meaning developer introduces a change in the kernel that breaks userspace; they may have a very good reason for doing so, it may make things better in some technical sense, but their changes are rejected with (usually) a long, angry tirade, and rightly so. systemd 230 introduces a change in its default configuration that breaks userspace; yes, it may be "more right" now, but it breaks existing programs, scripts, and workflows and it should rightly be criticized.

2

u/Ripdog May 29 '16

systemd 230 introduces a change in its default configuration that breaks userspace; yes, it may be "more right" now, but it breaks existing programs, scripts, and workflows and it should rightly be criticized

That sounds like and argument for windows-style eternal backwards compatibility even when the old behaviour didn't make sense [for most people].

2

u/MertsA May 29 '16

And doubly so when it's the distributions job to take care of this stuff. If this is the default for RHEL 8 or Debian 9 then who cares? It's a slight change and by then I'm sure it'll be seamless. If this is a change that broke or changed the behavior of your current install of Linux then your distribution sucks and they screwed up.

13

u/MertsA May 29 '16

The fact that regular user processes that I don't implicitly daemonize or screen don't terminate when I logout is news me.

They kind of do, on logout all of your old processes should terminate except for basically just screen and tmux. The problem is that it's not like anything goes through and kill -9s your old processes, they sometimes don't terminate, even when they should so you get buggy behavior like this: https://github.com/systemd/systemd/issues/2975

The fix is to have systemd terminate any process that's not cleaning up after itself. The problem is that screen and tmux are running under the user scope and there's not really a good way for systemd to know that screen isn't actually hung up, it's supposed to stick around after logout. You could do something like look at the process name and hardcode an exception for tmux and screen but that's a terrible idea and there's already an easy way to run things in a different scope that you don't kill.

8

u/buried_treasure May 29 '16

You could do something like look at the process name and hardcode an exception for tmux and screen but that's a terrible idea

But it's an equally terrible idea for these programs to put in a bunch of systemd-specific code. Even if all Linux distributions used systemd (and they don't, yet) tmux and screen have life far outside the Linux world. It makes little sense to have a ton of code in their source just to interact with one specific Linux init service, when all the other unixes have inits that work in the traditional manner.

5

u/MertsA May 29 '16

Either way, the correct fix is not to just assume that any hung program is supposed to be hung up. The user can currently just start it outside of their scope but it's unreasonable to expect the user to manually run screen and tmux in their own scope. If you asked anyone, Linux user, Windows user, OSX, etc what happens if they log into a computer, run some software, and then logout, they are all going to tell you that the software is closed. That's the accepted behavior. Historically Linux hasn't had anything that would terminate processes that didn't exit cleanly when they were supposed to. Now that's fixed but there's nothing to indicate whether or not a process is willfully sticking around after logout or if it's just broken. How is it a terrible idea for screen or tmux to put in some code in their existing platform compatibility code to tell systemd to run it in it's own scope? That's what that platform specific code is there for, to abstract away all platform specific features.

10

u/buried_treasure May 29 '16

Historically Linux hasn't had anything that would terminate processes that didn't exit cleanly when they were supposed to. Now that's fixed

One man's fix is another man's breakage.

Your claim is correct for people who are making use of a single-user desktop-oriented system.

As a server administrator I spend a large amount of my professional time running processes on Linux boxes (including processes as specific users) which, if I don't want to be fired, must continue to run when I log off and leave the office each evening.

→ More replies (5)