system/corennnnn
修訂 | aaa03057118b3225fcd72f0b3039f76b1fd80398 (tree) |
---|---|
時間 | 2015-12-22 12:21:35 |
作者 | Magnus Malmborn <magnus.malmborn@sony...> |
Commiter | Chih-Wei Huang |
Adding an 'exec' implementation to init
This is useful for running programs synchronously
during startup.
Change-Id: I0212fad22613124dd13b4f20b86d0dcc6cb59b6e
@@ -27,6 +27,7 @@ | ||
27 | 27 | #include <linux/if.h> |
28 | 28 | #include <arpa/inet.h> |
29 | 29 | #include <stdlib.h> |
30 | +#include <sys/wait.h> | |
30 | 31 | #include <sys/mount.h> |
31 | 32 | #include <sys/resource.h> |
32 | 33 | #include <sys/wait.h> |
@@ -256,7 +257,36 @@ int do_enable(int nargs, char **args) | ||
256 | 257 | |
257 | 258 | int do_exec(int nargs, char **args) |
258 | 259 | { |
259 | - return -1; | |
260 | + pid_t pid; | |
261 | + int status, i, prop_fd, prop_size, ret; | |
262 | + char *par[nargs], env_property[64], *env[2]; | |
263 | + | |
264 | + for (i = 0; i < (nargs - 1); i++) { | |
265 | + par[i] = args[i + 1]; | |
266 | + } | |
267 | + par[i] = NULL; | |
268 | + | |
269 | + pid = fork(); | |
270 | + if (pid == 0) { | |
271 | + /* Enable system properties */ | |
272 | + get_property_workspace(&prop_fd, &prop_size); | |
273 | + memset(env_property, 0, sizeof(env_property)); | |
274 | + sprintf(env_property, "ANDROID_PROPERTY_WORKSPACE=%d,%d", | |
275 | + dup(prop_fd), prop_size); | |
276 | + env[0] = env_property; | |
277 | + env[1] = NULL; | |
278 | + | |
279 | + ret = execve(par[0], par, env); | |
280 | + ERROR("execve %s (ret = %d, errno = %d)\n", par[0], ret, errno); | |
281 | + _exit(127); | |
282 | + } else if (pid > 0) { | |
283 | + do { | |
284 | + ret = waitpid(pid, &status, 0); | |
285 | + } while ((ret < 0) && (errno == EINTR)); | |
286 | + } else { | |
287 | + ERROR("fork error\n"); | |
288 | + } | |
289 | + return 0; | |
260 | 290 | } |
261 | 291 | |
262 | 292 | int do_export(int nargs, char **args) |