1 #include <error.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <unistd.h>
6
7 #include <cutils/properties.h>
8
9 static const char* services[] = {
10 "netd",
11 "surfaceflinger",
12 "zygote",
13 "zygote_secondary",
14 };
15
start_stop(bool start,int argc,char * argv[])16 static int start_stop(bool start, int argc, char* argv[]) {
17 if (getuid() != 0) error(1, 0, "must be root");
18 const char* property = start ? "ctl.start" : "ctl.stop";
19 if (argc > 2) {
20 error(1, 0, "usage: %s [SERVICE]\n", argv[0]);
21 } else if (argc == 2) {
22 property_set(property, argv[1]);
23 } else {
24 if (start) {
25 for (size_t i = 0; i < sizeof(services)/sizeof(services[0]); ++i) {
26 property_set(property, services[i]);
27 }
28 } else {
29 for (int i = sizeof(services)/sizeof(services[0]) - 1; i >= 0; --i) {
30 property_set(property, services[i]);
31 }
32 }
33 }
34 return 0;
35 }
36
start_main(int argc,char * argv[])37 extern "C" int start_main(int argc, char* argv[]) {
38 return start_stop(true, argc, argv);
39 }
40
stop_main(int argc,char * argv[])41 extern "C" int stop_main(int argc, char* argv[]) {
42 return start_stop(false, argc, argv);
43 }
44