From df2541a4fdd946ad2423442f1646c805fa8dee3c Mon Sep 17 00:00:00 2001 From: Julio Montes Date: Tue, 8 Dec 2015 15:14:47 -0600 Subject: [PATCH] fix spawn commands --- configure.ac | 7 +++++++ src/lib.c | 13 +++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index ad1f2c7..e65aeef 100644 --- a/configure.ac +++ b/configure.ac @@ -74,6 +74,13 @@ fi AC_SUBST(RESIZE2FS) AC_DEFINE_UNQUOTED([RESIZEFS_PATH], ["$RESIZE2FS"], [Path to resize2fs binary]) +AC_PATH_PROG([SHELL], [sh], [no], [$PATH:/sbin:/usr/sbin]) +if test x"$SHELL" == x"no" ; then + AC_MSG_ERROR([Please install sh.]) +fi +AC_SUBST(SHELL) +AC_DEFINE_UNQUOTED([SHELL_PATH], ["$SHELL"], [Path to sh binary]) + AC_PATH_PROG([HOSTNAMECTL], [hostnamectl], [no], [$PATH:/sbin:/usr/sbin]) if test x"$HOSTNAMECTL" == x"no" ; then AC_MSG_ERROR([Please install hostnamectl.]) diff --git a/src/lib.c b/src/lib.c index 5f810bf..e6f459a 100644 --- a/src/lib.c +++ b/src/lib.c @@ -75,26 +75,31 @@ bool exec_task(const gchar* command_line) { GError* error = NULL; gint exit_status = 0; gboolean result; + GString* command; + command = g_string_new(""); + g_string_printf(command, SHELL_PATH " -c '%s'", (char*)command_line ); - LOG(MOD "Executing: %s\n", command_line); - result = g_spawn_command_line_sync(command_line, + LOG(MOD "Executing: %s\n", command->str); + result = g_spawn_command_line_sync(command->str, &standard_output, &standard_error, &exit_status, &error); + g_string_free(command, true); + if (!result || exit_status != 0) { LOG(MOD "Command failed\n"); if (error) { LOG(MOD "Error: %s\n", (char*)error->message); } if (standard_error) { - LOG(MOD "STD Error: %s", (char*)standard_error); + LOG(MOD "STD Error: %s\n", (char*)standard_error); } } if (standard_output) { - LOG(MOD "STD output: %s", (char*)standard_output); + LOG(MOD "STD output: %s\n", (char*)standard_output); g_free(standard_output); }