knotty: Deal with exceptions not resetting terminal configuration

When an exception occurred, the terminal parameters (such as echo)
may not be reset correctly. This change ensures they do get
atexit time in all cases, avoiding the terminal corruption issues
that could sometimes occur.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
bitbake-worker: Gracefully handle SIGTERM

Currently if bitbake-worker handles a SIGTERM, it leaves the child
processes to complete or hang. It shouldn't do this so hook the SIGTERM
event and gracefully shutdown any children.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
runqueue.py: Handle worker disappearing gracefully

If the worker (or fakeworker) process disappears for some reason, the
system doesn't currently even notice. To fix this, we call waitpid
periodically, looking for exit events of our children. If these
occur, we can gracefully shutdown the server.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
runqueue.py: Gracefully handle a missing worker process

If the worker has already gone missing (e.g. SIGTERM), we should
gracefully handle the write failures at exit time rather than throwing
ugly tracebacks.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
cooker/command: Add setFeatures command

Add a command to allow backends to set particular 'features' on the
cooker (server).

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
server/process: Use the setFeatures command on the server instead of a manger

The use of a manager in the process server causes some issues since it remains
around for the lifetime of the server even though its only used during
initialisation and the system doesn't respond well to SIGTERM events
to the extra process (and two threads) the implementation involves.

Switching to a dedicated command simplifies the server process structure.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
server/process: Deal more gracefully with SIGTERM

Currently a SIGTERM to the UI process causes the UI simply to lock up.

By setting an exit flag, the waitEvent can raise a SIGINT, allowing the
UI to break out the event loop and exit. Currently this is results in a
traceback but that is more desirable than a hanging process.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
cooker: Handle SIGTERM more gracefully

If the cooker receives a SIGTERM it currently hangs using 100% CPU,

This patch adds in an intercept for the event and puts the cooker into
shutdown mode allowing it to exit cleanly/safely and avoiding the hang.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
providers/runqueue/taskdata: Optimise logger.debug calls

A run of "bitbake bash -c unpack" when the task has already been
completed resulted in about 9000 calls to logger.debug(). With this
patch which comments out some noisy/less usefull logging and moves
other logging calls outside loops, this number is reduced to 1000
calls. This results in cleaner logs and gives a small but
measurable 0.15s speedup. The log size dropped from 900kb to 160kb.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
knotty: Add missing continue statement for runQueueExitWait event

The continue statement was missing for this event and the event was then
listed in the "known safe to ignore list". Clean this up.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
knotty: Remove latency when exiting

There is no point in waiting 0.25s for when we should be processing
the shutdown. This simply reordering removes latency from the
bitbake command.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
server/process: Use a pipe for quit events instead of Event()

Its not possible to notice the change of status of an Event() in
the select call we sleep in. It would be possible in python 3.3 but
for now use a pipe instead. This removes small latency when bitbake
commands finish since the system doesn't sit in the select call.

(Debugging these kind of issues is apparent by setting a long sleep
for the select call)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
server/process: Drop unnecessary exit delay

When the server exits, we no longer appear to need this delay. This
is likely due to improvements in the various exit codepaths. There
is therefore no longer any point in taking the latency hit.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
server/process: Optimise latency when finishing idle functions

When idle functions finish, its likely we have some other work
to do, so don't sleep in the select call but instead, skip it.
This removes small amounts of latency in common commands.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
runqueue: Use SIGCHLD instead of polling waitpid

Instead of a significant number of calls to waitpid, register a SIGCHLD
handler instead.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>