Zimuzo | 9cc0be4 | 2019-01-09 11:37:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | #define LOG_TAG "apexd" |
| 18 | |
| 19 | #include "apexd_prop.h" |
| 20 | |
| 21 | #include <android-base/logging.h> |
| 22 | #include <android-base/properties.h> |
| 23 | |
Nikita Ioffe | 31dc34d | 2019-02-23 15:59:04 +0000 | [diff] [blame] | 24 | #include "apexd_utils.h" |
| 25 | |
Nikita Ioffe | 9bb12ed | 2020-03-21 13:08:04 +0000 | [diff] [blame] | 26 | using android::base::GetBoolProperty; |
Nikita Ioffe | bde5fb8 | 2020-02-07 18:24:39 +0000 | [diff] [blame] | 27 | using android::base::GetProperty; |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 28 | using android::base::Result; |
Nikita Ioffe | bde5fb8 | 2020-02-07 18:24:39 +0000 | [diff] [blame] | 29 | using android::base::WaitForProperty; |
Mohammad Samiul Islam | bd6ab0f | 2019-06-20 15:55:27 +0100 | [diff] [blame] | 30 | |
Zimuzo | 9cc0be4 | 2019-01-09 11:37:34 +0000 | [diff] [blame] | 31 | namespace android { |
| 32 | namespace apex { |
Nikita Ioffe | bde5fb8 | 2020-02-07 18:24:39 +0000 | [diff] [blame] | 33 | void waitForBootStatus(Result<void> (&revert_fn)(const std::string&), |
Gavin Corkery | 97634da | 2020-01-13 12:35:38 +0000 | [diff] [blame] | 34 | void (&complete_fn)()) { |
Nikita Ioffe | 9bb12ed | 2020-03-21 13:08:04 +0000 | [diff] [blame] | 35 | while (!GetBoolProperty("sys.boot_completed", false)) { |
Zimuzo | 9cc0be4 | 2019-01-09 11:37:34 +0000 | [diff] [blame] | 36 | // Check for change in either crashing property or sys.boot_completed |
| 37 | // Wait for updatable_crashing property change for most of the time |
| 38 | // (arbitrary 30s), briefly check if boot has completed successfully, |
| 39 | // if not continue waiting for updatable_crashing. |
| 40 | // We use this strategy so that we can quickly detect if an updatable |
| 41 | // process is crashing. |
Nikita Ioffe | bde5fb8 | 2020-02-07 18:24:39 +0000 | [diff] [blame] | 42 | if (WaitForProperty("sys.init.updatable_crashing", "1", |
| 43 | std::chrono::seconds(30))) { |
| 44 | auto name = GetProperty("sys.init.updatable_crashing_process_name", ""); |
| 45 | LOG(ERROR) << "Native process '" << (name.empty() ? "[unknown]" : name) |
| 46 | << "' is crashing. Attempting a revert"; |
Bernie Innocenti | d04d5d0 | 2020-02-06 22:01:51 +0900 | [diff] [blame] | 47 | auto result = revert_fn(name); |
| 48 | if (!result.ok()) { |
| 49 | LOG(ERROR) << "Revert failed : " << result.error(); |
Nikita Ioffe | 9bb12ed | 2020-03-21 13:08:04 +0000 | [diff] [blame] | 50 | break; |
Nikita Ioffe | 31dc34d | 2019-02-23 15:59:04 +0000 | [diff] [blame] | 51 | } else { |
Nikita Ioffe | 9bb12ed | 2020-03-21 13:08:04 +0000 | [diff] [blame] | 52 | // This should never be reached, since revert_fn should've rebooted a |
| 53 | // device. But if for some reason we end up here, let's reboot it |
| 54 | // manually. |
| 55 | LOG(ERROR) << "Active sessions were reverted, but reboot wasn't " |
| 56 | "triggered. Rebooting manually"; |
Nikita Ioffe | 31dc34d | 2019-02-23 15:59:04 +0000 | [diff] [blame] | 57 | Reboot(); |
Nikita Ioffe | 9bb12ed | 2020-03-21 13:08:04 +0000 | [diff] [blame] | 58 | return; |
Nikita Ioffe | 9ae986a | 2019-02-18 22:39:27 +0000 | [diff] [blame] | 59 | } |
Zimuzo | 9cc0be4 | 2019-01-09 11:37:34 +0000 | [diff] [blame] | 60 | } |
Nikita Ioffe | 9bb12ed | 2020-03-21 13:08:04 +0000 | [diff] [blame] | 61 | } |
| 62 | // Wait for boot to complete, and then run complete_fn. |
| 63 | // TODO(ioffe): this is a hack, instead we should have a binder call from |
| 64 | // system_server into apexd when boot completes. |
| 65 | if (WaitForProperty("sys.boot_completed", "1", std::chrono::minutes(5))) { |
| 66 | complete_fn(); |
| 67 | return; |
| 68 | } else { |
| 69 | LOG(ERROR) << "Boot never completed"; |
Zimuzo | 9cc0be4 | 2019-01-09 11:37:34 +0000 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | } // namespace apex |
| 73 | } // namespace android |