1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
27 #include <libconfig.h>
33 #include <sys/types.h>
34 #include <sys/reboot.h>
36 #include <asm-generic/setup.h> // for COMMAND_LINE_SIZE
38 #include "system-recovery.h"
40 void sys_power_reboot(void)
45 #define KERNEL_CMDLINE_KEY "tizen.recovery"
46 #define ACTION_BUFFER_SIZE 256
48 #define STR(x) _STR(x)
50 // looks for tizen.recovery= key in kernel command line
51 char *get_action_from_cmdline(void)
54 char cmdline[COMMAND_LINE_SIZE];
57 fp = fopen("/proc/cmdline", "r");
61 char *p = fgets(cmdline, sizeof cmdline, fp);
66 const char *prefix = KERNEL_CMDLINE_KEY "=";
67 p = strstr(cmdline, prefix);
72 for (len = 0; *(p + len) != 0 && !isspace(*(p + len)); ++len)
75 return strndup(p, len);
78 char *get_action_from_file(void)
81 char buf[ACTION_BUFFER_SIZE];
84 fp = fopen(SYSTEM_RECOVERY_ACTION_FILE, "r");
86 LOGD("Could not open recovery action file\n");
90 ret = fscanf(fp, "%" STR(ACTION_BUFFER_SIZE) "s", buf);
92 if (unlink(SYSTEM_RECOVERY_ACTION_FILE) < 0)
93 LOGD("Could not unlink recovery action file: %m\n");
98 return strndup(buf, ACTION_BUFFER_SIZE);
106 LOGD("[main] recovery started.\n");
109 ret = config_read_file(&cfg, SYSTEM_RECOVERY_CONFIG_FILE);
110 if (ret == CONFIG_FALSE) {
111 LOGD("Can't read config file");
116 ret = recovery_gui(&cfg);
118 ret = recovery_headless(&cfg);
121 LOGD("[main] recovery finished.\n");
122 config_destroy(&cfg);