diff options
Diffstat (limited to 'reboot/reboot.c')
-rw-r--r-- | reboot/reboot.c | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/reboot/reboot.c b/reboot/reboot.c index 45d8a8ef5..0e5170d42 100644 --- a/reboot/reboot.c +++ b/reboot/reboot.c | |||
@@ -17,35 +17,34 @@ | |||
17 | #include <errno.h> | 17 | #include <errno.h> |
18 | #include <stdio.h> | 18 | #include <stdio.h> |
19 | #include <stdlib.h> | 19 | #include <stdlib.h> |
20 | #include <cutils/properties.h> | ||
20 | #include <cutils/android_reboot.h> | 21 | #include <cutils/android_reboot.h> |
21 | #include <unistd.h> | 22 | #include <unistd.h> |
22 | 23 | ||
23 | int main(int argc, char *argv[]) | 24 | int main(int argc, char *argv[]) |
24 | { | 25 | { |
25 | int ret; | 26 | int ret; |
26 | int nosync = 0; | 27 | size_t prop_len; |
27 | int poweroff = 0; | 28 | char property_val[PROPERTY_VALUE_MAX]; |
28 | int flags = 0; | 29 | const char *cmd = "reboot"; |
30 | char *optarg = ""; | ||
29 | 31 | ||
30 | opterr = 0; | 32 | opterr = 0; |
31 | do { | 33 | do { |
32 | int c; | 34 | int c; |
33 | 35 | ||
34 | c = getopt(argc, argv, "np"); | 36 | c = getopt(argc, argv, "p"); |
35 | 37 | ||
36 | if (c == EOF) { | 38 | if (c == EOF) { |
37 | break; | 39 | break; |
38 | } | 40 | } |
39 | 41 | ||
40 | switch (c) { | 42 | switch (c) { |
41 | case 'n': | ||
42 | nosync = 1; | ||
43 | break; | ||
44 | case 'p': | 43 | case 'p': |
45 | poweroff = 1; | 44 | cmd = "shutdown"; |
46 | break; | 45 | break; |
47 | case '?': | 46 | case '?': |
48 | fprintf(stderr, "usage: %s [-n] [-p] [rebootcommand]\n", argv[0]); | 47 | fprintf(stderr, "usage: %s [-p] [rebootcommand]\n", argv[0]); |
49 | exit(EXIT_FAILURE); | 48 | exit(EXIT_FAILURE); |
50 | } | 49 | } |
51 | } while (1); | 50 | } while (1); |
@@ -55,20 +54,20 @@ int main(int argc, char *argv[]) | |||
55 | exit(EXIT_FAILURE); | 54 | exit(EXIT_FAILURE); |
56 | } | 55 | } |
57 | 56 | ||
58 | if(nosync) | 57 | if (argc > optind) |
59 | /* also set NO_REMOUNT_RO as remount ro includes an implicit sync */ | 58 | optarg = argv[optind]; |
60 | flags = ANDROID_RB_FLAG_NO_SYNC | ANDROID_RB_FLAG_NO_REMOUNT_RO; | 59 | |
60 | prop_len = snprintf(property_val, sizeof(property_val), "%s,%s", cmd, optarg); | ||
61 | if (prop_len >= sizeof(property_val)) { | ||
62 | fprintf(stderr, "reboot command too long: %s\n", optarg); | ||
63 | exit(EXIT_FAILURE); | ||
64 | } | ||
61 | 65 | ||
62 | if(poweroff) | 66 | ret = property_set(ANDROID_RB_PROPERTY, property_val); |
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) { | 67 | if(ret < 0) { |
69 | perror("reboot"); | 68 | perror("reboot"); |
70 | exit(EXIT_FAILURE); | 69 | exit(EXIT_FAILURE); |
71 | } | 70 | } |
72 | fprintf(stderr, "reboot returned\n"); | 71 | fprintf(stderr, "Done\n"); |
73 | return 0; | 72 | return 0; |
74 | } | 73 | } |