From bc9a598f3014f05e5fc086563322e926a36eff6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Tue, 8 Apr 2003 18:04:30 +0000 Subject: 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 --- libutil/pw_util.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/libutil/pw_util.c b/libutil/pw_util.c index 5eb0953..5d831e0 100644 --- a/libutil/pw_util.c +++ b/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; -- cgit v1.2.3