=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mail/popen.c,v retrieving revision 1.28 retrieving revision 1.29 diff -u -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 +1,4 @@ -/* $OpenBSD: popen.c,v 1.28 2001/11/20 23:19:44 millert Exp $ */ +/* $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,9 +36,9 @@ #ifndef lint #if 0 -static char sccsid[] = "@(#)popen.c 8.1 (Berkeley) 6/6/93"; +static const 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 $"; +static const char rcsid[] = "$OpenBSD: popen.c,v 1.29 2001/11/21 15:26:39 millert Exp $"; #endif #endif /* not lint */ @@ -46,11 +46,7 @@ #include #include #include -#ifdef __STDC__ #include -#else -#include -#endif #include "extern.h" #define READ 0 @@ -59,27 +55,27 @@ struct fp { FILE *fp; int pipe; - int pid; + pid_t pid; struct fp *link; }; static struct fp *fp_head; struct child { - int pid; + pid_t 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)); +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(file, mode) - char *file, *mode; +Fopen(char *file, char *mode) { FILE *fp; @@ -91,9 +87,7 @@ } FILE * -Fdopen(fd, mode) - int fd; - char *mode; +Fdopen(int fd, char *mode) { FILE *fp; @@ -105,21 +99,19 @@ } int -Fclose(fp) - FILE *fp; +Fclose(FILE *fp) { + unregister_file(fp); return(fclose(fp)); } FILE * -Popen(cmd, mode) - char *cmd; - char *mode; +Popen(char *cmd, char *mode) { int p[2]; int myside, hisside, fd0, fd1; - int pid; + pid_t pid; sigset_t nset; FILE *fp; @@ -156,8 +148,7 @@ } int -Pclose(ptr) - FILE *ptr; +Pclose(FILE *ptr) { int i; sigset_t nset, oset; @@ -175,7 +166,7 @@ } void -close_all_files() +close_all_files(void) { while (fp_head) @@ -186,9 +177,7 @@ } void -register_file(fp, pipe, pid) - FILE *fp; - int pipe, pid; +register_file(FILE *fp, int pipe, pid_t pid) { struct fp *fpp; @@ -202,8 +191,7 @@ } void -unregister_file(fp) - FILE *fp; +unregister_file(FILE *fp) { struct fp **pp, *p; @@ -216,9 +204,8 @@ errx(1, "Invalid file pointer"); } -static int -file_pid(fp) - FILE *fp; +static pid_t +file_pid(FILE *fp) { struct fp *p; @@ -237,14 +224,10 @@ * "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; +pid_t +start_commandv(char *cmd, sigset_t *nset, int infd, int outfd, va_list args) { - int pid; + pid_t pid; if ((pid = fork()) < 0) { warn("fork"); @@ -266,25 +249,12 @@ } 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; + pid_t 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) @@ -293,34 +263,19 @@ } 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; +prepare_child(sigset_t *nset, int infd, int outfd) { int i; sigset_t eset; @@ -352,8 +307,7 @@ } int -wait_command(pid) - int pid; +wait_command(pid_t pid) { if (wait_child(pid) < 0) { @@ -364,9 +318,7 @@ } static struct child * -findchild(pid, dont_alloc) - int pid; - int dont_alloc; +findchild(pid_t pid, int dont_alloc) { struct child **cpp; @@ -389,8 +341,7 @@ } static void -delchild(cp) - struct child *cp; +delchild(struct child *cp) { struct child **cpp; @@ -402,10 +353,9 @@ } void -sigchild(signo) - int signo; +sigchild(int signo) { - int pid; + pid_t pid; int status; struct child *cp; int save_errno = errno; @@ -431,8 +381,7 @@ * Wait for a specific child to die. */ int -wait_child(pid) - int pid; +wait_child(pid_t pid) { struct child *cp; sigset_t nset, oset; @@ -464,8 +413,7 @@ * Mark a child as don't care. */ void -free_child(pid) - int pid; +free_child(pid_t pid) { struct child *cp; sigset_t nset, oset; @@ -487,11 +435,10 @@ * Returns 1 for success, 0 for failure, -1 for bad usage. */ static int -handle_spool_locks(action) - int action; +handle_spool_locks(int action) { static FILE *lockfp = NULL; - static int lock_pid; + static pid_t lock_pid; if (action == 0) { /* Clear the lock */ @@ -535,13 +482,15 @@ } int -spool_lock() +spool_lock(void) { + return(handle_spool_locks(1)); } int -spool_unlock() +spool_unlock(void) { + return(handle_spool_locks(0)); }