16e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes#include <error.h> 26e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes#include <stdio.h> 36e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes#include <stdlib.h> 46e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes#include <string.h> 56e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes#include <unistd.h> 66e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes 76e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes#include <cutils/properties.h> 86e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes 96e83c3d76d02cd922620526c446cf5840e042706Elliott Hughesstatic const char* services[] = { 106e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes "netd", 116e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes "surfaceflinger", 126e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes "zygote", 136e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes "zygote_secondary", 146e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes}; 156e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes 166e83c3d76d02cd922620526c446cf5840e042706Elliott Hughesstatic int start_stop(bool start, int argc, char* argv[]) { 176e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes if (getuid() != 0) error(1, 0, "must be root"); 186e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes const char* property = start ? "ctl.start" : "ctl.stop"; 196e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes if (argc > 2) { 206e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes error(1, 0, "usage: %s [SERVICE]\n", argv[0]); 216e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes } else if (argc == 2) { 226e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes property_set(property, argv[1]); 236e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes } else { 246e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes if (start) { 256e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes for (size_t i = 0; i < sizeof(services)/sizeof(services[0]); ++i) { 266e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes property_set(property, services[i]); 276e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes } 286e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes } else { 296e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes for (int i = sizeof(services)/sizeof(services[0]) - 1; i >= 0; --i) { 306e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes property_set(property, services[i]); 316e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes } 326e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes } 336e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes } 346e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes return 0; 356e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes} 366e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes 376e83c3d76d02cd922620526c446cf5840e042706Elliott Hughesextern "C" int start_main(int argc, char* argv[]) { 386e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes return start_stop(true, argc, argv); 396e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes} 406e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes 416e83c3d76d02cd922620526c446cf5840e042706Elliott Hughesextern "C" int stop_main(int argc, char* argv[]) { 426e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes return start_stop(false, argc, argv); 436e83c3d76d02cd922620526c446cf5840e042706Elliott Hughes} 44