From ee15662140632672a6878787a1ff26f5ebdc1e68 Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Tue, 4 Aug 2009 20:37:51 -0400 Subject: adb: add "adb reboot" command. This will allow rebooting the device via adb on any build, including user builds. An optional argument can be provided (for example, "adb reboot bootloader" or adb reboot recovery") Signed-off-by: Mike Lockwood --- adb/services.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'adb/services.c') diff --git a/adb/services.c b/adb/services.c index 78d092b8..517da55f 100644 --- a/adb/services.c +++ b/adb/services.c @@ -33,6 +33,7 @@ # endif #else #include +#include #endif typedef struct stinfo stinfo; @@ -133,6 +134,20 @@ void restart_root_service(int fd, void *cookie) } } +void reboot_service(int fd, char *arg) +{ + char buf[100]; + int ret; + + sync(); + ret = __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, arg); + if (ret < 0) { + snprintf(buf, sizeof(buf), "reboot failed: %s\n", strerror(errno)); + writex(fd, buf, strlen(buf)); + } + adb_close(fd); +} + #endif #if 0 @@ -399,6 +414,11 @@ int service_to_fd(const char *name) ret = create_service_thread(file_sync_service, NULL); } else if(!strncmp(name, "remount:", 8)) { ret = create_service_thread(remount_service, NULL); + } else if(!strncmp(name, "reboot:", 7)) { + char* arg = name + 7; + if (*name == 0) + arg = NULL; + ret = create_service_thread(reboot_service, arg); } else if(!strncmp(name, "root:", 5)) { ret = create_service_thread(restart_root_service, NULL); #endif -- cgit v1.2.3