[OpenWrt-Devel] [PATCH procd 7/8] Show the shutdown sequence on the active virtual terminal
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 --- 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 #include +#include #include #include #include @@ -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" ); LOG("- shutdown -\n"); procd_inittab_run("shutdown"); sync(); -- 1.7.12.1 ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
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 --- 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 #include +#include > #include #include #include @@ > -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@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH procd 7/8] Show the shutdown sequence on the active virtual terminal
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 -Original Message- From: openwrt-devel [mailto:openwrt-devel-boun...@lists.openwrt.org] On Behalf Of John Crispin Sent: Friday, October 03, 2014 18:35 PM To: openwrt-devel@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 --- 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 #include +#include > #include #include #include @@ > -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@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH procd 7/8] Show the shutdown sequence on the active virtual terminal
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-boun...@lists.openwrt.org] On > Behalf Of John Crispin > Sent: Friday, October 03, 2014 18:35 PM > To: openwrt-devel@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 --- 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 #include +#include >> #include #include #include @@ >> -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@lists.openwrt.org > https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel > ___ > openwrt-devel mailing list > openwrt-devel@lists.openwrt.org > https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel > ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH procd 7/8] Show the shutdown sequence on the active virtual terminal
On 06/10/2014 16:47, Stam, Michel [FINT] wrote: > Hey John, > > Ok, I will rework the patch to use that, then repost it. > > Kind regards, > > Michel Stam i just had a look, we already have 2 pieces of code for reading values from the cmdline. can you move the code from init/initd.c and inittab.c to utils/utils.c and add a function such as get_cmdline_val(char *name, char *out, int len); that setups up the regex based on name and returns the value inside out. and then use it all 3 places please. > > -Original Message- From: openwrt-devel > [mailto:openwrt-devel-boun...@lists.openwrt.org] On Behalf Of John > Crispin Sent: Monday, October 06, 2014 16:46 PM To: > openwrt-devel@lists.openwrt.org Subject: Re: [OpenWrt-Devel] [PATCH > procd 7/8] Show the shutdown sequence on the active virtual > terminal > > > > 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-boun...@lists.openwrt.org] On Behalf Of >> John Crispin Sent: Friday, October 03, 2014 18:35 PM To: >> openwrt-devel@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 --- 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 #include +#include >>> #include #include #include >>> @@ -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@lists.openwrt.org >> https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel >> ___ openwrt-devel >> mailing list openwrt-devel@lists.openwrt.org >> https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel >> > ___ openwrt-devel > mailing list openwrt-devel@lists.openwrt.org > https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel > ___ openwrt-devel > mailing list openwrt-devel@lists.openwrt.org > https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel > ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH procd 7/8] Show the shutdown sequence on the active virtual terminal
Hey John, Ok, I will rework the patch to use that, then repost it. Kind regards, Michel Stam -Original Message- From: openwrt-devel [mailto:openwrt-devel-boun...@lists.openwrt.org] On Behalf Of John Crispin Sent: Monday, October 06, 2014 16:46 PM To: openwrt-devel@lists.openwrt.org Subject: Re: [OpenWrt-Devel] [PATCH procd 7/8] Show the shutdown sequence on the active virtual terminal 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-boun...@lists.openwrt.org] > On Behalf Of John Crispin > Sent: Friday, October 03, 2014 18:35 PM > To: openwrt-devel@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 --- 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 #include +#include >> #include #include #include @@ >> -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@lists.openwrt.org > https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel > ___ > openwrt-devel mailing list > openwrt-devel@lists.openwrt.org > https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel > ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel