new applet: script

Pascal Bellard pascal.bellard at ads-lu.com
Wed Feb 27 17:58:58 UTC 2008


Next version, 2 processes, vfork only, no signals.

> On Tuesday 26 February 2008 23:35, Pascal Bellard wrote:
>> A new version. Simpler and ... less buggy!
>
> +#include <getopt.h>
>
> Not needed now.
>
> +       if (opt & 8) {
> +               qflg++;
> +       }
>
> Why not use that bit in opt as a flag then?
>
> +       signal(SIGCHLD, finish); /* catch SIGTERM of children */
>
> First, function name is better be "sigchld_handler" or something like
> that.
> Second, it does not "catch SIGTERM of children". It
> signals that child exited (for whatever reason).
>
> +       tcgetattr(0, &tt);
> +       ioctl(0, TIOCGWINSZ, (char *)&win);
>
> And if these fail?...
>
> +                /* child1: link pty master output to mainshell stdout and
> file */
>
> What does it mean "link"? As in "ln -s"?
> "copy" is better term for what we do here.
>
> +                /* endless copy: stdin will not be closed */
>
> Why? It can be closed easily: imagine "script .... <file"
>
> +                       close(0);
> +                       fdscript = xopen(fname, mode);
> fdscript will be == 0. Always. You can use that.
> +                       /* copy until pty is close, i.e. child2 exits */
> +                       while ((count = read(pty, buf, sizeof(buf))) > 0)
> {
> +                               write(1, buf, count);
> +                               write(fdscript, buf, count);
> No handling of short writes here.
> +                               if (fflg) {
> +                                       fsync(fdscript);
> +                               }
> +                       }
> +                       done();
>
>
>
> +        execl(shell, strrchr(shell, '/') + 1, shell_arg, cflg, NULL);
> Theoretically, $SHELL can have no '/'...
> +        bb_perror_msg_and_die(shell);
> ... but can have '%'!

What can I done with '%' ?

>
>
> I edited script.c - see attached file.
>
> My biggest concern is that it is not NOMMU-capable because you use fork().
> It's better to combine "parent" and "child1" in one process, then
> vfork() will suffice for child2 and applet will work on NOMMU.
>
> Will try to do it.
> --
> vda
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: busybox-20080227-APPLET-SCRIPT.u
Type: application/octet-stream
Size: 9891 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20080227/658a97fc/attachment-0002.obj 


More information about the busybox mailing list