diff options
Diffstat (limited to 'src/util/mtp_support.c')
-rwxr-xr-x | src/util/mtp_support.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/util/mtp_support.c b/src/util/mtp_support.c index 83108d6..8517146 100755 --- a/src/util/mtp_support.c +++ b/src/util/mtp_support.c @@ -17,6 +17,7 @@ #include <glib.h> #include <glib/gprintf.h> #include <unistd.h> +#include <sys/wait.h> #include "mtp_support.h" #include "ptp_datacodes.h" #include "mtp_util.h" @@ -643,3 +644,38 @@ SUCCESS: DBG_SECURE("Unique dir name[%s]\n", new_path); return TRUE; } + +mtp_int32 _util_system_cmd_wait(const mtp_char *cmd) +{ + + int pid = 0; + int status = 0; + + if (cmd == NULL) + return -1; + + pid = fork(); + + if (pid == -1) + return -1; + + if (pid == 0) { + char *argv[4]; + argv[0] = "sh"; + argv[1] = "-c"; + argv[2] = (char*)cmd; + argv[3] = 0; + execv("/bin/sh", argv); + exit(127); + } + + do { + if (waitpid(pid, &status, 0) == -1) { + if (errno != EINTR) + return -1; + } else { + return status; + } + } while (1); +} + |