… | |
… | |
34 | #include <unistd.h> |
34 | #include <unistd.h> |
35 | #include <time.h> |
35 | #include <time.h> |
36 | |
36 | |
37 | #include "netcompat.h" |
37 | #include "netcompat.h" |
38 | |
38 | |
|
|
39 | #include "gettext.h" |
39 | #include "pidfile.h" |
40 | #include "pidfile.h" |
40 | #include "dropin.h" |
41 | #include "dropin.h" |
41 | |
42 | |
42 | #include "global.h" |
43 | #include "global.h" |
43 | #include "conf.h" |
44 | #include "conf.h" |
… | |
… | |
126 | slog (L_INFO, _("gvpe daemon %s (%s %s) starting"), VERSION, __DATE__, __TIME__); |
127 | slog (L_INFO, _("gvpe daemon %s (%s %s) starting"), VERSION, __DATE__, __TIME__); |
127 | |
128 | |
128 | return 0; |
129 | return 0; |
129 | } |
130 | } |
130 | |
131 | |
131 | void run_script (const run_script_cb &cb, bool wait) |
132 | bool run_script (const run_script_cb &cb, bool wait) |
132 | { |
133 | { |
133 | int pid; |
134 | int pid; |
134 | |
135 | |
135 | if ((pid = fork ()) == 0) |
136 | if ((pid = fork ()) == 0) |
136 | { |
137 | { |
137 | char *filename; |
138 | execl ("/bin/sh", "/bin/sh", "-c", cb (), (char *) 0); |
138 | asprintf (&filename, "%s/%s", confbase, cb()); |
139 | exit (EXIT_FAILURE); |
139 | execl (filename, filename, (char *) 0); |
|
|
140 | exit (126); |
|
|
141 | } |
140 | } |
142 | else if (pid > 0) |
141 | else if (pid > 0) |
143 | { |
142 | { |
144 | if (wait) |
143 | if (wait) |
145 | { |
144 | { |
|
|
145 | int status; |
|
|
146 | |
146 | waitpid (pid, 0, 0); |
147 | if (waitpid (pid, &status, 0) < 0) |
147 | /* TODO: check status */ |
148 | { |
|
|
149 | slog (L_WARN, _("waiting for an external command failed: %s."), |
|
|
150 | strerror (errno)); |
|
|
151 | return false; |
|
|
152 | } |
|
|
153 | else if (!WIFEXITED (status) || WEXITSTATUS (status) != EXIT_SUCCESS) |
|
|
154 | { |
|
|
155 | slog (L_WARN, _("external command returned with exit status %d (%04x)."), |
|
|
156 | WEXITSTATUS (status), status); |
|
|
157 | return false; |
|
|
158 | } |
148 | } |
159 | } |
149 | } |
160 | } |
|
|
161 | |
|
|
162 | return true; |
150 | } |
163 | } |
151 | |
164 | |
152 | #if ENABLE_HTTP_PROXY |
165 | #if ENABLE_HTTP_PROXY |
153 | // works like strdup |
166 | // works like strdup |
154 | u8 * |
167 | u8 * |