1 From 89de07a9442072f88d49869d8ecd8d42bae050a0 Mon Sep 17 00:00:00 2001
2 From: Jouni Malinen <jouni@qca.qualcomm.com>
3 Date: Mon, 6 Oct 2014 16:27:44 +0300
4 Subject: [PATCH 1/3] Add os_exec() helper to run external programs
6 Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
8 src/utils/os.h | 9 +++++++++
9 src/utils/os_unix.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
10 src/utils/os_win32.c | 6 ++++++
11 3 files changed, 70 insertions(+)
15 @@ -584,6 +584,15 @@ static inline void os_remove_in_array(vo
17 size_t os_strlcpy(char *dest, const char *src, size_t siz);
20 + * os_exec - Execute an external program
21 + * @program: Path to the program
22 + * @arg: Command line argument string
23 + * @wait_completion: Whether to wait until the program execution completes
24 + * Returns: 0 on success, -1 on error
26 +int os_exec(const char *program, const char *arg, int wait_completion);
29 #ifdef OS_REJECT_C_LIB_FUNCTIONS
30 #define malloc OS_DO_NOT_USE_malloc
31 --- a/src/utils/os_unix.c
32 +++ b/src/utils/os_unix.c
37 +#include <sys/wait.h>
40 #include <sys/capability.h>
41 @@ -540,3 +541,57 @@ char * os_strdup(const char *s)
44 #endif /* WPA_TRACE */
47 +int os_exec(const char *program, const char *arg, int wait_completion)
59 + /* run the external command in the child process */
60 + const int MAX_ARG = 30;
61 + char *_program, *_arg, *pos;
62 + char *argv[MAX_ARG + 1];
65 + _program = os_strdup(program);
66 + _arg = os_strdup(arg);
72 + while (i < MAX_ARG && pos && *pos) {
78 + pos = os_strchr(pos, ' ');
84 + execv(program, argv);
92 + if (wait_completion) {
93 + /* wait for the child process to complete in the parent */
94 + waitpid(pid, &pid_status, 0);
99 --- a/src/utils/os_win32.c
100 +++ b/src/utils/os_win32.c
101 @@ -244,3 +244,9 @@ size_t os_strlcpy(char *dest, const char
107 +int os_exec(const char *program, const char *arg, int wait_completion)