you need to increment try each time through the loop.
this works for me:
#include <u.h>
#include <libc.h>

void
fu(void)
{
        int rd, try;
        char buf[1024];

        for(try=0; try < 2; try++){
                alarm(2 * 1000);
                rd = read(0, buf, 1024);
                alarm(0);
                if(rd > 0) {
                        write(1, buf, rd);
                        break;
                }
        }
}

void
main(void)
{
        fu();
        exits("");
}

Reply via email to