From c02e584c5915b8ab0793b51664d3e4a27c7bda6c Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 25 Jun 2016 14:57:39 -0500 Subject: Code style pass. --- toys/android/start.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) (limited to 'toys/android') diff --git a/toys/android/start.c b/toys/android/start.c index 8981b679..82703b1f 100644 --- a/toys/android/start.c +++ b/toys/android/start.c @@ -29,28 +29,23 @@ config STOP #include -static const char *services[] = { - "netd", "surfaceflinger", "zygote", "zygote_secondary", NULL, -}; - static void start_stop(int start) { - const char* property = start ? "ctl.start" : "ctl.stop"; - int i; + // null terminated in both directions + char *services[] = {0,"netd","surfaceflinger","zygote","zygote_secondary",0}, + **ss = toys.optargs; + int direction = 1; - if (getuid() != 0) error_exit("must be root"); + if (getuid()) error_exit("must be root"); - if (*toys.optargs) { - for (i = 0; toys.optargs[i]; i++) property_set(property, toys.optargs[i]); - } else if (start) { - for (i = 0; i < ARRAY_LEN(services); ++i) { - property_set(property, services[i]); - } - } else { - for (i = ARRAY_LEN(services) - 1; i >= 0; --i) { - property_set(property, services[i]); - } + if (!*ss) { + // Iterate through optargs, or services forward/backward. + ss = services+1; + if (!start) ss += ARRAY_LEN(services)-1, direction = -1; } + + for (; *ss; ss += direction) + property_set(start ? "ctl.start" : "ctl.stop", property, *ss); } void start_main(void) @@ -58,10 +53,6 @@ void start_main(void) start_stop(1); } -#define CLEANUP_start -#define FOR_stop -#include "generated/flags.h" - void stop_main(void) { start_stop(0); -- cgit v1.2.3