• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <sys/system_properties.h>
31 
start_stop(int start)32 static void start_stop(int start)
33 {
34   char *property = start ? "ctl.start" : "ctl.stop";
35   // null terminated in both directions
36   char *services[] = {0,"netd","surfaceflinger","zygote","zygote_secondary",0},
37        **ss = toys.optargs;
38   int direction = 1;
39 
40   if (getuid()) error_exit("must be root");
41 
42   if (!*ss) {
43     // If we don't have optargs, iterate through services forward/backward.
44     ss = services+1;
45     if (!start) ss = services+ARRAY_LEN(services)-2, direction = -1;
46   }
47 
48   for (; *ss; ss += direction)
49     if (__system_property_set(property, *ss))
50       error_exit("failed to set property '%s' to '%s'", property, *ss);
51 }
52 
start_main(void)53 void start_main(void)
54 {
55   start_stop(1);
56 }
57 
stop_main(void)58 void stop_main(void)
59 {
60   start_stop(0);
61 }
62