[01:48] <Keybuk> today I feel like I have a handle of the event expression atomicity issues
[02:45] <Keybuk> Interesting question
[02:45] <Keybuk> when upstart kills a process, should it just kill that process, or should it kill everything in that process's group?
[02:53] <shawarma> Keybuk: Good question. What about the session?
[02:54] <Keybuk> the session?
[02:54] <shawarma> Yup.
[02:54] <shawarma> getsid()
[02:55] <Keybuk> you can't kill a session
[02:55] <shawarma> If you SIGHUP the session leader, it trickles down to the other processes in the session.
[02:56] <Keybuk> actually, it's more complicated than that
[02:56] <shawarma> If you SIGTERM the session leader, it doesn't kill the rest of the processes, afair.
[02:56] <Keybuk> you don't mean session leader
[02:56] <Keybuk> you mean process group leader
[02:56] <shawarma> No, I'm quite sure I mean session leader.
[02:57] <Keybuk> and the SIGHUP thing only applies to the foreground process group with a controlling terminal
[02:57] <Keybuk> iirc.
[02:57] <shawarma> That's the session leader.
[02:57] <shawarma> Gah.. getsid has no man page. Gimme a sec.
[02:57] <Keybuk> the session leader is the first process in the session?
[02:57] <Keybuk> the one where the sid == pid
[02:57] <shawarma> Right.
[02:57] <Keybuk> setsid() gives you a process where pid == pgrp == sid
[02:58] <shawarma> Right.
[02:58] <Keybuk> ie. it's the session leader and a process group leader
[02:58] <Keybuk> process groups can exist without their leader
[02:59] <Keybuk> sessions contain one or more process groups
[03:00] <Keybuk> sessions can have a controlling terminal
[03:00] <shawarma> Right.
[03:01] <Keybuk> one of the process groups can be the foreground process group
[03:01] <Keybuk> all of the others are the background process groups
[03:01] <Keybuk> Control-C on the terminal will send SIGINT to all processes in the session's foreground process group
[03:01] <Keybuk> if the terminal is hung-up, SIGHUP is sent only to the session leader
[03:02] <shawarma> What causes the other processes in the session to die, then?
[03:03] <Keybuk> Control-Z sends SIGTSTP to all processes in the foreground process gruop
[03:03] <Keybuk> Control-\ sends SIGQUIT to all processes in the foreground process group
[03:04] <Keybuk> reading from standard input while you are not in the foreground process group will send SIGTTIN back to you
[03:04] <shawarma> ABout SIGHUP: "This signal is also generated if the session leader terminates. In this case the signal is sent to each process in the foreground process group". Hmm.. Is it the kernel doing that?
[03:04] <Keybuk> writing to a terminal while you are not in the foreground process group may either succeed or send SIGTTOU back to you
[03:05] <shawarma> (from APUE)
[03:05] <Keybuk> shawarma: dunno, not got that far yet (I'm in APUE too :p)
[03:05] <shawarma> *G*
[03:05] <shawarma> I cheated and skipped ahead. :)
[03:07] <Keybuk> children in a process group that are stopped are sent SIGHUP followed by SIGCONT if the process group they are in becomes orphaned
[03:07] <Keybuk> (ie. the parents of all processes in that process group are in different sessions)
[03:08] <Keybuk> SIGHUP is only sent if there is a controlling terminal
[03:09] <Keybuk> if the session leader terminates, SIGHUP is sent to the foreground process group (apparently)
[03:12] <shawarma> By whom?
[03:12] <shawarma> Must be the kernel..
[03:17] <Keybuk> -- entering new session
[03:17] <Keybuk> pid: 9171
[03:17] <Keybuk> pgrp: 9171
[03:17] <Keybuk> sid: 9171
[03:17] <Keybuk> -- execing shell script
[03:17] <Keybuk> --shell
[03:17] <Keybuk> pid: 9172
[03:17] <Keybuk> pgrp: 9171
[03:17] <Keybuk> sid: 9171
[03:17] <Keybuk> --end shell
[03:17] <Keybuk> ok
[03:17] <Keybuk> so that's a session leader that execs a shell, which runs a single command
[03:17] <Keybuk> the shell is 9171
[03:17] <Keybuk> the process group and session of the simple command is also 9171
[03:17] <Keybuk> but the pid of the thing run in it is 9172
[03:17] <Keybuk> which makes sense
[03:24] <Keybuk> doesn't get SIGHUP here
[03:26] <Keybuk> aha
[03:26] <Keybuk> does if it has a terminal
[03:26] <Keybuk> -- entering new session
[03:26] <Keybuk> -- taking control of terminal
[03:26] <Keybuk> pid: 9618
[03:26] <Keybuk> pgrp: 9618
[03:26] <Keybuk> sid: 9618
[03:26] <Keybuk> -- execing shell script
[03:26] <Keybuk> -- shell 9618
[03:26] <Keybuk> pid: 9619
[03:27] <Keybuk> ppid: 9618
[03:27] <Keybuk> pgrp: 9618
[03:27] <Keybuk> sid: 9618
[03:27] <Keybuk> -- end shell
[03:27] <Keybuk> 9619 got SIGHUP
[03:27] <Keybuk> -- exit
[03:27] <Keybuk> right
[03:27] <Keybuk> SIGHUP comes from the terminal control driver only
[03:36] <Keybuk> that makes sense
[03:36] <Keybuk> so the question is still valid
[03:37] <shawarma> I forgot the question :)
[03:37] <Keybuk> when upstart wants to kill a job, should it just send TERM to dash (which won't kill anything else since there's no terminal) or to the entire process group?
[03:38] <Keybuk> and how will this affect services with multiple processes, since they'll all get TERM, rather than just the top one?
[03:38] <shawarma> How does that work, actually? You iterate throguh the process space looking for things with the same pgid?
[03:38] <Keybuk> killpg :p
[03:38] <Keybuk> thom: how would apache cope with that?
[03:40] <shawarma> I think each request each child is handling would be dropped and the top process would clean up the mess..
[03:44] <Keybuk> yeah
[03:44] <Keybuk> I think killpg is reasonable here
[03:45] <Keybuk> (it's also what sysvinit does ... I never noticed that)
[03:47] <Keybuk> *giggle*
[03:47] <Keybuk> well, that change royally buggered up my test suite
[06:01] <Keybuk> yay
[06:01] <Keybuk> job->cause is gone
[06:02] <AlexExtreme> whoo
[06:03] <Keybuk> though I now have a stack of issues with the new code ;o)
[06:03] <Keybuk> in particular
[06:03] <Keybuk>   start on foo and bar
[06:03] <Keybuk>   stop on frodo and bilbo
[06:03] <Keybuk> ...
[06:03] <Keybuk> if you stop that, and then foo happens quickly afterwards, it will start again
[06:03] <Keybuk> because the event tree still has the true values, and it's still enough to touch it
[06:03] <Keybuk> but if it happens after it has properly stopped, you need both foo and bar to happen again
[06:03] <Keybuk> (likewise for the stop on bit)
[06:04] <Keybuk> the way to solve that, I think, is to reference an "Event Expression" not just the root "Event Operator"
[06:04] <Keybuk> Event Expression would be the root Event Operator, and also an Event State
[06:05] <Keybuk> if the root operator becomes TRUE, the matching events from the tree are copied into the Event State, and then the operator tree is reset
[06:05] <Keybuk> the job would respond to the expression, so it retains the state while requiring the match to happen all over again