On Sunday 10 July 2011 22:33, Kevin Cernekee wrote:
> 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.


+                       ssize_t s = 
open_read_close("/sys/class/tty/console/active",
+                               &console[5], sizeof(console) - 5);
+                       if (s > 0) {
+                               /* found active console via sysfs (Linux 
2.6.38+ only) */
+                               console[4 + s] = 0;

Why 4, not 5? And if changed to 5, it can overflow console[],
need to use sizeof(console) - 6 in read.

+                               break;
+                       }


> 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.

Now we will require that linux/vt.h exists. This may be not such a good idea:
some people do use semibroken toolchain where some headers are missing.


> 0003 - fail gracefully if the device node is missing
> 
> 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.


Applied patches 1 and 3. Thanks!
-- 
vda
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to