xinit exits with failure on SIGTERM
Upon receiving a SIGTERM signal, xinit does a graceful stop, cleanly stopping the Xserver and any child applications, but still always exits with a failure:
if (gotSignal != 0) {
Errorx("unexpected signal %d", gotSignal);
exit(EXIT_FAILURE);
}
This is annoying for use cases where xinit is started by a service manager like systemd (for example in a HTPC or other appliance-like deployment running a single full-screen application). If systemd kills xinit, eg. on shutdown, this is always logged as an unclean stop, despite the fact that it was actually graceful. (in most other use cases, typically the child will initiate exit, which is handled cleanly.)
Can xinit return success instead, if it was able to stop cleanly? I think basically the few lines shown above can just be removed from xinit.c (the signal is not "unexpected" as it says), it checks for clean server/client exit next:
if (serverpid < 0)
Fatalx("server error");
if (clientpid < 0)
Fatalx("client error");
exit(EXIT_SUCCESS);
This will return failure only when there was an actual failure to stop cleanly, and success otherwise.