mirror of
https://github.com/clearlinux/micro-config-drive.git
synced 2026-09-06 21:51:42 +00:00
add function to exec async tasks
improve make_dir function to create parent directories (mkdir -p)
This commit is contained in:
@@ -114,10 +114,34 @@ bool exec_task(const gchar* command_line) {
|
||||
return result;
|
||||
}
|
||||
|
||||
bool exec_task_async(const gchar* command_line, GChildWatchFunc async_func_watcher, gpointer data) {
|
||||
GPid pid = 0;
|
||||
GError *error = NULL;
|
||||
gchar* command = g_strdup(command_line);
|
||||
gchar* argvp[] = {SHELL_PATH, "-c", command, NULL };
|
||||
|
||||
g_spawn_async(NULL, argvp, NULL,
|
||||
G_SPAWN_DO_NOT_REAP_CHILD,
|
||||
NULL, NULL, &pid, &error);
|
||||
|
||||
if (error) {
|
||||
LOG(MOD "Error running async command: %s\n", (char*)error->message);
|
||||
g_error_free(error);
|
||||
}
|
||||
|
||||
g_child_watch_add(pid, async_func_watcher, data);
|
||||
|
||||
LOG(MOD "Executing [%d]: %s -c \"%s\"\n", pid, SHELL_PATH, command);
|
||||
|
||||
g_free(command);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int make_dir(const char* pathname, mode_t mode) {
|
||||
struct stat stats;
|
||||
if (stat(pathname, &stats) != 0) {
|
||||
if (mkdir(pathname, mode) != 0) {
|
||||
if (g_mkdir_with_parents(pathname, (gint)mode) != 0) {
|
||||
LOG(MOD "Cannot create directory %s\n", pathname);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
#define __warn_unused_result__ __attribute__ ((warn_unused_result))
|
||||
|
||||
bool exec_task(const gchar* command_line);
|
||||
bool exec_task_async(const gchar* command_line, GChildWatchFunc async_func_watcher, gpointer data);
|
||||
void LOG(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
|
||||
int make_dir(const char* pathname, mode_t mode) __warn_unused_result__;
|
||||
int chown_path(const char* pathname, const char* ownername, const char* groupname) __warn_unused_result__;
|
||||
|
||||
Reference in New Issue
Block a user