#include #include #include #include #include #include #include #include #include int main() { const char *editor = "/usr/bin/vi"; const char *name; pid_t pid, caught; int sig; int st; if (getenv("EDITOR") != NULL) editor = getenv("EDITOR"); if ((name = strrchr(editor, '/')) != NULL) ++name; else name = editor; if ((pid = fork()) < 0) err(1, "fork"); if (pid == 0) return execlp(editor, name, NULL); #if 0 sleep(1); killpg(getpgrp(), SIGSTOP); #endif for (;;) { caught = waitpid(pid, &st, WUNTRACED); warnx("waitpid returned %d\n", caught); errno = WEXITSTATUS(st); if (caught == -1) return 1; else if (WIFSTOPPED(st)) { sig = WSTOPSIG(st); warnx("WSTOPSIG(%d) = %d\n", st, sig); sig = SIGSTOP; raise(sig); warnx("after raise(%d)\n", sig); } else if (WIFEXITED(st)) return errno; else return 1; } return 0; }