fbsplash

Denys Vlasenko vda.linux at googlemail.com
Fri Mar 28 10:46:34 UTC 2008


On Friday 28 March 2008 08:55, Michele Sanges wrote:
> 
> Il giorno gio, 27/03/2008 alle 17.28 +0100, Denys Vlasenko ha scritto:
> > O_NONBLOCK does not matter one iota if you reached EOF.
> > read() will return 0 immediately, it will not block.
> > 
> > Your code is hogging CPU, since your read() sits in a while (1) loop.
> 
> +       while(1) {
> +               int nVal;
> +
> +               len = read(fd, buf, 255);
> +	printf("after reading\n");
> +               if (len == -1) {
> +                       DEBUG_MESSAGE("error reading the fifo");
> +                       break;
> +               }
> +       }
> 
> Can you tell me why I see the printf string only when I send a command
> to the applet?

I don't know. You need to give more complete description of what you are doing.

Here is my description:

First, I modify fbsplash.c so that it doesn't really use fb device,
for ease of experiment, and also add a few debug prints.
See modified file in attachment. Basically:

                while ((num_buf = xmalloc_fgetline(fp)) != NULL) {
bb_error_msg("got '%s'", num_buf);
                        if (strncmp(num_buf, "exit", 4) == 0) {
...
                        }
                        free(num_buf);
                }
                // We got EOF/error on fp
                if (ferror(fp))
                        goto exit_cmd;
// TESTING: will read block?
{ static char b; read(fileno(fp), &b, 1); }
bb_error_msg("got EOF");
continue;

We are getting NULL from xmalloc_fgetline() when read() inside it
returns 0. Added "continue" makes it to not exit in this case
(this is what your code does - it doesn't exit on zero bytes read).

Now, I start fbsplash like this:

mkfifo /tmp/fbsplash.fifo
./busybox fbsplash -s qwe -f /tmp/fbsplash.fifo

and then in another xterm I run this sh script:

{
echo 11
sleep 1
echo 22
sleep 1
} >/tmp/fbsplash.fifo
echo 33 >/tmp/fbsplash.fifo
sleep 1
echo 44 >/tmp/fbsplash.fifo
sleep 1
echo exit >/tmp/fbsplash.fifo

In first xterm I see:

./busybox fbsplash -s qwe -f /tmp/fbsplash.fifo
fbsplash: got '11'
fbsplash: got '22'
fbsplash: got EOF
fbsplash: got EOF
fbsplash: got EOF
fbsplash: got EOF <===== repeats forever
...

Same experiment with strace added, so the result of test read
is visible:

strace -tt -o str.log ./busybox fbsplash -s qwe -f /tmp/fbsplash.fifo

str.log contains this:

11:40:03.193114 open("/tmp/fbsplash.fifo", O_RDONLY|O_LARGEFILE) = 3
11:40:05.743811 ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0xff993954) = -1 EINVAL (Invalid argument)
11:40:05.743942 read(3, "11\n", 1024)   = 3
11:40:05.761084 write(2, "fbsplash: got \'11\'\n", 19) = 19
11:40:05.761209 read(3, "22\n", 1024)   = 3
11:40:06.762729 write(2, "fbsplash: got \'22\'\n", 19) = 19
11:40:06.762861 read(3, "33\n", 1024)   = 3
11:40:07.763125 write(2, "fbsplash: got \'33\'\n", 19) = 19
11:40:07.763242 read(3, "", 1024)       = 0
11:40:07.763334 read(3, "", 1)          = 0
11:40:07.763425 write(2, "fbsplash: got EOF\n", 18) = 18
11:40:07.763531 read(3, "", 1)          = 0
11:40:07.763622 write(2, "fbsplash: got EOF\n", 18) = 18
11:40:07.763721 read(3, "", 1)          = 0
11:40:07.763812 write(2, "fbsplash: got EOF\n", 18) = 18
11:40:07.763915 read(3, "", 1)          = 0
11:40:07.764006 write(2, "fbsplash: got EOF\n", 18) = 18
11:40:07.764105 read(3, "", 1)          = 0
11:40:07.764196 write(2, "fbsplash: got EOF\n", 18) = 18
11:40:07.764294 read(3, "", 1)          = 0
11:40:07.764385 write(2, "fbsplash: got EOF\n", 18) = 18
11:40:07.764483 read(3, "", 1)          = 0
11:40:07.764574 write(2, "fbsplash: got EOF\n", 18) = 18
11:40:07.764672 read(3, "", 1)          = 0
11:40:07.764763 write(2, "fbsplash: got EOF\n", 18) = 18
....

See? As soon as this block finished:

{
echo 11
sleep 1
echo 22
sleep 1
} >/tmp/fbsplash.fifo

and /tmp/fbsplash.fifo is closed on input side, reads
on output side do not block anymore, they return 0
immediately.

Hope it's clearer now.
--
vda
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fbsplash.c
Type: text/x-csrc
Size: 11181 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20080328/2c7fe841/attachment-0002.c 


More information about the busybox mailing list