summaryrefslogtreecommitdiffstats
path: root/lib/system
diff options
context:
space:
mode:
authorGeoff Levand <geoffrey.levand@am.sony.com>2009-07-09 10:40:43 -0700
committerGeoff Levand <geoffrey.levand@am.sony.com>2009-07-09 10:40:43 -0700
commit322a024f44bd6c2d665010588d74a681c9703431 (patch)
tree69f5a5bc35c067fd6a583106c1bbf628695832c6 /lib/system
parent965e71e54686b0987409276933c085f794bf21f6 (diff)
downloadtalos-petitboot-322a024f44bd6c2d665010588d74a681c9703431.tar.gz
talos-petitboot-322a024f44bd6c2d665010588d74a681c9703431.zip
Log child output
Redirect the output of child processes to pb_log. Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com>
Diffstat (limited to 'lib/system')
-rw-r--r--lib/system/system.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/system/system.c b/lib/system/system.c
index 380dded..65bd6bf 100644
--- a/lib/system/system.c
+++ b/lib/system/system.c
@@ -3,6 +3,7 @@
#include "config.h"
#endif
+#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
@@ -104,13 +105,13 @@ int pb_rmdir_recursive(const char *base, const char *dir)
int pb_run_cmd(const char *const *cmd_argv)
{
- int status;
- pid_t pid;
#if defined(DEBUG)
enum {do_debug = 1};
#else
enum {do_debug = 0};
#endif
+ int status;
+ pid_t pid;
if (do_debug) {
const char *const *p = cmd_argv;
@@ -125,12 +126,23 @@ int pb_run_cmd(const char *const *cmd_argv)
pb_log("%s: %s\n", __func__, cmd_argv[0]);
pid = fork();
+
if (pid == -1) {
pb_log("%s: fork failed: %s\n", __func__, strerror(errno));
return -1;
}
if (pid == 0) {
+ int log = fileno(pb_log_get_stream());
+
+ /* Redirect child output to log. */
+
+ status = dup2(log, STDOUT_FILENO);
+ assert(status != -1);
+
+ status = dup2(log, STDERR_FILENO);
+ assert(status != -1);
+
execvp(cmd_argv[0], (char *const *)cmd_argv);
pb_log("%s: exec failed: %s\n", __func__, strerror(errno));
exit(EXIT_FAILURE);
OpenPOWER on IntegriCloud