state: set_stdio: chdir back to / in case of failure #9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This has been previously posted to the mailinglist
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: openwrt/openwrt#6005
Fixes: 91da63d ("properly handle return codes")