1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <server_configurable_flags/disaster_recovery.h>
18 #include <server_configurable_flags/get_flags.h>
19 #include <string>
20
21 #include "android-base/logging.h"
22
23 // flags_heatlh_check binary takes 1 argument -- reset_mode
24 // If reset_mode == BOOT_FAILURE, the binary will examine how many
25 // consecutive reboots have failed. If there are more than 4 consecutive
26 // reboot failures, flag reset will be performed.
27 // If reset_mode == UPDATABLE_CRASHING, the binary will directly perform
28 // flag reset actions.
main(int argc,char * argv[])29 int main(int argc, char* argv[]) {
30 if (argc != 2) {
31 LOG(ERROR) << "argc: " << std::to_string(argc) << ", it should only be 2.";
32 return 1;
33 }
34
35 std::string reset_mode_str(argv[1]);
36 server_configurable_flags::ResetMode reset_mode;
37 if (reset_mode_str == "BOOT_FAILURE") {
38 reset_mode = server_configurable_flags::BOOT_FAILURE;
39 } else if (reset_mode_str == "UPDATABLE_CRASHING") {
40 reset_mode = server_configurable_flags::UPDATABLE_CRASHING;
41 } else {
42 LOG(ERROR) << "invalid reset mode: " << reset_mode_str << ".";
43 return 1;
44 }
45
46 server_configurable_flags::ServerConfigurableFlagsReset(reset_mode);
47
48 return 0;
49 }