summaryrefslogtreecommitdiffstats
path: root/reboot
diff options
context:
space:
mode:
authorBenoit Goby2013-03-22 18:23:48 -0500
committerBenoit Goby2013-03-26 14:24:10 -0500
commitc6d7e200eddd620d8ac55259ab3aa5f8bfa2aadb (patch)
tree3e2e332d9ed70377e13c91e2990c4a914d4f5f8b /reboot
parent82075a4044efe57ad9bad3d18982e311b4ef53ae (diff)
downloadplatform-system-core-c6d7e200eddd620d8ac55259ab3aa5f8bfa2aadb.tar.gz
platform-system-core-c6d7e200eddd620d8ac55259ab3aa5f8bfa2aadb.tar.xz
platform-system-core-c6d7e200eddd620d8ac55259ab3aa5f8bfa2aadb.zip
toolbox: Make reboot a separate command from toolbox
Set the CAP_SYS_BOOT filesystem capability on the new reboot command and keep CAP_SYS_BOOT in adb bounding set so that the shell user can run it. Change-Id: I1dd6143445ee2a952254f0452ab6e544318431dd
Diffstat (limited to 'reboot')
-rw-r--r--reboot/Android.mk12
-rw-r--r--reboot/reboot.c74
2 files changed, 86 insertions, 0 deletions
diff --git a/reboot/Android.mk b/reboot/Android.mk
new file mode 100644
index 000000000..4db0c1e4d
--- /dev/null
+++ b/reboot/Android.mk
@@ -0,0 +1,12 @@
1# Copyright 2013 The Android Open Source Project
2
3LOCAL_PATH:= $(call my-dir)
4include $(CLEAR_VARS)
5
6LOCAL_SRC_FILES:= reboot.c
7
8LOCAL_SHARED_LIBRARIES:= libcutils
9
10LOCAL_MODULE:= reboot
11
12include $(BUILD_EXECUTABLE)
diff --git a/reboot/reboot.c b/reboot/reboot.c
new file mode 100644
index 000000000..45d8a8ef5
--- /dev/null
+++ b/reboot/reboot.c
@@ -0,0 +1,74 @@
1/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <errno.h>
18#include <stdio.h>
19#include <stdlib.h>
20#include <cutils/android_reboot.h>
21#include <unistd.h>
22
23int main(int argc, char *argv[])
24{
25 int ret;
26 int nosync = 0;
27 int poweroff = 0;
28 int flags = 0;
29
30 opterr = 0;
31 do {
32 int c;
33
34 c = getopt(argc, argv, "np");
35
36 if (c == EOF) {
37 break;
38 }
39
40 switch (c) {
41 case 'n':
42 nosync = 1;
43 break;
44 case 'p':
45 poweroff = 1;
46 break;
47 case '?':
48 fprintf(stderr, "usage: %s [-n] [-p] [rebootcommand]\n", argv[0]);
49 exit(EXIT_FAILURE);
50 }
51 } while (1);
52
53 if(argc > optind + 1) {
54 fprintf(stderr, "%s: too many arguments\n", argv[0]);
55 exit(EXIT_FAILURE);
56 }
57
58 if(nosync)
59 /* also set NO_REMOUNT_RO as remount ro includes an implicit sync */
60 flags = ANDROID_RB_FLAG_NO_SYNC | ANDROID_RB_FLAG_NO_REMOUNT_RO;
61
62 if(poweroff)
63 ret = android_reboot(ANDROID_RB_POWEROFF, flags, 0);
64 else if(argc > optind)
65 ret = android_reboot(ANDROID_RB_RESTART2, flags, argv[optind]);
66 else
67 ret = android_reboot(ANDROID_RB_RESTART, flags, 0);
68 if(ret < 0) {
69 perror("reboot");
70 exit(EXIT_FAILURE);
71 }
72 fprintf(stderr, "reboot returned\n");
73 return 0;
74}