[OpenWrt-Devel] [PATCH procd 7/8] Show the shutdown sequence on the active virtual terminal

John Crispin blogic at openwrt.org
Fri Oct 3 12:34:42 EDT 2014


see inline

On 02/10/2014 14:56, Michel Stam wrote:
> procd by default writes to /dev/console. When rebooting, this means
> that the terminal on which the reboot sequence was started will not
> see what is going on. This patch fixes that by reopening stdin,
> stdout and stderr to /dev/tty0 upon reboot.
> 
> Also, due to (probably) pivot-root, /proc/1/fd shows 1-3 pointing
> to /console. This patch also fixes that.
> 
> Signed-off-by: Michel Stam <m.stam at fugro.nl> --- state.c | 13
> +++++++++++++ 1 file changed, 13 insertions(+)
> 
> diff --git a/state.c b/state.c index e6c8712..2268de3 100644 ---
> a/state.c +++ b/state.c @@ -12,7 +12,9 @@ * GNU General Public
> License for more details. */
> 
> +#include <fcntl.h> #include <sys/reboot.h> +#include <stdio.h> 
> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> @@
> -37,6 +39,14 @@ enum { static int state = STATE_NONE; static int
> reboot_event;
> 
> +static void set_stdio( const char* tty ) +{ +	freopen( tty, "r",
> stdin ); +	freopen( tty, "w", stdout ); +	freopen( tty, "w", stderr
> ); +	fcntl(STDERR_FILENO, F_SETFL, fcntl(STDERR_FILENO, F_GETFL) |
> O_NONBLOCK); +} + static void state_enter(void) { char ubus_cmd[] =
> "/sbin/ubusd"; @@ -55,6 +65,7 @@ static void state_enter(void) 
> LOG("- ubus -\n"); procd_connect_ubus();
> 
> +		set_stdio( "/dev/console" ); LOG("- init -\n"); service_init(); 
> service_start_early("ubus", ubus_cmd); @@ -71,6 +82,8 @@ static
> void state_enter(void) break;
> 
> case STATE_SHUTDOWN: +		/* Redirect output to the current virtual
> terminal for the users' benefit */ +		set_stdio( "/dev/tty0" );

tty0 is a virtual console on a desktop. routers don't have a tty0.
this would break all the routers



> LOG("- shutdown -\n"); procd_inittab_run("shutdown"); sync();
> 
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list