switch-root: NACK invalid requests instead of false success

initctl switch-root always exits 0, no matter what happens on the
finit side.  do_switch_root_api() sends the ACK before switch_root()
has validated anything, so any failure after that point never reaches
the client -- the error only shows up in the log.  The runlevel guard
in api_cb() has the same problem: it rejects the request but still
sends an ACK.

Split the validation out of switch_root() into switch_root_precheck()
and run it before the ACK.  A failed check now sends a NACK with the
error message, which initctl prints before exiting 1:

    initctl switch-root /mnt
    switch-root: /mnt is not a mount point

The ACK is only sent once the precheck passes, since after that point
we are committed.  On success finit execs the new init and the
connection dies with no reply at all, so initctl treats only an
explicit NACK as failure.

Signed-off-by: Paweł Sobczak <github@fixeq.qzz.io>
This commit is contained in:
Paweł Sobczak authored and Joachim Wiberg committed 2026-08-16 23:17:57 +02:00
1 parent 8e2492fc87
commit 42840f0f36
4 files changed
+130 -69

No files matched your search

+2
View File
@@ -70,6 +70,8 @@ int plugin_init (uev_ctx_t *ctx);
void plugin_exit (void);
void iterate_proc (int (*cb)(int, void *), void *data);
int switch_root_precheck(const char *newroot, const char *newinit,
char *errbuf, size_t errbuflen);
int switch_root (const char *newroot, const char *newinit);
#endif /* FINIT_PRIVATE_H_ */