aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Fleming <matt.fleming@intel.com>2012-09-03 14:35:14 +0100
committerMatt Fleming <matt.fleming@intel.com>2012-09-04 17:33:51 +0100
commit2088016394a3e0cecbddda97ac71a895ae8513ff (patch)
treea10fb2e559fa382070e4f7f856ce9a60dc7b1d59
parentd1d03dee6bc961b0afd8dfc68fd35772ecded8be (diff)
downloadsyslinux-2088016394a3e0cecbddda97ac71a895ae8513ff.tar.gz
syslinux-2088016394a3e0cecbddda97ac71a895ae8513ff.tar.xz
syslinux-2088016394a3e0cecbddda97ac71a895ae8513ff.zip
console: Close stdin, stdout, stderr on ldlinux.c32 unload
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@intel.com>
-rw-r--r--com32/elflink/ldlinux/ldlinux.c12
-rw-r--r--com32/lib/Makefile2
-rw-r--r--core/extern.inc2
-rw-r--r--core/hello.c5
-rw-r--r--core/init.c2
5 files changed, 13 insertions, 10 deletions
diff --git a/com32/elflink/ldlinux/ldlinux.c b/com32/elflink/ldlinux/ldlinux.c
index 1c261cd5..f82b1662 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 5d270a49..fc5defc5 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 3cde2863..953be42b 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 d30fc3b9..bed7cb59 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 01319f49..26b4a191 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();