Matt Fleming
2012-Sep-04 16:36 UTC
[syslinux] [PATCH] console: Close stdin, stdout, stderr on ldlinux.c32 unload
From: Matt Fleming <matt.fleming at intel.com> The location of __file_info[] and ansicon_counter are split between the core and ldlinux.c32. We can end up calling __ansicon_close (from fp->oop->close) in the process of reloading ldlinux.c32, and while ansicon_counter is set to its initialised data value of 0 when reloading ldlinux.c32, the core is never reloaded, and so __file_info[] retains its pointers. What this amounts to is that when ldlinux.c32 tries to call openconsole() after being reloaded, the core tries to close the ansicon device (the core still has pointers to __ansicon_close) despite the ansicon code having no knowledge of ever being opened (because ansicon_counter was reinitialised). The most logical way to deal with this is to close stdin, stdout and stderr when unloading ldlinux.c32. It also turns out that sys/openconsole.o was present in two Makefile variables which lead to duplication of code, data, etc. We only need it present in libcom32min.a and not in the core since the core never handles opening consoles, at least not now that we've deleted printf_init() which is safe because we always open a console in ldlinux.c32 anyway. Signed-off-by: Matt Fleming <matt.fleming at intel.com> --- com32/elflink/ldlinux/ldlinux.c | 12 ++++++++++++ com32/lib/Makefile | 2 +- core/extern.inc | 2 -- core/hello.c | 5 ----- core/init.c | 2 -- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/com32/elflink/ldlinux/ldlinux.c b/com32/elflink/ldlinux/ldlinux.c index 1c261cd..f82b166 100644 --- a/com32/elflink/ldlinux/ldlinux.c +++ b/com32/elflink/ldlinux/ldlinux.c @@ -252,6 +252,18 @@ cmdline: goto auto_boot; } + +/* + * Undo the work we did in openconsole(). + */ +static void __destructor close_console(void) +{ + int i; + + for (i = 0; i <= 2; i++) + close(i); +} + int main(int argc __unused, char **argv __unused) { const void *adv; diff --git a/com32/lib/Makefile b/com32/lib/Makefile index 5d270a4..fc5defc 100644 --- a/com32/lib/Makefile +++ b/com32/lib/Makefile @@ -170,7 +170,7 @@ CORELIBOBJS = \ sprintf.o strlcat.o strchr.o strlcpy.o strncasecmp.o ctypes.o \ fputs.o fwrite2.o fwrite.o fgetc.o fclose.o errno.o lmalloc.o \ sys/err_read.o sys/err_write.o sys/null_read.o \ - sys/stdcon_write.o sys/openconsole.o \ + sys/stdcon_write.o \ syslinux/memscan.o strrchr.o \ libgcc/__ashldi3.o libgcc/__udivdi3.o \ libgcc/__negdi2.o libgcc/__ashrdi3.o libgcc/__lshrdi3.o \ diff --git a/core/extern.inc b/core/extern.inc index 3cde286..953be42 100644 --- a/core/extern.inc +++ b/core/extern.inc @@ -27,8 +27,6 @@ extern hexdump, mydump - extern printf_init - extern mem_init ; fs.c diff --git a/core/hello.c b/core/hello.c index d30fc3b..bed7cb5 100644 --- a/core/hello.c +++ b/core/hello.c @@ -76,8 +76,3 @@ void mp5(void) myprint(5); } -void printf_init(void) -{ - openconsole(&dev_null_r, &dev_stdcon_w); -} - diff --git a/core/init.c b/core/init.c index 01319f4..26b4a19 100644 --- a/core/init.c +++ b/core/init.c @@ -62,7 +62,6 @@ static inline void bios_timer_init(void) *hook = (uint32_t)&timer_irq; } -extern void printf_init(void); void init(com32sys_t *regs __unused) { int i; @@ -74,7 +73,6 @@ void init(com32sys_t *regs __unused) KbdMap[i] = i; adjust_screen(); - printf_init(); /* Init the memory subsystem */ mem_init(); -- 1.7.4.4