diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2007-05-13 14:19:19 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2007-05-13 14:19:19 +0000 |
commit | e5696904d6bb8a5740d08c3b8542c670220bc601 (patch) | |
tree | 3a07e7c190e43b56555e0414f9fea89ca56198be /sbin | |
parent | 01b5a6ccce89c6a4e4b4bd48f85a0317de336a2a (diff) |
Sync editit() with sendbug.
OK krw@.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/disklabel/disklabel.c | 54 |
1 files changed, 26 insertions, 28 deletions
diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c index c1fdd91b5c1..047a2ac9e25 100644 --- a/sbin/disklabel/disklabel.c +++ b/sbin/disklabel/disklabel.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.c,v 1.107 2007/04/26 22:42:11 krw Exp $ */ +/* $OpenBSD: disklabel.c,v 1.108 2007/05/13 14:19:18 ray Exp $ */ /* * Copyright (c) 1987, 1993 @@ -39,7 +39,7 @@ static const char copyright[] = #endif /* not lint */ #ifndef lint -static const char rcsid[] = "$OpenBSD: disklabel.c,v 1.107 2007/04/26 22:42:11 krw Exp $"; +static const char rcsid[] = "$OpenBSD: disklabel.c,v 1.108 2007/05/13 14:19:18 ray Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -1157,13 +1157,19 @@ edit(struct disklabel *lp, int f) return (1); } +/* + * Execute an editor on the specified pathname, which is interpreted + * from the shell. This means flags may be included. + * + * Returns -1 on error, or the exit value on success. + */ int editit(const char *pathname) { char *argp[] = {"sh", "-c", NULL, NULL}, *ed, *p; sig_t sighup, sigint, sigquit; pid_t pid; - int st; + int saved_errno, st; ed = getenv("VISUAL"); if (ed == NULL || ed[0] == '\0') @@ -1174,44 +1180,36 @@ editit(const char *pathname) return (-1); argp[2] = p; - top: sighup = signal(SIGHUP, SIG_IGN); sigint = signal(SIGINT, SIG_IGN); sigquit = signal(SIGQUIT, SIG_IGN); - if ((pid = fork()) == -1) { - int saved_errno = errno; - - (void)signal(SIGHUP, sighup); - (void)signal(SIGINT, sigint); - (void)signal(SIGQUIT, sigquit); - if (saved_errno == EAGAIN) { - sleep(1); - goto top; - } - free(p); - errno = saved_errno; - return (-1); - } + if ((pid = fork()) == -1) + goto fail; if (pid == 0) { execv(_PATH_BSHELL, argp); _exit(127); } + while (waitpid(pid, &st, 0) == -1) + if (errno != EINTR) + goto fail; free(p); - for (;;) { - if (waitpid(pid, &st, 0) == -1) { - if (errno != EINTR) - return (-1); - } else - break; - } (void)signal(SIGHUP, sighup); (void)signal(SIGINT, sigint); (void)signal(SIGQUIT, sigquit); - if (!WIFEXITED(st) || WEXITSTATUS(st) != 0) { - errno = ECHILD; + if (!WIFEXITED(st)) { + errno = EINTR; return (-1); } - return (0); + return (WEXITSTATUS(st)); + + fail: + saved_errno = errno; + (void)signal(SIGHUP, sighup); + (void)signal(SIGINT, sigint); + (void)signal(SIGQUIT, sigquit); + free(p); + errno = saved_errno; + return (-1); } char * |