1 /* start.c - Start/stop system services. 2 * 3 * Copyright 2016 The Android Open Source Project 4 5 USE_START(NEWTOY(start, "", TOYFLAG_USR|TOYFLAG_SBIN)) 6 USE_STOP(NEWTOY(stop, "", TOYFLAG_USR|TOYFLAG_SBIN)) 7 8 config START 9 bool "start" 10 depends on TOYBOX_ON_ANDROID 11 default y 12 help 13 usage: start [SERVICE...] 14 15 Starts the given system service, or netd/surfaceflinger/zygotes. 16 17 config STOP 18 bool "stop" 19 depends on TOYBOX_ON_ANDROID 20 default y 21 help 22 usage: stop [SERVICE...] 23 24 Stop the given system service, or netd/surfaceflinger/zygotes. 25 */ 26 27 #define FOR_start 28 #include "toys.h" 29 30 static void start_stop(int start) 31 { 32 char *property = start ? "ctl.start" : "ctl.stop"; 33 // null terminated in both directions 34 char *services[] = {0,"netd","surfaceflinger","zygote","zygote_secondary",0}, 35 **ss = toys.optargs; 36 int direction = 1; 37 38 if (getuid()) error_exit("must be root"); 39 40 if (!*ss) { 41 // If we don't have optargs, iterate through services forward/backward. 42 ss = services+1; 43 if (!start) ss = services+ARRAY_LEN(services)-2, direction = -1; 44 } 45 46 for (; *ss; ss += direction) 47 if (__system_property_set(property, *ss)) 48 error_exit("failed to set property '%s' to '%s'", property, *ss); 49 } 50 51 void start_main(void) 52 { 53 start_stop(1); 54 } 55 56 void stop_main(void) 57 { 58 start_stop(0); 59 } 60