=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mail/popen.c,v retrieving revision 1.5 retrieving revision 1.6 diff -c -r1.5 -r1.6 *** src/usr.bin/mail/popen.c 1997/05/30 08:51:43 1.5 --- src/usr.bin/mail/popen.c 1997/07/13 21:21:15 1.6 *************** *** 1,5 **** ! /* $OpenBSD: popen.c,v 1.5 1997/05/30 08:51:43 deraadt Exp $ */ ! /* $NetBSD: popen.c,v 1.4 1996/06/08 19:48:35 christos Exp $ */ /* * Copyright (c) 1980, 1993 --- 1,5 ---- ! /* $OpenBSD: popen.c,v 1.6 1997/07/13 21:21:15 millert Exp $ */ ! /* $NetBSD: popen.c,v 1.6 1997/05/13 06:48:42 mikel Exp $ */ /* * Copyright (c) 1980, 1993 *************** *** 38,44 **** #if 0 static char sccsid[] = "@(#)popen.c 8.1 (Berkeley) 6/6/93"; #else ! static char rcsid[] = "$OpenBSD: popen.c,v 1.5 1997/05/30 08:51:43 deraadt Exp $"; #endif #endif /* not lint */ --- 38,44 ---- #if 0 static char sccsid[] = "@(#)popen.c 8.1 (Berkeley) 6/6/93"; #else ! static char rcsid[] = "$OpenBSD: popen.c,v 1.6 1997/07/13 21:21:15 millert Exp $"; #endif #endif /* not lint */ *************** *** 81,87 **** register_file(fp, 0, 0); (void) fcntl(fileno(fp), F_SETFD, 1); } ! return fp; } FILE * --- 81,87 ---- register_file(fp, 0, 0); (void) fcntl(fileno(fp), F_SETFD, 1); } ! return(fp); } FILE * *************** *** 95,101 **** register_file(fp, 0, 0); (void) fcntl(fileno(fp), F_SETFD, 1); } ! return fp; } int --- 95,101 ---- register_file(fp, 0, 0); (void) fcntl(fileno(fp), F_SETFD, 1); } ! return(fp); } int *************** *** 103,109 **** FILE *fp; { unregister_file(fp); ! return fclose(fp); } FILE * --- 103,109 ---- FILE *fp; { unregister_file(fp); ! return(fclose(fp)); } FILE * *************** *** 118,124 **** FILE *fp; if (pipe(p) < 0) ! return NULL; (void) fcntl(p[READ], F_SETFD, 1); (void) fcntl(p[WRITE], F_SETFD, 1); if (*mode == 'r') { --- 118,124 ---- FILE *fp; if (pipe(p) < 0) ! return(NULL); (void) fcntl(p[READ], F_SETFD, 1); (void) fcntl(p[WRITE], F_SETFD, 1); if (*mode == 'r') { *************** *** 132,145 **** } sigemptyset(&nset); if ((pid = start_command(cmd, &nset, fd0, fd1, NOSTR, NOSTR, NOSTR)) < 0) { ! close(p[READ]); ! close(p[WRITE]); ! return NULL; } ! (void) close(hisside); if ((fp = fdopen(myside, mode)) != NULL) register_file(fp, 1, pid); ! return fp; } int --- 132,145 ---- } sigemptyset(&nset); if ((pid = start_command(cmd, &nset, fd0, fd1, NOSTR, NOSTR, NOSTR)) < 0) { ! (void)close(p[READ]); ! (void)close(p[WRITE]); ! return(NULL); } ! (void)close(hisside); if ((fp = fdopen(myside, mode)) != NULL) register_file(fp, 1, pid); ! return(fp); } int *************** *** 151,164 **** i = file_pid(ptr); unregister_file(ptr); ! (void) fclose(ptr); sigemptyset(&nset); sigaddset(&nset, SIGINT); sigaddset(&nset, SIGHUP); sigprocmask(SIG_BLOCK, &nset, &oset); i = wait_child(i); sigprocmask(SIG_SETMASK, &oset, NULL); ! return i; } void --- 151,164 ---- i = file_pid(ptr); unregister_file(ptr); ! (void)fclose(ptr); sigemptyset(&nset); sigaddset(&nset, SIGINT); sigaddset(&nset, SIGHUP); sigprocmask(SIG_BLOCK, &nset, &oset); i = wait_child(i); sigprocmask(SIG_SETMASK, &oset, NULL); ! return(i); } void *************** *** 167,175 **** while (fp_head) if (fp_head->pipe) ! (void) Pclose(fp_head->fp); else ! (void) Fclose(fp_head->fp); } void --- 167,175 ---- while (fp_head) if (fp_head->pipe) ! (void)Pclose(fp_head->fp); else ! (void)Fclose(fp_head->fp); } void *************** *** 179,185 **** { struct fp *fpp; ! if ((fpp = (struct fp *) malloc(sizeof *fpp)) == NULL) panic("Out of memory"); fpp->fp = fp; fpp->pipe = pipe; --- 179,185 ---- { struct fp *fpp; ! if ((fpp = (struct fp *) malloc(sizeof(*fpp))) == NULL) panic("Out of memory"); fpp->fp = fp; fpp->pipe = pipe; *************** *** 211,217 **** for (p = fp_head; p; p = p->link) if (p->fp == fp) ! return (p->pid); panic("Invalid file pointer"); /*NOTREACHED*/ } --- 211,217 ---- for (p = fp_head; p; p = p->link) if (p->fp == fp) ! return(p->pid); panic("Invalid file pointer"); /*NOTREACHED*/ } *************** *** 234,241 **** int pid; if ((pid = start_command(cmd, mask, infd, outfd, a0, a1, a2)) < 0) ! return -1; ! return wait_command(pid); } /*VARARGS4*/ --- 234,241 ---- int pid; if ((pid = start_command(cmd, mask, infd, outfd, a0, a1, a2)) < 0) ! return(-1); ! return(wait_command(pid)); } /*VARARGS4*/ *************** *** 249,260 **** int pid; if ((pid = vfork()) < 0) { ! perror("fork"); ! return -1; } if (pid == 0) { char *argv[100]; ! int i = getrawlist(cmd, argv, sizeof argv / sizeof *argv); if ((argv[i++] = a0) != NOSTR && (argv[i++] = a1) != NOSTR && --- 249,260 ---- int pid; if ((pid = vfork()) < 0) { ! warn("fork"); ! return(-1); } if (pid == 0) { char *argv[100]; ! int i = getrawlist(cmd, argv, sizeof(argv)/ sizeof(*argv)); if ((argv[i++] = a0) != NOSTR && (argv[i++] = a1) != NOSTR && *************** *** 262,271 **** argv[i] = NOSTR; prepare_child(mask, infd, outfd); execvp(argv[0], argv); ! perror(argv[0]); _exit(1); } ! return pid; } void --- 262,271 ---- argv[i] = NOSTR; prepare_child(mask, infd, outfd); execvp(argv[0], argv); ! warn(argv[0]); _exit(1); } ! return(pid); } void *************** *** 284,296 **** dup2(infd, 0); if (outfd >= 0) dup2(outfd, 1); ! if (nset) { for (i = 1; i < NSIG; i++) if (sigismember(nset, i)) (void) signal(i, SIG_IGN); - if (!sigismember(nset, SIGINT)) - (void) signal(SIGINT, SIG_DFL); } sigfillset(&fset); (void) sigprocmask(SIG_UNBLOCK, &fset, NULL); } --- 284,298 ---- dup2(infd, 0); if (outfd >= 0) dup2(outfd, 1); ! if (nset == NULL) ! return; ! if (nset != NULL) { for (i = 1; i < NSIG; i++) if (sigismember(nset, i)) (void) signal(i, SIG_IGN); } + if (nset == NULL || !sigismember(nset, SIGINT)) + (void) signal(SIGINT, SIG_DFL); sigfillset(&fset); (void) sigprocmask(SIG_UNBLOCK, &fset, NULL); } *************** *** 301,310 **** { if (wait_child(pid) < 0) { ! printf("Fatal error in process.\n"); ! return -1; } ! return 0; } static struct child * --- 303,312 ---- { if (wait_child(pid) < 0) { ! puts("Fatal error in process."); ! return(-1); } ! return(0); } static struct child * *************** *** 317,328 **** cpp = &(*cpp)->link) ; if (*cpp == NULL) { ! *cpp = (struct child *) malloc(sizeof (struct child)); (*cpp)->pid = pid; (*cpp)->done = (*cpp)->free = 0; (*cpp)->link = NULL; } ! return *cpp; } static void --- 319,330 ---- cpp = &(*cpp)->link) ; if (*cpp == NULL) { ! *cpp = (struct child *) malloc(sizeof(struct child)); (*cpp)->pid = pid; (*cpp)->done = (*cpp)->free = 0; (*cpp)->link = NULL; } ! return(*cpp); } static void *************** *** 377,383 **** wait_status = cp->status; delchild(cp); sigprocmask(SIG_SETMASK, &oset, NULL); ! return wait_status.w_status ? -1 : 0; } /* --- 379,385 ---- wait_status = cp->status; delchild(cp); sigprocmask(SIG_SETMASK, &oset, NULL); ! return(wait_status.w_status ? -1 : 0); } /* *************** *** 415,426 **** if (action == 0) { /* Clear the lock */ if (lockfp == NULL) { ! fprintf(stderr, ! "handle_spool_locks: no spool lock to remove.\n"); ! return (-1); } (void)kill(lock_pid, SIGTERM); ! Pclose(lockfp); lockfp = NULL; } else if (action == 1) { /* Create the lock */ --- 417,428 ---- if (action == 0) { /* Clear the lock */ if (lockfp == NULL) { ! fputs("handle_spool_locks: no spool lock to remove.\n", ! stderr); ! return(-1); } (void)kill(lock_pid, SIGTERM); ! (void)Pclose(lockfp); lockfp = NULL; } else if (action == 1) { /* Create the lock */ *************** *** 430,436 **** if ((lockfp = Popen(cmd, "r")) == NULL || getc(lockfp) != '1') { lockfp = NULL; free(cmd); ! return (0); } lock_pid = fp_head->pid; /* new entries added at head */ --- 432,438 ---- if ((lockfp = Popen(cmd, "r")) == NULL || getc(lockfp) != '1') { lockfp = NULL; free(cmd); ! return(0); } lock_pid = fp_head->pid; /* new entries added at head */ *************** *** 438,447 **** } else { fprintf(stderr, "handle_spool_locks: unknown action %d\n", action); ! return (-1); } ! return (1); } int --- 440,449 ---- } else { fprintf(stderr, "handle_spool_locks: unknown action %d\n", action); ! return(-1); } ! return(1); } int