[uClibc]buglet in `tinylogin' with new uClibc stdio
Miles Bader
miles at lsi.nec.co.jp
Wed Mar 13 07:29:27 UTC 2002
When I telnet to my board, which uses apps compiled with the new uClibc
stdio, I can login succesfully, but /etc/motd (which is output by
tinylogin before execing the shell) is truncated:
(images) telnet mcspx1
Trying 10.30.114.220...
Connected to mcspx1.ucom.lsi.nec.co.jp.
Escape character is '^]'.
mcspx1.ucom.lsi.nec.co.jp login: miles
No directory, logging in with HOME=/
Welcome to
____ _ _ _ ___ ____ ___
_ _ / ___| (_)_ __ _ _ _ _ / >_ _( _ ) ___| / _ \
| | | | | | | | '_ \| | | < \/ > / /< \ / > _ \___ \| | | |
| |_| | |_
BusyBox v0.60.0 (2002.03.13-02:50+0000) Built-in shell (msh)
Enter 'help' for a list of built-in commands.
$
Looking at the code (in `user/tinylogin/login.c' from the
uClinux-dist-20020214 distribution), it outputs motd using a loop, in
the `motd' function:
if ((fp = fopen("/etc/motd", "r")) != NULL) {
while ((c = getc(fp)) != EOF) {
putchar(c);
}
fclose(fp);
}
and then the caller of `motd' (`login_main') goes ahead and execs the shell.
So it seems that the problem is that stdio isn't flushed. Here's a
patch that fixes the problem (for the uClinux-dev people):
diff -ruP -X../diff.xcl ../orig/uClinux-dist/user/tinylogin/login.c ./user/tinylogin/login.c
--- ../orig/uClinux-dist/user/tinylogin/login.c Thu Feb 14 11:44:34 2002
+++ user/tinylogin/login.c Wed Mar 13 16:15:42 2002
@@ -405,6 +405,7 @@
while ((c = getc(fp)) != EOF) {
putchar(c);
}
+ fflush (stdout);
fclose(fp);
}
}
However, I wonder why this didn't happen with the old stdio....
Was it not buffered, or did it default to line buffering? Is this a
potential compatibility problem?
-Miles
--
Love is a snowmobile racing across the tundra. Suddenly it flips over,
pinning you underneath. At night the ice weasels come. --Nietzsche
More information about the uClibc
mailing list