summaryrefslogtreecommitdiffstats
path: root/toolbox/start_stop.cpp
blob: dc48c0c0c506922679e4c997225f0f87a952a750 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <error.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include <cutils/properties.h>

static const char* services[] = {
  "netd",
  "surfaceflinger",
  "zygote",
  "zygote_secondary",
};

static int start_stop(bool start, int argc, char* argv[]) {
  if (getuid() != 0) error(1, 0, "must be root");
  const char* property = start ? "ctl.start" : "ctl.stop";
  if (argc > 2) {
    error(1, 0, "usage: %s [SERVICE]\n", argv[0]);
  } else if (argc == 2) {
    property_set(property, argv[1]);
  } else {
    if (start) {
      for (size_t i = 0; i < sizeof(services)/sizeof(services[0]); ++i) {
        property_set(property, services[i]);
      }
    } else {
      for (int i = sizeof(services)/sizeof(services[0]) - 1; i >= 0; --i) {
        property_set(property, services[i]);
      }
    }
  }
  return 0;
}

extern "C" int start_main(int argc, char* argv[]) {
  return start_stop(true, argc, argv);
}

extern "C" int stop_main(int argc, char* argv[]) {
  return start_stop(false, argc, argv);
}