On Wednesday 26 March 2008 15:24, James Simmons wrote:
> 
> This patch allows openvt to wait for command completion.
> 
> 
> diff -urwN busybox.orig/console-tools/openvt.c busybox/console-tools/openvt.c
> --- busybox.orig/console-tools/openvt.c       2008-03-26 09:51:27.000000000 
> -0400
> +++ busybox/console-tools/openvt.c    2008-03-26 10:10:50.000000000 -0400
> @@ -16,12 +16,16 @@
>  int openvt_main(int argc, char **argv)
>  {
>       char vtname[sizeof(VC_FORMAT) + 2];
> +     pid_t pid;
> +     int flags;
> +
> +     flags = getopt32(argc, argv, "w");

Does not compile: getopt32() does not take argc, only argv.

Also, you need "+w" - you must not eat -options in
"COMMAND [ARGS...]" part. Try "openvt -w ls -l"

>  
>       if (argc < 3)
>               bb_show_usage();
>  
>       /* check for illegal vt number: < 1 or > 63 */
> -     sprintf(vtname, VC_FORMAT, (int)xatou_range(argv[1], 1, 63));
> +     sprintf(vtname, VC_FORMAT, (int)xatou_range(argv[optind], 1, 63));
>  
>       bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS, argv);
>       /* grab new one */
> @@ -30,7 +34,13 @@
>       xdup2(0, STDOUT_FILENO);
>       xdup2(0, STDERR_FILENO);
>  
> +     if (flags & 1) {
> +             pid = xspawn(&argv[argc-1]);

Bug.

Strace of "./busybox openvt -w 20 ls true":

25653 vfork()                           = 25659
25659 execve("/root/bin/true", ["true"], [/* 32 vars */]) = -1 ENOENT (No such 
file or directory)
                        ^^^^


> +             flags = wait4pid(pid);
> +     } else {
>       argv += 2;
>       BB_EXECVP(argv[0], argv);
> -     _exit(1);

Indentation damage

> +             flags = EXIT_SUCCESS;
> +     }
> +     _exit(flags);
>  }
> diff -urwN busybox.orig/include/usage.h busybox/include/usage.h
> --- busybox.orig/include/usage.h      2008-03-26 09:52:06.000000000 -0400
> +++ busybox/include/usage.h   2008-03-26 10:08:28.000000000 -0400
> @@ -2816,9 +2816,11 @@
>         "to standard output. With no FILE or when FILE is -, read standard 
> input."
>  
>  #define openvt_trivial_usage \
> -       "VTNUM COMMAND [ARGS...]"
> +       "[-w] VTNUM COMMAND [ARGS...]"
>  #define openvt_full_usage \
> -       "Start a command on a new virtual terminal"
> +       "Start a command on a new virtual terminal\n" \
> +       "\nOptions:" \
> +       "\n   -w      wait for command to complete" \

All other help texts are formatted differently.
--
vda
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to