diff options
author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2003-04-08 18:04:30 +0000 |
---|---|---|
committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2003-04-08 18:04:30 +0000 |
commit | c794881f8c9ac331f3c519f2bdad4fb880f28200 (patch) | |
tree | fdf0a825829ac94584e86407a71623a47633a1f3 /lib/libutil/pw_util.c | |
parent | 71ec78e34025ca9b565d7c88675af88aaa2018ce (diff) | |
download | src-c794881f8c9ac331f3c519f2bdad4fb880f28200.tar.gz src-c794881f8c9ac331f3c519f2bdad4fb880f28200.zip |
Band-aid for the "^C kills the editor" problem. I haven't yet found the
proper way to fix this. The way this works is to prepend "exec " to
the editor command to eliminate the "shell in the middle" which prevents
us from properly reawakening the editor after a SIGTSTP.
PR: bin/50679
Notes
Notes:
svn path=/head/; revision=113265
Diffstat (limited to 'lib/libutil/pw_util.c')
-rw-r--r-- | lib/libutil/pw_util.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/lib/libutil/pw_util.c b/lib/libutil/pw_util.c index 5eb09535c709..5d831e04ae4e 100644 --- a/lib/libutil/pw_util.c +++ b/lib/libutil/pw_util.c @@ -290,7 +290,6 @@ pw_edit(int notsetuid) struct stat st1, st2; const char *editor; char *editcmd; - int editcmdlen; int pstat; if ((editor = getenv("EDITOR")) == NULL) @@ -306,14 +305,8 @@ pw_edit(int notsetuid) (void)setgid(getgid()); (void)setuid(getuid()); } - if ((editcmdlen = sysconf(_SC_ARG_MAX) - 6) <= 0 || - (editcmd = malloc(editcmdlen)) == NULL) + if (asprintf(&editcmd, "exec %s %s", editor, tempname) == NULL) _exit(EXIT_FAILURE); - if (snprintf(editcmd, editcmdlen, "%s %s", - editor, tempname) >= editcmdlen) { - free(editcmd); /* pedantry */ - _exit(EXIT_FAILURE); - } errno = 0; execl(_PATH_BSHELL, "sh", "-c", editcmd, NULL); free(editcmd); @@ -322,13 +315,16 @@ pw_edit(int notsetuid) /* parent */ break; } + setpgid(editpid, editpid); + tcsetpgrp(1, editpid); for (;;) { - editpid = waitpid(editpid, &pstat, WUNTRACED); - if (editpid == -1) { + if (waitpid(editpid, &pstat, WUNTRACED) == -1) { unlink(tempname); return (-1); } else if (WIFSTOPPED(pstat)) { raise(WSTOPSIG(pstat)); + tcsetpgrp(1, getpgid(editpid)); + kill(editpid, SIGCONT); } else if (WIFEXITED(pstat) && WEXITSTATUS(pstat) == 0) { editpid = -1; break; |