=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mail/popen.c,v retrieving revision 1.28 retrieving revision 1.29 diff -c -r1.28 -r1.29 *** src/usr.bin/mail/popen.c 2001/11/20 23:19:44 1.28 --- src/usr.bin/mail/popen.c 2001/11/21 15:26:39 1.29 *************** *** 1,4 **** ! /* $OpenBSD: popen.c,v 1.28 2001/11/20 23:19:44 millert Exp $ */ /* $NetBSD: popen.c,v 1.6 1997/05/13 06:48:42 mikel Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: popen.c,v 1.29 2001/11/21 15:26:39 millert Exp $ */ /* $NetBSD: popen.c,v 1.6 1997/05/13 06:48:42 mikel Exp $ */ /* *************** *** 36,44 **** #ifndef lint #if 0 ! static char sccsid[] = "@(#)popen.c 8.1 (Berkeley) 6/6/93"; #else ! static char rcsid[] = "$OpenBSD: popen.c,v 1.28 2001/11/20 23:19:44 millert Exp $"; #endif #endif /* not lint */ --- 36,44 ---- #ifndef lint #if 0 ! static const char sccsid[] = "@(#)popen.c 8.1 (Berkeley) 6/6/93"; #else ! static const char rcsid[] = "$OpenBSD: popen.c,v 1.29 2001/11/21 15:26:39 millert Exp $"; #endif #endif /* not lint */ *************** *** 46,56 **** #include #include #include - #ifdef __STDC__ #include - #else - #include - #endif #include "extern.h" #define READ 0 --- 46,52 ---- *************** *** 59,85 **** struct fp { FILE *fp; int pipe; ! int pid; struct fp *link; }; static struct fp *fp_head; struct child { ! int pid; char done; char free; int status; struct child *link; }; static struct child *child, *child_freelist = NULL; - static struct child *findchild __P((int, int)); - static void delchild __P((struct child *)); - static int file_pid __P((FILE *)); - static int handle_spool_locks __P((int)); FILE * ! Fopen(file, mode) ! char *file, *mode; { FILE *fp; --- 55,81 ---- struct fp { FILE *fp; int pipe; ! pid_t pid; struct fp *link; }; static struct fp *fp_head; struct child { ! pid_t pid; char done; char free; int status; struct child *link; }; static struct child *child, *child_freelist = NULL; + static struct child *findchild(pid_t, int); + static void delchild(struct child *); + static pid_t file_pid(FILE *); + static int handle_spool_locks(int); + FILE * ! Fopen(char *file, char *mode) { FILE *fp; *************** *** 91,99 **** } FILE * ! Fdopen(fd, mode) ! int fd; ! char *mode; { FILE *fp; --- 87,93 ---- } FILE * ! Fdopen(int fd, char *mode) { FILE *fp; *************** *** 105,125 **** } int ! Fclose(fp) ! FILE *fp; { unregister_file(fp); return(fclose(fp)); } FILE * ! Popen(cmd, mode) ! char *cmd; ! char *mode; { int p[2]; int myside, hisside, fd0, fd1; ! int pid; sigset_t nset; FILE *fp; --- 99,117 ---- } int ! Fclose(FILE *fp) { + unregister_file(fp); return(fclose(fp)); } FILE * ! Popen(char *cmd, char *mode) { int p[2]; int myside, hisside, fd0, fd1; ! pid_t pid; sigset_t nset; FILE *fp; *************** *** 156,163 **** } int ! Pclose(ptr) ! FILE *ptr; { int i; sigset_t nset, oset; --- 148,154 ---- } int ! Pclose(FILE *ptr) { int i; sigset_t nset, oset; *************** *** 175,181 **** } void ! close_all_files() { while (fp_head) --- 166,172 ---- } void ! close_all_files(void) { while (fp_head) *************** *** 186,194 **** } void ! register_file(fp, pipe, pid) ! FILE *fp; ! int pipe, pid; { struct fp *fpp; --- 177,183 ---- } void ! register_file(FILE *fp, int pipe, pid_t pid) { struct fp *fpp; *************** *** 202,209 **** } void ! unregister_file(fp) ! FILE *fp; { struct fp **pp, *p; --- 191,197 ---- } void ! unregister_file(FILE *fp) { struct fp **pp, *p; *************** *** 216,224 **** errx(1, "Invalid file pointer"); } ! static int ! file_pid(fp) ! FILE *fp; { struct fp *p; --- 204,211 ---- errx(1, "Invalid file pointer"); } ! static pid_t ! file_pid(FILE *fp) { struct fp *p; *************** *** 237,250 **** * "nset" contains the signals to ignore in the new process. * SIGINT is enabled unless it's in "nset". */ ! int ! start_commandv(cmd, nset, infd, outfd, args) ! char *cmd; ! sigset_t *nset; ! int infd, outfd; ! va_list args; { ! int pid; if ((pid = fork()) < 0) { warn("fork"); --- 224,233 ---- * "nset" contains the signals to ignore in the new process. * SIGINT is enabled unless it's in "nset". */ ! pid_t ! start_commandv(char *cmd, sigset_t *nset, int infd, int outfd, va_list args) { ! pid_t pid; if ((pid = fork()) < 0) { warn("fork"); *************** *** 266,290 **** } int - #ifdef __STDC__ run_command(char *cmd, sigset_t *nset, int infd, int outfd, ...) - #else - run_command(cmd, nset, infd, outfd, va_alist) - char *cmd; - sigset_t *nset; - int infd; - int outfd; - va_dcl - #endif { ! int pid; va_list args; - #ifdef __STDC__ va_start(args, outfd); - #else - va_start(args); - #endif pid = start_commandv(cmd, nset, infd, outfd, args); va_end(args); if (pid < 0) --- 249,260 ---- } int run_command(char *cmd, sigset_t *nset, int infd, int outfd, ...) { ! pid_t pid; va_list args; va_start(args, outfd); pid = start_commandv(cmd, nset, infd, outfd, args); va_end(args); if (pid < 0) *************** *** 293,326 **** } int - #ifdef __STDC__ start_command(char *cmd, sigset_t *nset, int infd, int outfd, ...) - #else - start_command(cmd, nset, infd, outfd, va_alist) - char *cmd; - sigset_t *nset; - int infd; - int outfd; - va_dcl - #endif { va_list args; int r; - #ifdef __STDC__ va_start(args, outfd); - #else - va_start(args); - #endif r = start_commandv(cmd, nset, infd, outfd, args); va_end(args); return(r); } void ! prepare_child(nset, infd, outfd) ! sigset_t *nset; ! int infd, outfd; { int i; sigset_t eset; --- 263,281 ---- } int start_command(char *cmd, sigset_t *nset, int infd, int outfd, ...) { va_list args; int r; va_start(args, outfd); r = start_commandv(cmd, nset, infd, outfd, args); va_end(args); return(r); } void ! prepare_child(sigset_t *nset, int infd, int outfd) { int i; sigset_t eset; *************** *** 352,359 **** } int ! wait_command(pid) ! int pid; { if (wait_child(pid) < 0) { --- 307,313 ---- } int ! wait_command(pid_t pid) { if (wait_child(pid) < 0) { *************** *** 364,372 **** } static struct child * ! findchild(pid, dont_alloc) ! int pid; ! int dont_alloc; { struct child **cpp; --- 318,324 ---- } static struct child * ! findchild(pid_t pid, int dont_alloc) { struct child **cpp; *************** *** 389,396 **** } static void ! delchild(cp) ! struct child *cp; { struct child **cpp; --- 341,347 ---- } static void ! delchild(struct child *cp) { struct child **cpp; *************** *** 402,411 **** } void ! sigchild(signo) ! int signo; { ! int pid; int status; struct child *cp; int save_errno = errno; --- 353,361 ---- } void ! sigchild(int signo) { ! pid_t pid; int status; struct child *cp; int save_errno = errno; *************** *** 431,438 **** * Wait for a specific child to die. */ int ! wait_child(pid) ! int pid; { struct child *cp; sigset_t nset, oset; --- 381,387 ---- * Wait for a specific child to die. */ int ! wait_child(pid_t pid) { struct child *cp; sigset_t nset, oset; *************** *** 464,471 **** * Mark a child as don't care. */ void ! free_child(pid) ! int pid; { struct child *cp; sigset_t nset, oset; --- 413,419 ---- * Mark a child as don't care. */ void ! free_child(pid_t pid) { struct child *cp; sigset_t nset, oset; *************** *** 487,497 **** * Returns 1 for success, 0 for failure, -1 for bad usage. */ static int ! handle_spool_locks(action) ! int action; { static FILE *lockfp = NULL; ! static int lock_pid; if (action == 0) { /* Clear the lock */ --- 435,444 ---- * Returns 1 for success, 0 for failure, -1 for bad usage. */ static int ! handle_spool_locks(int action) { static FILE *lockfp = NULL; ! static pid_t lock_pid; if (action == 0) { /* Clear the lock */ *************** *** 535,547 **** } int ! spool_lock() { return(handle_spool_locks(1)); } int ! spool_unlock() { return(handle_spool_locks(0)); } --- 482,496 ---- } int ! spool_lock(void) { + return(handle_spool_locks(1)); } int ! spool_unlock(void) { + return(handle_spool_locks(0)); }