1 #include <errno.h> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <cutils/android_reboot.h> 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; 12 int flags = 0; 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 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; 45 46 if(poweroff) 47 ret = android_reboot(ANDROID_RB_POWEROFF, flags, 0); 48 else if(argc > optind) 49 ret = android_reboot(ANDROID_RB_RESTART2, flags, argv[optind]); 50 else 51 ret = android_reboot(ANDROID_RB_RESTART, flags, 0); 52 if(ret < 0) { 53 perror("reboot"); 54 exit(EXIT_FAILURE); 55 } 56 fprintf(stderr, "reboot returned\n"); 57 return 0; 58 } 59