ath9k: add a few calibration related fixes
[openwrt.git] / package / network / services / hostapd / patches / 002-Add-os_exec-helper-to-run-external-programs.patch
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
5
6 Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
7 ---
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(+)
12
13 --- a/src/utils/os.h
14 +++ b/src/utils/os.h
15 @@ -584,6 +584,15 @@ static inline void os_remove_in_array(vo
16   */
17  size_t os_strlcpy(char *dest, const char *src, size_t siz);
18  
19 +/**
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
25 + */
26 +int os_exec(const char *program, const char *arg, int wait_completion);
27 +
28  
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
33 @@ -9,6 +9,7 @@
34  #include "includes.h"
35  
36  #include <time.h>
37 +#include <sys/wait.h>
38  
39  #ifdef ANDROID
40  #include <sys/capability.h>
41 @@ -540,3 +541,57 @@ char * os_strdup(const char *s)
42  }
43  
44  #endif /* WPA_TRACE */
45 +
46 +
47 +int os_exec(const char *program, const char *arg, int wait_completion)
48 +{
49 +       pid_t pid;
50 +       int pid_status;
51 +
52 +       pid = fork();
53 +       if (pid < 0) {
54 +               perror("fork");
55 +               return -1;
56 +       }
57 +
58 +       if (pid == 0) {
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];
63 +               int i;
64 +
65 +               _program = os_strdup(program);
66 +               _arg = os_strdup(arg);
67 +
68 +               argv[0] = _program;
69 +
70 +               i = 1;
71 +               pos = _arg;
72 +               while (i < MAX_ARG && pos && *pos) {
73 +                       while (*pos == ' ')
74 +                               pos++;
75 +                       if (*pos == '\0')
76 +                               break;
77 +                       argv[i++] = pos;
78 +                       pos = os_strchr(pos, ' ');
79 +                       if (pos)
80 +                               *pos++ = '\0';
81 +               }
82 +               argv[i] = NULL;
83 +
84 +               execv(program, argv);
85 +               perror("execv");
86 +               os_free(_program);
87 +               os_free(_arg);
88 +               exit(0);
89 +               return -1;
90 +       }
91 +
92 +       if (wait_completion) {
93 +               /* wait for the child process to complete in the parent */
94 +               waitpid(pid, &pid_status, 0);
95 +       }
96 +
97 +       return 0;
98 +}
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
102  
103         return s - src - 1;
104  }
105 +
106 +
107 +int os_exec(const char *program, const char *arg, int wait_completion)
108 +{
109 +       return -1;
110 +}