=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/bc/bc.y,v retrieving revision 1.27 retrieving revision 1.28 diff -c -r1.27 -r1.28 *** src/usr.bin/bc/bc.y 2005/09/18 19:29:41 1.27 --- src/usr.bin/bc/bc.y 2006/03/18 20:44:43 1.28 *************** *** 1,5 **** %{ ! /* $OpenBSD: bc.y,v 1.27 2005/09/18 19:29:41 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek --- 1,5 ---- %{ ! /* $OpenBSD: bc.y,v 1.28 2006/03/18 20:44:43 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek *************** *** 31,41 **** */ #ifndef lint ! static const char rcsid[] = "$OpenBSD: bc.y,v 1.27 2005/09/18 19:29:41 otto Exp $"; #endif /* not lint */ #include #include #include #include #include --- 31,45 ---- */ #ifndef lint ! static const char rcsid[] = "$OpenBSD: bc.y,v 1.28 2006/03/18 20:44:43 otto Exp $"; #endif /* not lint */ + #include + #include + #include #include + #include #include #include #include *************** *** 102,107 **** --- 106,112 ---- static char str_table[UCHAR_MAX][2]; static bool do_fork = true; static u_short var_count; + static pid_t dc; extern char *__progname; *************** *** 277,285 **** } | QUIT { putchar('q'); fflush(stdout); ! exit(0); } | RETURN return_expression { --- 282,293 ---- } | QUIT { + sigset_t mask; + putchar('q'); fflush(stdout); ! sigprocmask(SIG_BLOCK, NULL, &mask); ! sigsuspend(&mask); } | RETURN return_expression { *************** *** 1045,1050 **** --- 1053,1079 ---- return ret; } + /* ARGSUSED */ + void + sigchld(int signo) + { + pid_t pid; + int status; + + for (;;) { + pid = waitpid(dc, &status, WCONTINUED); + if (pid == -1) { + if (errno == EINTR) + continue; + _exit(0); + } + if (WIFEXITED(status) || WIFSIGNALED(status)) + _exit(0); + else + break; + } + } + int main(int argc, char *argv[]) { *************** *** 1085,1100 **** argc -= optind; argv += optind; for (i = 0; i < argc; i++) sargv[sargc++] = argv[i]; if (do_fork) { if (pipe(p) == -1) err(1, "cannot create pipe"); ! ret = fork(); ! if (ret == -1) err(1, "cannot fork"); ! else if (ret == 0) { close(STDOUT_FILENO); dup(p[1]); close(p[0]); --- 1114,1131 ---- argc -= optind; argv += optind; + interactive = isatty(STDIN_FILENO); for (i = 0; i < argc; i++) sargv[sargc++] = argv[i]; if (do_fork) { if (pipe(p) == -1) err(1, "cannot create pipe"); ! dc = fork(); ! if (dc == -1) err(1, "cannot fork"); ! else if (dc != 0) { ! signal(SIGCHLD, sigchld); close(STDOUT_FILENO); dup(p[1]); close(p[0]); *************** *** 1108,1114 **** err(1, "cannot find dc"); } } - signal(SIGINT, abort_line); yywrap(); return yyparse(); } --- 1139,1144 ----