summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Lockwood2009-08-04 19:37:51 -0500
committerMike Lockwood2009-08-10 19:15:25 -0500
commit704aa833382a73f8e02d49b7e9c2aef9a49c65bd (patch)
tree8f0fe8e6f7268c2d2ac85e468e5119aee2ef7be0
parentc5ceeeedeeb1cc3ba3d8b54b04f983ae666755a2 (diff)
downloadplatform-system-core-704aa833382a73f8e02d49b7e9c2aef9a49c65bd.tar.gz
platform-system-core-704aa833382a73f8e02d49b7e9c2aef9a49c65bd.tar.xz
platform-system-core-704aa833382a73f8e02d49b7e9c2aef9a49c65bd.zip
DO NOT MERGE cherry-pick "adb reboot" from master:
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 <lockwood@android.com>
-rw-r--r--adb/adb.c14
-rw-r--r--adb/adb.h2
-rw-r--r--adb/commandline.c17
-rw-r--r--adb/services.c20
4 files changed, 52 insertions, 1 deletions
diff --git a/adb/adb.c b/adb/adb.c
index 956df544e..e8d2c8fa8 100644
--- a/adb/adb.c
+++ b/adb/adb.c
@@ -30,6 +30,8 @@
30 30
31#if !ADB_HOST 31#if !ADB_HOST
32#include <private/android_filesystem_config.h> 32#include <private/android_filesystem_config.h>
33#include <linux/capability.h>
34#include <linux/prctl.h>
33#else 35#else
34#include "usb_vendors.h" 36#include "usb_vendors.h"
35#endif 37#endif
@@ -879,6 +881,11 @@ int adb_main(int is_daemon)
879 /* don't listen on port 5037 if we are running in secure mode */ 881 /* don't listen on port 5037 if we are running in secure mode */
880 /* don't run as root if we are running in secure mode */ 882 /* don't run as root if we are running in secure mode */
881 if (secure) { 883 if (secure) {
884 struct __user_cap_header_struct header;
885 struct __user_cap_data_struct cap;
886
887 prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
888
882 /* add extra groups: 889 /* add extra groups:
883 ** AID_ADB to access the USB driver 890 ** AID_ADB to access the USB driver
884 ** AID_LOG to read system logs (adb logcat) 891 ** AID_LOG to read system logs (adb logcat)
@@ -896,6 +903,13 @@ int adb_main(int is_daemon)
896 setgid(AID_SHELL); 903 setgid(AID_SHELL);
897 setuid(AID_SHELL); 904 setuid(AID_SHELL);
898 905
906 /* set CAP_SYS_BOOT capability, so "adb reboot" will succeed */
907 header.version = _LINUX_CAPABILITY_VERSION;
908 header.pid = 0;
909 cap.effective = cap.permitted = (1 << CAP_SYS_BOOT);
910 cap.inheritable = 0;
911 capset(&header, &cap);
912
899 D("Local port 5037 disabled\n"); 913 D("Local port 5037 disabled\n");
900 } else { 914 } else {
901 if(install_listener("tcp:5037", "*smartsocket*", NULL)) { 915 if(install_listener("tcp:5037", "*smartsocket*", NULL)) {
diff --git a/adb/adb.h b/adb/adb.h
index 95610a738..8d57bf26c 100644
--- a/adb/adb.h
+++ b/adb/adb.h
@@ -33,7 +33,7 @@
33#define ADB_VERSION_MAJOR 1 // Used for help/version information 33#define ADB_VERSION_MAJOR 1 // Used for help/version information
34#define ADB_VERSION_MINOR 0 // Used for help/version information 34#define ADB_VERSION_MINOR 0 // Used for help/version information
35 35
36#define ADB_SERVER_VERSION 21 // Increment this when we want to force users to start a new adb server 36#define ADB_SERVER_VERSION 22 // Increment this when we want to force users to start a new adb server
37 37
38typedef struct amessage amessage; 38typedef struct amessage amessage;
39typedef struct apacket apacket; 39typedef struct apacket apacket;
diff --git a/adb/commandline.c b/adb/commandline.c
index 548d36248..5414e5eb5 100644
--- a/adb/commandline.c
+++ b/adb/commandline.c
@@ -147,6 +147,7 @@ void help()
147 " adb get-serialno - prints: <serial-number>\n" 147 " adb get-serialno - prints: <serial-number>\n"
148 " adb status-window - continuously print device status for a specified device\n" 148 " adb status-window - continuously print device status for a specified device\n"
149 " adb remount - remounts the /system partition on the device read-write\n" 149 " adb remount - remounts the /system partition on the device read-write\n"
150 " adb reboot [bootloader|recovery] - reboots the device, optionally into the bootloader or recovery program\n"
150 " adb root - restarts adb with root permissions\n" 151 " adb root - restarts adb with root permissions\n"
151 "\n" 152 "\n"
152 "networking:\n" 153 "networking:\n"
@@ -915,6 +916,22 @@ top:
915 return 1; 916 return 1;
916 } 917 }
917 918
919 if(!strcmp(argv[0], "reboot")) {
920 int fd;
921 if (argc > 1)
922 snprintf(buf, sizeof(buf), "reboot:%s", argv[1]);
923 else
924 snprintf(buf, sizeof(buf), "reboot:");
925 fd = adb_connect(buf);
926 if(fd >= 0) {
927 read_and_dump(fd);
928 adb_close(fd);
929 return 0;
930 }
931 fprintf(stderr,"error: %s\n", adb_error());
932 return 1;
933 }
934
918 if(!strcmp(argv[0], "root")) { 935 if(!strcmp(argv[0], "root")) {
919 int fd = adb_connect("root:"); 936 int fd = adb_connect("root:");
920 if(fd >= 0) { 937 if(fd >= 0) {
diff --git a/adb/services.c b/adb/services.c
index 78d092b83..517da55f5 100644
--- a/adb/services.c
+++ b/adb/services.c
@@ -33,6 +33,7 @@
33# endif 33# endif
34#else 34#else
35#include <sys/poll.h> 35#include <sys/poll.h>
36#include <sys/reboot.h>
36#endif 37#endif
37 38
38typedef struct stinfo stinfo; 39typedef struct stinfo stinfo;
@@ -133,6 +134,20 @@ void restart_root_service(int fd, void *cookie)
133 } 134 }
134} 135}
135 136
137void reboot_service(int fd, char *arg)
138{
139 char buf[100];
140 int ret;
141
142 sync();
143 ret = __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART2, arg);
144 if (ret < 0) {
145 snprintf(buf, sizeof(buf), "reboot failed: %s\n", strerror(errno));
146 writex(fd, buf, strlen(buf));
147 }
148 adb_close(fd);
149}
150
136#endif 151#endif
137 152
138#if 0 153#if 0
@@ -399,6 +414,11 @@ int service_to_fd(const char *name)
399 ret = create_service_thread(file_sync_service, NULL); 414 ret = create_service_thread(file_sync_service, NULL);
400 } else if(!strncmp(name, "remount:", 8)) { 415 } else if(!strncmp(name, "remount:", 8)) {
401 ret = create_service_thread(remount_service, NULL); 416 ret = create_service_thread(remount_service, NULL);
417 } else if(!strncmp(name, "reboot:", 7)) {
418 char* arg = name + 7;
419 if (*name == 0)
420 arg = NULL;
421 ret = create_service_thread(reboot_service, arg);
402 } else if(!strncmp(name, "root:", 5)) { 422 } else if(!strncmp(name, "root:", 5)) {
403 ret = create_service_thread(restart_root_service, NULL); 423 ret = create_service_thread(restart_root_service, NULL);
404#endif 424#endif