From: anton Date: Sat, 17 Jun 2017 09:55:01 +0000 (+0000) Subject: Pass the command to execute as an argument. Allows the edit program to be X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=78f99cd3d554e7edade210de5a224e39907d6848;p=openbsd Pass the command to execute as an argument. Allows the edit program to be reused. --- diff --git a/regress/bin/ksh/edit/edit.c b/regress/bin/ksh/edit/edit.c index 2c8ec4936e8..0e707af294c 100644 --- a/regress/bin/ksh/edit/edit.c +++ b/regress/bin/ksh/edit/edit.c @@ -19,17 +19,19 @@ #include #include #include +#include #include #include #include #include -static void sigchld(int); +static void sigchld(int); +static void __dead usage(void); static volatile sig_atomic_t gotsigchld; int -main(void) +main(int argc, char *argv[]) { char in[BUFSIZ], out[BUFSIZ]; struct pollfd pfd; @@ -39,6 +41,9 @@ main(void) size_t nin, nread, nwrite; int nready, ptyfd; + if (argc < 2) + usage(); + nin = 0; for (;;) { if (nin == sizeof(in)) @@ -64,9 +69,8 @@ main(void) if (pid == -1) err(1, "forkpty"); if (pid == 0) { - /* Run restricted shell ignoring ~/.profile. */ - execlp("ksh", "ksh", "-r", NULL); - err(1, "ksh"); + execvp(argv[1], &argv[1]); + err(1, "%s", argv[1]); } nread = nwrite = 0; @@ -116,3 +120,10 @@ sigchld(int sig) { gotsigchld = sig == SIGCHLD; } + +static void __dead +usage(void) +{ + fprintf(stderr, "usage: edit command [args]\n"); + exit(1); +} diff --git a/regress/bin/ksh/edit/subr.sh b/regress/bin/ksh/edit/subr.sh index 685f4d99031..fb027c4e885 100644 --- a/regress/bin/ksh/edit/subr.sh +++ b/regress/bin/ksh/edit/subr.sh @@ -16,7 +16,7 @@ testseq() { stdin=$1 exp=$(echo "$2") - act=$(echo -n "$stdin" | ./edit) + act=$(echo -n "$stdin" | ./edit ksh -r) [ "$exp" = "$act" ] && return 0 echo input: