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;
maxwen27116ba2015-08-14 21:41:28 +020010 int nosync = 0;
11 int poweroff = 0;
12 int flags = 0;
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +020013
14 opterr = 0;
15 do {
16 int c;
17
maxwen27116ba2015-08-14 21:41:28 +020018 c = getopt(argc, argv, "np");
19
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +020020 if (c == EOF) {
21 break;
22 }
maxwen27116ba2015-08-14 21:41:28 +020023
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +020024 switch (c) {
maxwen27116ba2015-08-14 21:41:28 +020025 case 'n':
26 nosync = 1;
27 break;
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +020028 case 'p':
maxwen27116ba2015-08-14 21:41:28 +020029 poweroff = 1;
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +020030 break;
31 case '?':
maxwen27116ba2015-08-14 21:41:28 +020032 fprintf(stderr, "usage: %s [-n] [-p] [rebootcommand]\n", argv[0]);
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +020033 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
maxwen27116ba2015-08-14 21:41:28 +020042#if 0 // This isn't supported anymore. Sync, always
43 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;
46#endif
Jiangyi4983f4b2013-11-03 05:37:40 -050047
maxwen27116ba2015-08-14 21:41:28 +020048 if(poweroff)
49 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 }
maxwen27116ba2015-08-14 21:41:28 +020058 fprintf(stderr, "reboot returned\n");
Tanguy Pruvot8aeb3712011-06-30 08:59:26 +020059 return 0;
60}