summaryrefslogtreecommitdiff
path: root/regress/bin/ksh
diff options
context:
space:
mode:
authoranton <anton@cvs.openbsd.org>2017-06-17 09:55:02 +0000
committeranton <anton@cvs.openbsd.org>2017-06-17 09:55:02 +0000
commit5edccafdb4140a4354321620f61b9e92b36eb2ae (patch)
tree892365354d2f821cc5952249c3258e1e0868e3dc /regress/bin/ksh
parent17a8cd38de8fa90677edc5f5276db78f966b05b9 (diff)
Pass the command to execute as an argument. Allows the edit program to be
reused.
Diffstat (limited to 'regress/bin/ksh')
-rw-r--r--regress/bin/ksh/edit/edit.c21
-rw-r--r--regress/bin/ksh/edit/subr.sh2
2 files changed, 17 insertions, 6 deletions
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 <poll.h>
#include <signal.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <util.h>
-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: