@@ -124,7 +124,8 @@ RaucBase::RaucBase(sdbus::dont_run_event_loop_thread_t) {
124
124
proxy = dbus::createProxy (defaults::service_domain, defaults::object_path, sdbus::dont_run_event_loop_thread);
125
125
}
126
126
127
- void RaucBase::configure () {
127
+ void RaucBase::configure (const std::string& verify_update_script_path) {
128
+ this ->verify_update_script_path = verify_update_script_path;
128
129
try {
129
130
dbus::initialise_handlers (proxy, [this ]() { configure_handlers (); });
130
131
} catch (const sdbus::Error& e) {
@@ -204,24 +205,36 @@ RaucBase::slot_info_t RaucBase::convert(slots_t& slots) {
204
205
return result;
205
206
}
206
207
207
- int RaucBase::check_system_health () {
208
+ rauc_messages::HealthCheckStatus RaucBase::check_system_health () {
208
209
// checking the success or failure of an OTA update following reboot
209
- //
210
- // get_primary_slot() may not be helpfull since it is updated as a result
211
- // of rauc status mark-active and isn't a good indicator that we have
212
- // rebooted into the newly updated partition
213
- //
214
- // get_boot_slot() should be more reliable since it indicates the slot
215
- // we booted from. This will change on a successful OTA + reboot
216
-
217
- std::string cmd = " /usr/bin/check_system_health.sh" ;
218
-
219
- // TODO(james-ctc): should the failure of this prevent the OTA being marked good?
220
- const auto res = everest::lib::system::safe_system (cmd, {" check_system_health.sh" });
221
- if (res.code != 0 ) {
222
- EVLOG_error << " Unable to run the system check script:" << cmd.c_str ();
210
+ using namespace rauc_messages ;
211
+ if (verify_update_script_path.empty ()) {
212
+ return HealthCheckStatus::ScriptNotSet;
223
213
}
224
- return res.code ;
214
+ if (access (verify_update_script_path.c_str (), X_OK) != 0 ) {
215
+ EVLOG_error << " Health check script '" << verify_update_script_path << " ' not executable" ;
216
+ return HealthCheckStatus::ScriptNotExecutable;
217
+ }
218
+ const auto res = everest::lib::system::safe_system (verify_update_script_path, {verify_update_script_path});
219
+ switch (res.status ) {
220
+ case everest::lib::system::CMD_SETUP_FAILED:
221
+ EVLOG_error << " Health check script '" << verify_update_script_path << " ' setup failed, errno: " << res.code ;
222
+ return HealthCheckStatus::SetupFailed;
223
+ case everest::lib::system::CMD_TERMINATED:
224
+ EVLOG_error << " Health check script '" << verify_update_script_path << " ' terminated by signal: " << res.code ;
225
+ return HealthCheckStatus::ScriptError;
226
+ case everest::lib::system::CMD_SUCCESS:
227
+ if (res.code == 0 ) {
228
+ EVLOG_debug << " Health check script '" << verify_update_script_path << " ' returned success" ;
229
+ return HealthCheckStatus::Success;
230
+ } else {
231
+ EVLOG_error << " Health check script '" << verify_update_script_path
232
+ << " ' returned error code: " << res.code ;
233
+ return HealthCheckStatus::ScriptError;
234
+ }
235
+ }
236
+ // Should not reach here
237
+ return HealthCheckStatus::ScriptError;
225
238
}
226
239
227
240
sdbus::PendingAsyncCall RaucBase::get_operation (property_cb handler) const {
@@ -245,10 +258,15 @@ sdbus::PendingAsyncCall RaucBase::get_progress(property_cb handler) const {
245
258
}
246
259
247
260
bool RaucBase::decide_if_good (const rauc_messages::UpdateTransaction& saved, const CurrentState& current) {
248
- // by default just check that the boot slot has changed
249
- // The return code from /usr/bin/check_system_health.sh could be used to
250
- // prevent marking as good
251
- return saved.boot_slot != current.boot_slot ;
261
+ // check that the boot slot has changed and update script ran successfully or was not set
262
+ if (saved.boot_slot == current.boot_slot ) {
263
+ return false ;
264
+ }
265
+ if (current.system_health_rc != rauc_messages::HealthCheckStatus::Success and
266
+ current.system_health_rc != rauc_messages::HealthCheckStatus::ScriptNotSet) {
267
+ return false ;
268
+ }
269
+ return true ;
252
270
}
253
271
254
272
// ----------------------------------------------------------------------------
0 commit comments