Unsorted

Denys Vlasenko vda.linux at googlemail.com
Sat Sep 29 23:24:51 UTC 2007


On Saturday 29 September 2007 20:37, Vladimir Dronnikov wrote:
> Hello, Denys!
> 
> Why deal with fd #3? Let's go further!
> Please, take a look at new version.

I see you liked it :)

With monor edits:

static char t;

static void quit(int signum)
{
        ioctl(1, KDSETLED, t);
        exit(0);
}

int led_main(int argc, char **argv);
int led_main(int argc, char **argv)
{
        char c;

        // open console
        close(1);
        xmove_fd(xopen("/dev/console", O_RDWR), 1);

        // save current state
        ioctl(1, KDGETLED, &t);

        // treat arg as a file; single '-' means stdin
        if (argc > 1 && argv[1][0] && NOT_LONE_DASH(argv[1]))
                xmove_fd(xopen(argv[1], O_RDONLY), 0);

        // enable CTRL+C
        sig_catch(SIGINT, quit);

        // read and display states
        while (!done && 1 == read(0, &c, 1)) {
                // * means 50 ms delay
                if ('*' == c) { usleep(50000); continue; }
                // . means 200 ms delay
                if ('.' == c) { usleep(200000); continue; }
                // - means 500 ms delay
                if ('-' == c) { usleep(500000); continue; }
                // ^ means rewind
                if ('^' == c) { if (!lseek(0, 0, 0)) continue; }
                // [0..7] means new state
                if (c < '0' || c > '7') continue;
                // set state
                ioctl(1, KDSETLED, c-'0');
        }

        // cleanup
        if (ENABLE_FEATURE_CLEAN_UP) {
                close(0);
                close(1);
        }

        return 0;
}

Well, the question is: what is rationale for inclusion led applet
into busybox. Is there a userbase for it?
--
vda



More information about the busybox mailing list