The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 1 | #include <errno.h> |
| 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
Ken Sumrall | e3aeeb4 | 2011-03-07 23:29:42 -0800 | [diff] [blame] | 4 | #include <cutils/android_reboot.h> |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 5 | #include <unistd.h> |
| 6 | |
| 7 | int reboot_main(int argc, char *argv[]) |
| 8 | { |
| 9 | int ret; |
| 10 | int nosync = 0; |
| 11 | int poweroff = 0; |
Ken Sumrall | e3aeeb4 | 2011-03-07 23:29:42 -0800 | [diff] [blame] | 12 | int flags = 0; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 13 | |
| 14 | opterr = 0; |
| 15 | do { |
| 16 | int c; |
| 17 | |
| 18 | c = getopt(argc, argv, "np"); |
| 19 | |
| 20 | if (c == EOF) { |
| 21 | break; |
| 22 | } |
| 23 | |
| 24 | switch (c) { |
| 25 | case 'n': |
| 26 | nosync = 1; |
| 27 | break; |
| 28 | case 'p': |
| 29 | poweroff = 1; |
| 30 | break; |
| 31 | case '?': |
| 32 | fprintf(stderr, "usage: %s [-n] [-p] [rebootcommand]\n", argv[0]); |
| 33 | exit(EXIT_FAILURE); |
| 34 | } |
| 35 | } while (1); |
| 36 | |
| 37 | if(argc > optind + 1) { |
| 38 | fprintf(stderr, "%s: too many arguments\n", argv[0]); |
| 39 | exit(EXIT_FAILURE); |
| 40 | } |
| 41 | |
Ken Sumrall | e3aeeb4 | 2011-03-07 23:29:42 -0800 | [diff] [blame] | 42 | if(nosync) |
| 43 | /* also set NO_REMOUNT_RO as remount ro includes an implicit sync */ |
| 44 | flags = ANDROID_RB_FLAG_NO_SYNC | ANDROID_RB_FLAG_NO_REMOUNT_RO; |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 45 | |
| 46 | if(poweroff) |
Ken Sumrall | e3aeeb4 | 2011-03-07 23:29:42 -0800 | [diff] [blame] | 47 | ret = android_reboot(ANDROID_RB_POWEROFF, flags, 0); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 48 | else if(argc > optind) |
Ken Sumrall | e3aeeb4 | 2011-03-07 23:29:42 -0800 | [diff] [blame] | 49 | ret = android_reboot(ANDROID_RB_RESTART2, flags, argv[optind]); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 50 | else |
Ken Sumrall | e3aeeb4 | 2011-03-07 23:29:42 -0800 | [diff] [blame] | 51 | ret = android_reboot(ANDROID_RB_RESTART, flags, 0); |
The Android Open Source Project | dd7bc33 | 2009-03-03 19:32:55 -0800 | [diff] [blame] | 52 | if(ret < 0) { |
| 53 | perror("reboot"); |
| 54 | exit(EXIT_FAILURE); |
| 55 | } |
| 56 | fprintf(stderr, "reboot returned\n"); |
| 57 | return 0; |
| 58 | } |