blob: c412fd622a84eb71a79ac78c714d4b51d2d730bd [file] [log] [blame]
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +02001#include <errno.h>
2#include <stdio.h>
3#include <stdlib.h>
Tanguy Pruvot8a6c2c22012-04-28 00:24:09 +02004#include <cutils/android_reboot.h>
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +02005#include <unistd.h>
6
7int reboot_main(int argc, char *argv[])
8{
9 int ret;
10 int nosync = 0;
11 int poweroff = 0;
Tanguy Pruvot8a6c2c22012-04-28 00:24:09 +020012 int flags = 0;
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +020013
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
Ricardo Cerqueira25e89dc2013-11-05 03:43:38 +000042#if 0 // This isn't supported anymore. Sync, always
Tanguy Pruvot8a6c2c22012-04-28 00:24:09 +020043 if(nosync)
44 /* also set NO_REMOUNT_RO as remount ro includes an implicit sync */
45 flags = ANDROID_RB_FLAG_NO_SYNC | ANDROID_RB_FLAG_NO_REMOUNT_RO;
Ricardo Cerqueira25e89dc2013-11-05 03:43:38 +000046#endif
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +020047
48 if(poweroff)
Tanguy Pruvot8a6c2c22012-04-28 00:24:09 +020049 ret = android_reboot(ANDROID_RB_POWEROFF, flags, 0);
50 else if(argc > optind)
51 ret = android_reboot(ANDROID_RB_RESTART2, flags, argv[optind]);
52 else
53 ret = android_reboot(ANDROID_RB_RESTART, flags, 0);
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +020054 if(ret < 0) {
55 perror("reboot");
56 exit(EXIT_FAILURE);
57 }
58 fprintf(stderr, "reboot returned\n");
59 return 0;
60}