diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-06-19 13:27:17 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-06-19 13:27:17 +0000 |
commit | cfae5e9b6768208df5e40ccce118ff1734d78361 (patch) | |
tree | c73ec022a1afebaa8002873f48c6c0d2bd1be9d9 /usr.sbin/edquota | |
parent | 8651ffa7b3c3c2a6f3aa62882dd5c03832b5fc4c (diff) |
do not use system() to start $EDITOR, but fake system() ourselves
Diffstat (limited to 'usr.sbin/edquota')
-rw-r--r-- | usr.sbin/edquota/edquota.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/usr.sbin/edquota/edquota.c b/usr.sbin/edquota/edquota.c index e1c8f129f5e..0cf5e1286e6 100644 --- a/usr.sbin/edquota/edquota.c +++ b/usr.sbin/edquota/edquota.c @@ -42,7 +42,7 @@ static char copyright[] = #ifndef lint /*static char sccsid[] = "from: @(#)edquota.c 8.1 (Berkeley) 6/6/93";*/ -static char *rcsid = "$Id: edquota.c,v 1.9 1996/06/06 20:27:49 deraadt Exp $"; +static char *rcsid = "$Id: edquota.c,v 1.10 1996/06/19 13:27:16 deraadt Exp $"; #endif /* not lint */ /* @@ -329,26 +329,27 @@ editit(tmpfile) char *tmpfile; { long omask; - int pid, stat; - extern char *getenv(); - + int pid, stat, xpid; + char *argp[] = {"sh", "-c", NULL, NULL}; register char *ed; char *p; + if ((ed = getenv("EDITOR")) == (char *)0) ed = _PATH_VI; p = (char *)malloc(strlen(ed) + 1 + strlen(tmpfile) + 1); if (!p) return (0); sprintf(p, "%s %s", ed, tmpfile); + argp[2] = p; omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP)); top: if ((pid = fork()) < 0) { extern errno; - free(p); if (errno == EPROCLIM) { fprintf(stderr, "You have too many processes\n"); + free(p); return(0); } if (errno == EAGAIN) { @@ -356,18 +357,24 @@ editit(tmpfile) goto top; } perror("fork"); + free(p); return (0); } if (pid == 0) { sigsetmask(omask); setgid(getgid()); setuid(getuid()); - if (system(p) == -1) - perror(ed); - exit(1); + execv(_PATH_BSHELL, argp); + _exit(127); } free(p); - waitpid(pid, &stat, 0); + for (;;) { + xpid = waitpid(pid, (int *)&stat, WUNTRACED); + if (WIFSTOPPED(stat)) + raise(WSTOPSIG(stat)); + else if (WIFEXITED(stat)) + break; + } sigsetmask(omask); if (!WIFEXITED(stat) || WEXITSTATUS(stat) != 0) return (0); |