Skip to content

confd: set IITO startup/failure conditions (fixes status LEDs) - #1587

Open
pjator wants to merge 1 commit into
kernelkit:mainfrom
pjator:nanopi-r2s-led
Open

confd: set IITO startup/failure conditions (fixes status LEDs)#1587
pjator wants to merge 1 commit into
kernelkit:mainfrom
pjator:nanopi-r2s-led

Conversation

@pjator

@pjator pjator commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

iitod.json expects /run/finit/cond/run/startup/success before the LAN and status LEDs light up, but nothing ever creates it. Add a small finit service (after confd/ready) that sets the condition on every boot.

Description

Checklist

Tick relevant boxes, this PR is-a or has-a:

  • Bugfix
    • Regression tests
    • ChangeLog updates (for next release)
  • Feature
    • YANG model change => revision updated?
    • Regression tests added?
    • ChangeLog updates (for next release)
    • Documentation added?
  • Test changes
    • Checked in changed Readme.adoc (make test-spec)
    • Added new test to group Readme.adoc and yaml file
  • Code style update (formatting, renaming)
  • Refactoring (please detail in commit messages)
  • Build related changes
  • Documentation content changes
    • ChangeLog updated (for major changes)
  • Other (please describe):

@wkz

wkz commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

When confd became its own daemon (in 77a7915), the conditions used by IITO where also removed.

Currently, a condition is set when startup is applied:

symlink("/run/finit/cond/reconf", "/run/finit/cond/usr/bootstrap");

But there are no corresponding conditions for the failure cases. I suggest we add those and then update the IITO configuration to match.

@wkz wkz left a comment

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.

Let's fix the root cause so that it (1) fixes all boards and (2) also fixes the error cases when startup fails to apply cleanly.

@pjator

pjator commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

Fixed per your suggestion. confd now sets run/startup/success after a clean bootstrap and run/failure/success/run/failure/failure in handle_startup_failure() (fail-secure + panic paths). The board-specific workaround is dropped. Verified on hardware: LED lights on boot, eMMC visible.

@pjator pjator changed the title board: nanopi-r2s: set iitod startup condition for LAN/status LEDs confd: set IITO startup/failure conditions (fixes status LEDs) Aug 14, 2026
The product and common iitod.json configurations reference finit
conditions /run/finit/cond/run/startup/success and
/run/finit/cond/run/failure/{success,failure} to drive status LEDs,
but nothing ever creates them, so the LEDs stay dark on every boot.

confd already signals usr/bootstrap when startup applies; add the
matching conditions for a clean startup and for the failure paths
(fail-secure fallback and the fatal runlevel 9 case), which fixes
LED behaviour on all boards.

Co-authored-by: Jarvis (Hermes Agent) <jarvis@woxblom.com>

@wkz wkz left a comment

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.

Thanks for taking another stab at this! Sorry about the slew of comments 😅 - you picked a pretty core piece of code for your first contribution.

In addition to these changes, I think handle_startup_failure() might need some additional changes. Let's wait and see what @troglobit thinks.

Also, the IITO config needs to be updated to reference the new condition names.

Comment thread src/confd/src/main.c
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.

Comment thread src/confd/src/main.c
Comment on lines +64 to +71
/* 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 = '/';
}
}

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.

Comment thread src/confd/src/main.c
Comment on lines 872 to +876
symlink("/run/finit/cond/reconf", "/run/finit/cond/usr/bootstrap");

/* Signal IITO that startup applied cleanly (status LEDs) */
set_finit_cond("run/startup/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
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.

Comment thread src/confd/src/main.c
if (r != SR_ERR_OK)
WARN("Failed to sync startup datastore: %s", sr_strerror(r));

return 0;

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("startup-config-ok");
return 0;

I believe this is the point where we want to signal a successful application of startup-config

Comment thread src/confd/src/main.c
int r;

ERROR("Failed loading startup-config, reverting to Fail Secure mode!");

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("startup-config-error");

Whatever happens beyond this point, I think we should leave a marker that we could not apply startup-config.

Comment thread src/confd/src/main.c
/* 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?

Comment thread src/confd/src/main.c
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.

Comment thread src/confd/src/main.c
}

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.

@pjator

pjator commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

@wkz Thanks for the thorough review — it's really helpful, and I agree with the direction (usr/ namespace, single-level condition names, and updating the IITO config accordingly).

I'll wait for @troglobit's input before pushing an updated version, so we can address everything in one pass and match the structure you'd prefer.

I'll follow up once he's had a chance to weigh in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants