Skip to content

Commit

Permalink
fix spawn commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio Montes committed Dec 8, 2015
1 parent 4661ac8 commit df2541a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
7 changes: 7 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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.])
Expand Down
13 changes: 9 additions & 4 deletions src/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit df2541a

Please sign in to comment.