[ale] Weird Perl problem

Christopher Fowler cfowler at outpostsentinel.com
Tue Oct 17 21:49:50 EDT 2006


I'm creating a usb flash stick to flash our devices.  I've loaded perl
and it is not behaving well with STDIN. 

~ $ ls -l /
drwxrwxr-x    2 root     root         1024 Oct 17 21:37 bin
drwxrwxr-x   11 root     root        12288 Oct 17 16:15 dev
drwxrwxr-x    3 root     root         1024 Oct 17 20:44 etc
drwxrwxr-x   11 500      501          1024 Oct 17 21:40 initrd
drwxrwxr-x    2 root     root         1024 Oct 17 19:54 lib
drwx------    2 root     root        12288 Oct 17 21:37 lost+found
drwxr-xr-x    3 root     root         1024 Oct 17 13:49 mnt
drwxrwxr-x    4 root     root         1024 Oct 17 18:25 opt
dr-xr-xr-x   41 root     root            0 Oct 17 21:40 proc
drwxr-xr-x    2 root     root         1024 Oct 17 20:44 root
drwxrwxr-x    2 root     root         1024 Oct 17 12:56 sbin
drwxrwxrwt    2 root     root           60 Oct 17 21:40 tmp
drwxrwxr-x    5 root     root         1024 Oct 17 16:26 usr
drwxr-xr-x    5 root     root         1024 Oct 17 18:25 var
~ $ ls -l / | perl -e 'while(<STDIN>) { print "$_"; }'
~ $


notice above I'm piping the contents of the same command I executed
first to perl.  Perl does not even read it ?

strace shows an attempt to read STDIN but gets 0 (eof)

~ $ ls -l / | strace -e trace=open,read,write,select perl -e 'while
(<STDIN>) { print "$_"; }'
open("/etc/ld.so.cache", O_RDONLY)      = 3
open("/lib/libnsl.so.1", O_RDONLY)      = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\320\344"...,
512) = 512
open("/lib/libdl.so.2", O_RDONLY)       = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\260{_\000"...,
512) = 512
open("/lib/libm.so.6", O_RDONLY)        = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\0S]\000"...,
512) = 512
open("/lib/libcrypt.so.1", O_RDONLY)    = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\340\207"...,
512) = 512
open("/lib/libutil.so.1", O_RDONLY)     = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\220\254"...,
512) = 512
open("/lib/libpthread.so.0", O_RDONLY)  = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\20\310"...,
512) = 512
open("/lib/libc.so.6", O_RDONLY)        = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\20\237"...,
512) = 512
open("/dev/urandom", O_RDONLY|O_LARGEFILE) = 3
read(3, "\260HY\377", 4)                = 4
open("/dev/null", O_RDONLY|O_LARGEFILE) = 3
read(0, "", 4096)                       = 0

It can read my echo

~ $ echo "Hello" | strace -e trace=open,read,write,select perl -e 'while
(<STDIN>) { print "$_"; }'
open("/etc/ld.so.cache", O_RDONLY)      = 3
open("/lib/libnsl.so.1", O_RDONLY)      = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\320\344"...,
512) = 512
open("/lib/libdl.so.2", O_RDONLY)       = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\260{_\000"...,
512) = 512
open("/lib/libm.so.6", O_RDONLY)        = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\0S]\000"...,
512) = 512
open("/lib/libcrypt.so.1", O_RDONLY)    = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\340\207"...,
512) = 512
open("/lib/libutil.so.1", O_RDONLY)     = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\220\254"...,
512) = 512
open("/lib/libpthread.so.0", O_RDONLY)  = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\20\310"...,
512) = 512
open("/lib/libc.so.6", O_RDONLY)        = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\20\237"...,
512) = 512
open("/dev/urandom", O_RDONLY|O_LARGEFILE) = 3
read(3, "\230\341l\263", 4)             = 4
open("/dev/null", O_RDONLY|O_LARGEFILE) = 3
read(0, "Hello\n", 4096)                = 6
write(1, "Hello\n", 6Hello
)                  = 6
read(0, "", 4096)  


And it seems to work with large output. If I do a find / it will display
but will seem to be cut off.
/usr/bin/who
/usr/bin/yes
/usr/bin/comm
/usr~ $ 
~ $

I'm using busybox ash shell.  I probably should try this using perl exec
and not use the shell.  That might tell me if the problem is in the
shell.










More information about the Ale mailing list