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

John Crispin blogic at openwrt.org
Mon Oct 6 10:45:47 EDT 2014



On 06/10/2014 15:24, Stam, Michel [FINT] wrote:
> Hello John,
> 
> We have a tty0 (our board happened to have an x86 processor), the
> situation is no different when you're running this with the console port
> on the serial port of a router board. The presence of the VT in the
> kernel determines if tty0 actually exists. So point taken, I had not
> taken that into account.
> 
> My point is that i would like to see what is going on when I issue a
> reboot on a device. It would be logical to see that on whatever screen
> happens to be active at that moment.
> Is it acceptable for you if I try and open /dev/tty0 if available, or
> use /dev/console otherwise? 
> 
> Kind regards,
> 
> Michel Stam


inside inittab.c we work out the value of console= on the kernels
cmdline and use the value as basis for setting up console. you could try
to reuse that value to work out actual terminal that the messages should
be printed to.




> 
> -----Original Message-----
> From: openwrt-devel [mailto:openwrt-devel-bounces at lists.openwrt.org] On
> Behalf Of John Crispin
> Sent: Friday, October 03, 2014 18:35 PM
> To: openwrt-devel at lists.openwrt.org
> Subject: Re: [OpenWrt-Devel] [PATCH procd 7/8] Show the shutdown
> sequence on the active virtual terminal
> 
> 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
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel at lists.openwrt.org
> https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
> 
_______________________________________________
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