sofar/xorg-launch-helper — pull request #2 by kangkai (2012-08-23 03:24:26+00:00)
Title: Generate the pidfile of Xorg

Generate the pidfile of Xorg, so that we can help systemd to retrieve Xorg's
PID by specify "PIDFile=" keyword in .service file.

The pidfile location: "XDG_RUNTIME_DIR"/Xorg.pid

The background story why we need this patch:

Basically this little launch helper forks and puts Xorg running background as
daemon, waits a very short time till when Xorg is ready then exits. This kind
of "double fork" makes kernel re-parent Xorg to PID 1 (which is system
systemd).

This behavior is not a issue as long as you're running this helper (to launch
Xorg) and service as system systemd only. But for the systemd integration that
using user session to launch Xorg, the "re-parent Xorg to PID 1" makes Xorg
loses babysit of user systemd. Which leaves issue when system shuts down.

E.g. We've observed job that trying to stop xorg.service can't get finished
during shutdown, until a 90s timeout, and user-session@xxx.service get killed
(SIGKILL). This is because when Xorg get SIGTERM-ed and quit, neither user
systemd nor system systemd can be properly notified and trigger its belonging
xorg.service to a stop/done state.

* For the system systemd, it gets the SIGCHLD when Xorg quit, but it won't
go further since Xorg is not in it's watching pids;

* For the user systemd, it does not even got the SIGCHLD, since it lost
tracking of this child during booting up;

This patch is helping user systemd to get tracked of Xorg by specify PIDFile,
by adding this line into the xorg.service file:

PIDFile=%t/Xorg.pid

I've verified, it works.

Signed-off-by: Yin Kangkai
Signed-off-by: Karol Lewandowski
Signed-off-by: "Kok, Auke-jan H"