Replace system_command_* and run_command_* APIs with simpler spawn()
This commit introduces following utility functions to handle
external process execution:
- spawn() - forks parent and executes specified command via execve(),
establishes pipe between child and parent to monitor child lifetime.
Ability to customize child environment is provided by the means of
callbacks - spawn_{setstdout{,err},chdir,umask} are provided to set
fds, chdir, and umask respectively.
- wait_for_pid() - waitpid() for child, returning its exit code
- spawn_wait() - combines both of above and adds ability to optionally
specify timeout after which child is killed. Returns childs exit
code (as wait_for_pid()), or -1 when timed out.
Change-Id: I55d1e4ae8f547be3883c43132a0e083b91f730e3