On Fri, Jul 8, 2011 at 12:33 AM, Denys Vlasenko
<[email protected]> wrote:
> There is probably no deep wisdom behind it. I think second #ifdef
> should be changed to #ifdef VT_GETSTATE, it will make more sense that way.

Here are a few patches to implement the changes we discussed:

0001 - check sysfs for the name of the active console

function                                             old     new   delta
.rodata                                           147781  147813     +32
cttyhack_main                                        296     324     +28
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 60/0)               Total: 60 bytes
   text    data     bss     dec     hex filename
1002368    1667    4961 1008996   f6564 busybox_old
1002428    1667    4961 1009056   f65a0 busybox_unstripped

Changing the code to use "do/while(0)/break/goto" instead of
"if(console[8])" saved about 12 bytes.

This was tested with ttyS0 and ttyAMA0, with and without the sysfs
feature.  Not tested on tty0.

It is legal for /sys/class/tty/console/active to return more than one
device name, separated by spaces.  I did not attempt to handle this
case, so if cttyhack runs into this situation it will try to open e.g.
"/dev/ttyS0 ttyS1" and this will not succeed.


0002 - test for defined(VT_GETSTATE) instead of defined(__linux__)

No impact on code size.

This patch brings cttyhack in line with the approach used in init/init.c:

#ifdef __linux__
#include <linux/vt.h>
#endif

[...]

#ifdef VT_foo

This case is relatively easy to handle because VT_GETSTATE and struct
vt_stat are both defined in <linux/vt.h>.  You should not get one
without the other.

(Side note: is TIOCGSERIAL available on any non-Linux platforms?  If
so, what does it use in lieu of the Linux serial_struct?  If not,
should cttyhack be marked as Linux-only?)


0003 - fail gracefully if the device node is missing

function                                             old     new   delta
cttyhack_main                                        324     328      +4
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/0 up/down: 4/0)                 Total: 4 bytes
   text    data     bss     dec     hex filename
1002428    1667    4961 1009056   f65a0 busybox_old
1002432    1667    4961 1009060   f65a4 busybox_unstripped


One thing I noticed when testing with the console on ttyAMA0 is that
TIOCGSERIAL still succeeds (via serial_core.c:uart_get_info() in the
kernel), so cttyhack erroneously tries to open the nonexistent
/dev/ttyS0 device, and when that fails, it exits without running the
shell.  This actually means you are worse off with cttyhack than
without it, in some unusual cases.

cttyhack could also fail to open the correct device if mdev somehow
malfunctioned.

My proposed fix is to change cttyhack so that it merely skips the
"dup2" code with a non-fatal error, rather than terminating
immediately, if it cannot open the device.

Attachment: 0001-cttyhack-check-sysfs-for-the-name-of-the-active-cons.patch
Description: Binary data

Attachment: 0002-cttyhack-test-for-defined-VT_GETSTATE-instead-of-def.patch
Description: Binary data

Attachment: 0003-cttyhack-fail-gracefully-if-the-device-node-is-missi.patch
Description: Binary data

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to