Skip to content

Commit

Permalink
Delay start of dockerd until SD card is available (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
killenheladagen authored Aug 8, 2024
1 parent 8f0a6d6 commit 7b48035
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions app/dockerdwrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@ static gboolean get_and_verify_tls_selection(AXParameter* param_handle, bool* us
return true;
}

// Meant to be used as a one-shot call from g_timeout_add_seconds()
static gboolean quit_main_loop(void*) {
main_loop_quit();
return FALSE;
}

// Read and verify consistency of settings. Call set_status_parameter() or quit_program() and return
// false on error.
static bool read_settings(struct settings* settings, const struct app_state* app_state) {
Expand Down Expand Up @@ -430,6 +436,15 @@ static bool read_settings(struct settings* settings, const struct app_state* app
return false;
}

// It takes a few seconds from sd_disk_storage_init() until sd_card_callback(), which is when
// app_state->sd_card_area is set. Waiting here means we may avoid failure in the call to
// prepare_data_root() below.
if (is_parameter_yes(param_handle, PARAM_SD_CARD_SUPPORT) && !app_state->sd_card_area) {
int id = g_timeout_add_seconds(5, quit_main_loop, NULL);
g_main_loop_run(loop); // Wait until the timer or sd_card_callback() calls main_loop_quit()
g_source_remove(id); // If it was sd_card_callback(), the timer must not restart dockerd.
}

if (!(settings->data_root = prepare_data_root(param_handle, app_state->sd_card_area)))
return false;

Expand Down Expand Up @@ -679,12 +694,6 @@ static void stop_dockerd(void) {
log_info("Stopped dockerd.");
}

// Meant to be used as a one-shot call from g_timeout_add_seconds()
static gboolean quit_main_loop(void*) {
main_loop_quit();
return FALSE;
}

// Meant to be used as an AXParameter callback
static void restart_dockerd_when_parameter_changed(const gchar* name,
const gchar* value,
Expand Down

0 comments on commit 7b48035

Please sign in to comment.