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

70

u/ShadowPouncer May 29 '16

This is one of those things which really has good arguments both ways.

If I'm running a desktop session, and I log out of that session, with few exceptions nothing should be left running.

If I start up a terminal instance, and I put things into the background, run them under screen or tmux, run them with nohup, or just start a daemon as my own user, those things should NOT be killed when I close the terminal or when I log out.

And even more so if I login via ssh.

tmux and screen are mildly special, however I would strongly argue that anything launched from an interactive terminal session should be treated as equally 'special' by systemd.

This is only problematic because you can start a terminal session from your desktop session, and that might need to involve some systemd/PAM hooks in the terminal emulator of your choice.

But stop treating everything like a bloody graphical desktop systemd.

57

u/lubutu May 29 '16

Isn't this what SIGHUP was made for anyway? Systemd can send hang-up signals to all processes in the session, and those that aren't meant to hang up can ignore it.

7

u/flying-sheep May 30 '16

there are no fine-grained semantics for this on linux.

SIGHUP means “detach from terminal” but it says nothing about if the process then is a persistent daemon or one that should stay only for the duration of the user session.

  • ssh-agent is a daemon that should definitely be killed on logoff
  • tmux is one that should definitely stay

there’s no way to distinguish between one or the other. (other than the thing systemd says tmux should use)

1

u/lubutu May 30 '16

If systemd sent SIGHUP to every process in the session then those that are meant to live on, like tmux, can ignore it, and those that are meant not to, like ssh-agent, can terminate, even if it is a daemon with no tty. What distinguishes the two is simply whether they catch SIGHUP.

12

u/argv_minus_one May 29 '16

What is the systemd crew's rationale for killing every process in the session instead of sending only SIGHUP?

I tried Googling for an answer to this question, but didn't find one. Perhaps they simply didn't think of it?

7

u/tso May 29 '16

Over at a certain debian bug report thread, a link was provided to a systemd issue that in turn points to a change in dbus behavior.

https://github.com/systemd/systemd/issues/2900

Frankly it seems like we are looking at multiple overlapping systems that all have their own take on the term "session".

Note btw that the initial issue have crap all to do with the terminal, but heavy terminal users are those that are getting thrown out with the bath water.

Should not be surprising though, as systemd and the rest is developed from the DE point of view. I really loath the day that the Linux ecosystem shifted from a kernel up mentality to a DE down mentality.

1

u/argv_minus_one May 29 '16

That doesn't say anything about SIGHUP…

4

u/pstch May 29 '16

I'm also trying to understand why they didn't think SIGHUP was adapted for this.

1

u/[deleted] May 30 '16

Because NIH (tm) and Not Invented Yesterday (tm).

→ More replies (2)

24

u/Lennartwareparty May 29 '16

If I'm running a desktop session, and I log out of that session, with few exceptions nothing should be left running.

Why not? Graphical desktops as it stands contain terminals as well.

There's actually such a thing as X re-attachement. Some programs made for this elect not to kill themselves when the X server closes and yes, the protocol specifically allows for this if you have a good reason. If I start an IRC bouncer through X I very much like it to continue to live after I log out, that's sort of the point now isn't it?

Obviously this can still be done with this systemd-ism, but the problem is the one that is outlined in this link. systemd has the balls to ask people to include special code just for them. There is one standard which works throughout Unix, and one that is required for systemd systems which kill processes even if they have detached from their controlling terminal and nohupped for them to continue to run.

2

u/ShadowPouncer May 30 '16

TIL regarding X re-attachment.

However as it stands there is no good default-close standard for X sessions that matches SIGHUP (with the very standard method of detaching from the controlling terminal and/or catching SIGHUP to remain running).

This is suboptimal.

Now, personally I think that the right option is probably to give everything started via the GUI a controlling terminal and to hang up that controlling terminal when the session ends, though I'm sure that would have the potential for unintended side effects.

But regardless I do think that some kind of solution is needed, and since I'm not writing the solution myself I'm not going to throw stones at the solution for the GUI that they are writing.

I just think that it needs to stay the hell away from anything that starts it's life with a controlling terminal, and that very much includes stuff that you start from a terminal inside an X session.

2

u/Lennartwareparty May 30 '16

However as it stands there is no good default-close standard for X sessions that matches SIGHUP (with the very standard method of detaching from the controlling terminal and/or catching SIGHUP to remain running).

Well, there is, xlib and xcb by default make applications exit when X is closed down, this is similar to HUP, an application however may always choose to ignore it or do something else if it thinks that is appropriate for its functioning, just as it can ignore HUP

It's more that there is no aequivalent of nohup for X programs, you can't start it in such a way to make it ignore that X ends, it has to do it on its own if it thinks that's a sane idea.

The reason that is pointed out that this exists is because a change in DBus bugged out in GNOME or something which meant that a bunch of background processes which used to exit when X quit no longer do and thus keep accumilating themselves.

1

u/Lazerguns May 30 '16

systemd has the balls to ask people to include special code just for them.

Depends on how you read it. If you read it as a suggestion to make tmux work better with the standard init system on the platform that 99% of tmux users are using it doesn't take much "balls".

3

u/gorgikosev May 29 '16

Which is why the best way to do it is to keep existing behaviour but introduce systemd-run-soft to soft-daemonize programs. Those would be closed if unresponsive after HUP when the desktop session ends.

13

u/SubwayMonkeyHour May 29 '16

If I'm running a desktop session, and I log out of that session, with few exceptions nothing should be left running.

I'd argue that this applies to servers as well... I actually think it applies even more than desktops because if I log in to the server and running commands I don't want anything left increasing the attack surface after I log out. If I wanted it to be running after I log out I'd use the process manager be it systemd, supervisor, etc.

24

u/ShadowPouncer May 29 '16

I commented on a child comment, but this really belongs here:

Absolutely anything launched from an interactive terminal session, regardless of if it's a local terminal or ssh or something else, has had a method to deal with this for an exceptionally long time.

As mentioned in other comments, it is called SIGHUP, and it is sent when the controlling terminal 'hangs up'.

The default action of SIGHUP is to terminate the process.

Anything that either disconnects from the PTY or intercepts SIGHUP is already taking steps to prevent itself from being killed on logout, and that should not be overridden by systemd just because the GUI world needs a similar solution.

3

u/flying-sheep May 30 '16

but that doesn’t carry semantics about the end of the user session, only about the moment the terminal disconnects.

when you start ssh-agent and tmux, the former should die at logoff and the latter not. yet there’s no API to mark which should behave how.

3

u/ShadowPouncer May 30 '16

If ssh-agent wants to die at logoff, it should not catch SIGHUP, and it should not detach from it's controlling terminal.

Both catching SIGHUP and detaching from the controlling terminal take active work, so it already takes an active decision, via a standard POSIX API, to decide to remain running in a terminal session after the user session terminates.

https://en.wikipedia.org/wiki/SIGHUP

Now, you could argue that ssh-agent has decided to do these things when it should not have, but the point is that it has decided to do these things, and this is a wheel that really doesn't need to be reinvented.

1

u/flying-sheep May 30 '16

why should it stay attached to its terminal? it’s a daemon, it doesn’t output things, and it should stay active in the background until logoff.

that’s what it wants to do. it also stays after logoff, but that’s unintentional.

26

u/Yioda May 29 '16 edited May 29 '16

Then fucking kill it before logout, or run it through a systemd-broken-terminal! We are talking functionality that has been working since day 0 in unix. It is disgusting that people actually support this attitude of repeteadly breaking working code "because we know what's better for you".

e: BTW, sorry for the tone, my anger is not really against you.

0

u/[deleted] May 29 '16

[deleted] — view deleted comment

17

u/Yioda May 29 '16

What that has to do with anything? (really, I don't get it) If you, as a user, don't want processes lingering when you logout, take and active action to kill the processes, and then logout. Or if you want the system to do it automatically for you, run it through a service that has that functionality. But don't change basic unix default job control behaviour and working code. The systemd option should default to off.

→ More replies (3)
→ More replies (2)
→ More replies (8)