Pass the command to execute as an argument. Allows the edit program to be
authoranton <anton@openbsd.org>
Sat, 17 Jun 2017 09:55:01 +0000 (09:55 +0000)
committeranton <anton@openbsd.org>
Sat, 17 Jun 2017 09:55:01 +0000 (09:55 +0000)
reused.

regress/bin/ksh/edit/edit.c
regress/bin/ksh/edit/subr.sh

index 2c8ec49..0e707af 100644 (file)
 #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);
+}
index 685f4d9..fb027c4 100644 (file)
@@ -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: