reimplement exec_task function

This commit is contained in:
Julio Montes
2015-11-24 10:34:58 -06:00
parent bbd77c21a8
commit d259dacf5b
2 changed files with 38 additions and 8 deletions
+37 -7
View File
@@ -62,13 +62,43 @@ void LOG(const char *fmt, ...) {
va_end(args);
}
void exec_task(const gchar* task) {
/*
* execute a process externally in a secured and limited enviroment,
* handle return values gracefully
*/
LOG(MOD "Executing: %s\n", task);
system(task);
bool exec_task(const gchar* command_line) {
gchar* standard_output = NULL;
gchar* standard_error = NULL;
GError* error = NULL;
gint exit_status = 0;
gboolean result;
LOG(MOD "Executing: %s\n", command_line);
result = g_spawn_command_line_sync(command_line,
&standard_output,
&standard_error,
&exit_status,
&error);
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\n", (char*)standard_error);
}
}
if (standard_output) {
g_free(standard_output);
}
if (standard_error) {
g_free(standard_error);
}
if (error) {
g_error_free(error);
}
return result;
}
int make_dir(const char* pathname, mode_t mode) {
+1 -1
View File
@@ -48,7 +48,7 @@
#define cloud_config_dump(...)
#endif /* DEBUG */
void exec_task(const gchar* task);
gboolean exec_task(const gchar* command_line);
void LOG(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
int make_dir(const char* pathname, mode_t mode);
int chown_path(const char* pathname, const char* ownername, const char* groupname);