diff --git a/src/confd/src/main.c b/src/confd/src/main.c index f679d9df6..f646a8ee7 100644 --- a/src/confd/src/main.c +++ b/src/confd/src/main.c @@ -49,6 +49,31 @@ */ #define SENTINEL_PATH "/run/confd.boot" +/* + * Set a finit condition, e.g. "run/startup/success", creating parent + * directories as needed. Used to signal IITO (and finit services) about + * the outcome of the bootstrap/startup sequence. + */ +static void set_finit_cond(const char *cond) +{ + char path[128]; + char *p; + + snprintf(path, sizeof(path), "/run/finit/cond/%s", cond); + + /* mkdir -p parent directories (e.g. /run/finit/cond/run/startup) */ + for (p = path + strlen("/run/finit/cond/"); *p; p++) { + if (*p == '/') { + *p = '\0'; + mkdir(path, 0755); + *p = '/'; + } + } + + if (symlink("/run/finit/cond/reconf", path) && errno != EEXIST) + WARN("Failed to set finit condition %s: %m", path); +} + /* Callback type names from sysrepo plugin API */ #define SRP_INIT_CB "sr_plugin_init_cb" #define SRP_CLEANUP_CB "sr_plugin_cleanup_cb" @@ -512,6 +537,7 @@ static void handle_startup_failure(sr_session_ctx_t *sess, const char *failure_p ERROR("sr_copy_config(factory-default) failed: %s", sr_strerror(r)); /* Nuclear option: wipe everything */ systemf("rm -f /etc/sysrepo/data/*startup* /etc/sysrepo/data/*running* /dev/shm/sr_*"); + set_finit_cond("run/failure/failure"); return; } @@ -521,11 +547,13 @@ static void handle_startup_failure(sr_session_ctx_t *sess, const char *failure_p ERROR("Failed loading failure-config, aborting!"); banner_append("CRITICAL ERROR: Logins are disabled, no credentials available"); systemf("initctl -nbq runlevel 9"); + set_finit_cond("run/failure/failure"); return; } } banner_append("ERROR: Corrupt startup-config, system has reverted to default login credentials"); + set_finit_cond("run/failure/success"); } /* @@ -843,6 +871,9 @@ int main(int argc, char **argv) /* Signal that bootstrap is complete (dbus, resolvconf depend on this) */ symlink("/run/finit/cond/reconf", "/run/finit/cond/usr/bootstrap"); + /* Signal IITO that startup applied cleanly (status LEDs) */ + set_finit_cond("run/startup/success"); + /* * Write restart sentinel. From this point on, sysrepo and the system * are in a consistent state. If confd exits for any reason (crash or