state: set_stdio: chdir back to / in case of failure master
authorAndreas Gnau <andreas.gnau@iopsys.eu>
Tue, 5 Dec 2023 17:51:46 +0000 (18:51 +0100)
committerJohn Crispin <john@phrozen.org>
Wed, 11 Dec 2024 11:10:55 +0000 (12:10 +0100)
commite2f05deb93949f447d397e8cd3a341bc8e53cd38
tree796a0ed93dd5d6363ba84b67316dd68e36156352
parent30542c94c4255acfaffa8e20b88783b01fa00c4a
state: set_stdio: chdir back to / in case of failure

set_stdio chdirs to /dev/ to facilitate easy freopen of the console
device name given by the tty parameter. Make sure to chdir back to / in
all cases, even in the error path. This keeps the function free from
unintended side effects.

Before this commit, in case of an error, the working directory would
remain /dev/ which would break sysupgrade because the rest of the code
would rely on the current working directory to be unchanged, which is
not an unreasonable expectation to make.

Fixing this fixes an issue where sysupgrade would fail, when
/dev/console does not exist or cannot be opened, which can happen for
example when setting console= on kernel cmdline.

Closes: https://github.com/openwrt/openwrt/issues/6005
Fixes: 91da63d3d3fd ("properly handle return codes")
Signed-off-by: Andreas Gnau <andreas.gnau@iopsys.eu>
state.c