Re: [PATCH procd] state: set_stdio: chdir back to / in case of failure

2024-03-15 Thread Andreas Gnau via openwrt-devel
The sender domain has a DMARC Reject/Quarantine policy which disallows
sending mailing list messages using the original "From" header.

To mitigate this problem, the original message has been wrapped
automatically by the mailing list software.--- Begin Message ---

Friendly ping ;-)

--- End Message ---
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[PATCH procd] state: set_stdio: chdir back to / in case of failure

2023-12-07 Thread Andreas Gnau via openwrt-devel
The sender domain has a DMARC Reject/Quarantine policy which disallows
sending mailing list messages using the original "From" header.

To mitigate this problem, the original message has been wrapped
automatically by the mailing list software.--- Begin Message ---
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 /
done 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 
---
 state.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/state.c b/state.c
index fb81248fd7e7..30e3569c8af9 100644
--- a/state.c
+++ b/state.c
@@ -48,11 +48,12 @@ static void set_stdio(const char* tty)
if (chdir("/dev") ||
!freopen(tty, "r", stdin) ||
!freopen(tty, "w", stdout) ||
-   !freopen(tty, "w", stderr) ||
-   chdir("/"))
+   !freopen(tty, "w", stderr))
ERROR("failed to set stdio: %m\n");
else
fcntl(STDERR_FILENO, F_SETFL, fcntl(STDERR_FILENO, F_GETFL) | 
O_NONBLOCK);
+   if (chdir("/"))
+   ERROR("failed to change dir to /: %m\n");
 }
 
 static void set_console(void)
-- 
2.43.0


--- End Message ---
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel