Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/confd/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
snprintf(path, sizeof(path), "/run/finit/cond/%s", cond);
snprintf(path, sizeof(path), "/run/finit/cond/usr/%s", cond);

I understand the impulse to use the old condition names from IITO's config. However, the run/ namespace is reserved by Finit to signal the status of run jobs under its control. The usr/ namespace is allocated for general use by the system.


/* 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 = '/';
}
}
Comment on lines +64 to +71

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* 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 = '/';
}
}

Finit guarantees that /run/finit/cond/usr exists (via a tmpfiles snippet). So with the suggested change above, together with limiting condition names to a single level, we can safely skip this.


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"
Expand Down Expand Up @@ -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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@troglobit: Should we not emit the CRITICAL ERROR: ... in this scenario as well? The system is still without any defined config in this case, no?

}

Expand All @@ -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");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set_finit_cond("run/failure/failure");
set_finit_cond("failure-config-error");

Depending on @troglobit's input, this path may have to be merged with the earlier error path. But I think at think point we want to signal "we tried, but failed, to apply failure-config.

return;
}
}

banner_append("ERROR: Corrupt startup-config, system has reverted to default login credentials");
set_finit_cond("run/failure/success");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
set_finit_cond("run/failure/success");
set_finit_cond("failure-config-ok");

For symmetry with the other condition names.

}

/*
Expand Down Expand Up @@ -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");

Comment on lines 872 to +876

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
symlink("/run/finit/cond/reconf", "/run/finit/cond/usr/bootstrap");
/* Signal IITO that startup applied cleanly (status LEDs) */
set_finit_cond("run/startup/success");
set_finit_cond("bootstrap");

Let's move the existing condition to use the new helper, but I don't think we can be sure that startup has cleanly applied at this point. I have marked that point in a separate comment.

/*
* Write restart sentinel. From this point on, sysrepo and the system
* are in a consistent state. If confd exits for any reason (crash or
Expand Down