summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorRay Lai <ray@cvs.openbsd.org>2007-05-11 02:37:32 +0000
committerRay Lai <ray@cvs.openbsd.org>2007-05-11 02:37:32 +0000
commitf4a2e3c6889aa930bfc14aa068754ebcf1f53572 (patch)
treeb7aa5395798998eed0f148a054e3bf51a839165d /usr.bin
parent30894b282cfd799e5aa6026d5905c7cc41d9049b (diff)
Sync with editit from sendbug.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/cvs/logmsg.c48
1 files changed, 19 insertions, 29 deletions
diff --git a/usr.bin/cvs/logmsg.c b/usr.bin/cvs/logmsg.c
index 9d7b2218610..15c51fde6c7 100644
--- a/usr.bin/cvs/logmsg.c
+++ b/usr.bin/cvs/logmsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: logmsg.c,v 1.39 2007/04/20 08:36:00 xsa Exp $ */
+/* $OpenBSD: logmsg.c,v 1.40 2007/05/11 02:37:31 ray Exp $ */
/*
* Copyright (c) 2007 Joris Vink <joris@openbsd.org>
*
@@ -198,49 +198,39 @@ cvs_logmsg_edit(const char *pathname)
char *argp[] = {"sh", "-c", NULL, NULL}, *p;
sig_t sighup, sigint, sigquit;
pid_t pid;
- int st;
+ int saved_errno, st;
(void)xasprintf(&p, "%s %s", cvs_editor, pathname);
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;
- }
- xfree(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;
xfree(p);
- for (;;) {
- if (waitpid(pid, &st, WUNTRACED) == -1) {
- if (errno != EINTR)
- return (-1);
- } else if (WIFSTOPPED(st))
- raise(WSTOPSIG(st));
- 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);
+ xfree(p);
+ errno = saved_errno;
+ return (-1);
}