HomePhabricator

Make many minor improvements to daemon behavior

Description

Make many minor improvements to daemon behavior

Summary:
Ref T10811.

First, declare() at constructor scope doesn't actually work properly, because PHP is a beautiful language full of wonderful and interesting ideas. Instead, it affects file scope (or something???). In practice, this is often the same thing, except that sometimes it isn't.

To reproduce this, run:

libphutil/ $ echo '{}' | php ./scripts/daemon/exec/exec_daemon.php PhutilHangForeverDaemon --verbose

Then send it SIGTERM. Before the change, it ignores the signal. Now, it exits properly.

Second, stuff was printing <<VERB>> and such by accident because of typos. Fix the extra <> so this just prints <VERB>. I observed proper terminal output after this patch.

Third, always print when we catch a signal. Hopefully this will help identify possible problems related to rogue signals. I observed messages about caught signals.

Fourth, when a script emits some text on stderr, print each line separately. This aligns things better and makes them easier to read. I observed multi-line messages spread across multiple lines with headers on each line, aligning more readably.

Fifth, add a missing period

Sixth, after a subprocess gets kill -9'd, exit with error code 128 + 9 (137) instead of -1 (and likewise for other signal codes, if any exist). I kill -9'd a daemon and saw a more useful exit code.

Test Plan:
See above for particulars.

Also ran bin/phd debug ... and signaled processes, observed normal operation and more useful log output.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10811

Differential Revision: https://secure.phabricator.com/D15977