summaryrefslogtreecommitdiff
path: root/usr.bin/mail/popen.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/mail/popen.c')
-rw-r--r--usr.bin/mail/popen.c84
1 files changed, 43 insertions, 41 deletions
diff --git a/usr.bin/mail/popen.c b/usr.bin/mail/popen.c
index 1c0226fbbbe..30194940932 100644
--- a/usr.bin/mail/popen.c
+++ b/usr.bin/mail/popen.c
@@ -1,5 +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 $ */
+/* $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,7 +38,7 @@
#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 $";
+static char rcsid[] = "$OpenBSD: popen.c,v 1.6 1997/07/13 21:21:15 millert Exp $";
#endif
#endif /* not lint */
@@ -81,7 +81,7 @@ Fopen(file, mode)
register_file(fp, 0, 0);
(void) fcntl(fileno(fp), F_SETFD, 1);
}
- return fp;
+ return(fp);
}
FILE *
@@ -95,7 +95,7 @@ Fdopen(fd, mode)
register_file(fp, 0, 0);
(void) fcntl(fileno(fp), F_SETFD, 1);
}
- return fp;
+ return(fp);
}
int
@@ -103,7 +103,7 @@ Fclose(fp)
FILE *fp;
{
unregister_file(fp);
- return fclose(fp);
+ return(fclose(fp));
}
FILE *
@@ -118,7 +118,7 @@ Popen(cmd, mode)
FILE *fp;
if (pipe(p) < 0)
- return NULL;
+ return(NULL);
(void) fcntl(p[READ], F_SETFD, 1);
(void) fcntl(p[WRITE], F_SETFD, 1);
if (*mode == 'r') {
@@ -132,14 +132,14 @@ Popen(cmd, mode)
}
sigemptyset(&nset);
if ((pid = start_command(cmd, &nset, fd0, fd1, NOSTR, NOSTR, NOSTR)) < 0) {
- close(p[READ]);
- close(p[WRITE]);
- return NULL;
+ (void)close(p[READ]);
+ (void)close(p[WRITE]);
+ return(NULL);
}
- (void) close(hisside);
+ (void)close(hisside);
if ((fp = fdopen(myside, mode)) != NULL)
register_file(fp, 1, pid);
- return fp;
+ return(fp);
}
int
@@ -151,14 +151,14 @@ Pclose(ptr)
i = file_pid(ptr);
unregister_file(ptr);
- (void) fclose(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;
+ return(i);
}
void
@@ -167,9 +167,9 @@ close_all_files()
while (fp_head)
if (fp_head->pipe)
- (void) Pclose(fp_head->fp);
+ (void)Pclose(fp_head->fp);
else
- (void) Fclose(fp_head->fp);
+ (void)Fclose(fp_head->fp);
}
void
@@ -179,7 +179,7 @@ register_file(fp, pipe, pid)
{
struct fp *fpp;
- if ((fpp = (struct fp *) malloc(sizeof *fpp)) == NULL)
+ if ((fpp = (struct fp *) malloc(sizeof(*fpp))) == NULL)
panic("Out of memory");
fpp->fp = fp;
fpp->pipe = pipe;
@@ -211,7 +211,7 @@ file_pid(fp)
for (p = fp_head; p; p = p->link)
if (p->fp == fp)
- return (p->pid);
+ return(p->pid);
panic("Invalid file pointer");
/*NOTREACHED*/
}
@@ -234,8 +234,8 @@ run_command(cmd, mask, infd, outfd, a0, a1, a2)
int pid;
if ((pid = start_command(cmd, mask, infd, outfd, a0, a1, a2)) < 0)
- return -1;
- return wait_command(pid);
+ return(-1);
+ return(wait_command(pid));
}
/*VARARGS4*/
@@ -249,12 +249,12 @@ start_command(cmd, mask, infd, outfd, a0, a1, a2)
int pid;
if ((pid = vfork()) < 0) {
- perror("fork");
- return -1;
+ warn("fork");
+ return(-1);
}
if (pid == 0) {
char *argv[100];
- int i = getrawlist(cmd, argv, sizeof argv / sizeof *argv);
+ int i = getrawlist(cmd, argv, sizeof(argv)/ sizeof(*argv));
if ((argv[i++] = a0) != NOSTR &&
(argv[i++] = a1) != NOSTR &&
@@ -262,10 +262,10 @@ start_command(cmd, mask, infd, outfd, a0, a1, a2)
argv[i] = NOSTR;
prepare_child(mask, infd, outfd);
execvp(argv[0], argv);
- perror(argv[0]);
+ warn(argv[0]);
_exit(1);
}
- return pid;
+ return(pid);
}
void
@@ -284,13 +284,15 @@ prepare_child(nset, infd, outfd)
dup2(infd, 0);
if (outfd >= 0)
dup2(outfd, 1);
- if (nset) {
+ if (nset == NULL)
+ return;
+ if (nset != NULL) {
for (i = 1; i < NSIG; i++)
if (sigismember(nset, i))
(void) signal(i, SIG_IGN);
- if (!sigismember(nset, SIGINT))
- (void) signal(SIGINT, SIG_DFL);
}
+ if (nset == NULL || !sigismember(nset, SIGINT))
+ (void) signal(SIGINT, SIG_DFL);
sigfillset(&fset);
(void) sigprocmask(SIG_UNBLOCK, &fset, NULL);
}
@@ -301,10 +303,10 @@ wait_command(pid)
{
if (wait_child(pid) < 0) {
- printf("Fatal error in process.\n");
- return -1;
+ puts("Fatal error in process.");
+ return(-1);
}
- return 0;
+ return(0);
}
static struct child *
@@ -317,12 +319,12 @@ findchild(pid)
cpp = &(*cpp)->link)
;
if (*cpp == NULL) {
- *cpp = (struct child *) malloc(sizeof (struct child));
+ *cpp = (struct child *) malloc(sizeof(struct child));
(*cpp)->pid = pid;
(*cpp)->done = (*cpp)->free = 0;
(*cpp)->link = NULL;
}
- return *cpp;
+ return(*cpp);
}
static void
@@ -377,7 +379,7 @@ wait_child(pid)
wait_status = cp->status;
delchild(cp);
sigprocmask(SIG_SETMASK, &oset, NULL);
- return wait_status.w_status ? -1 : 0;
+ return(wait_status.w_status ? -1 : 0);
}
/*
@@ -415,12 +417,12 @@ handle_spool_locks(action)
if (action == 0) {
/* Clear the lock */
if (lockfp == NULL) {
- fprintf(stderr,
- "handle_spool_locks: no spool lock to remove.\n");
- return (-1);
+ fputs("handle_spool_locks: no spool lock to remove.\n",
+ stderr);
+ return(-1);
}
(void)kill(lock_pid, SIGTERM);
- Pclose(lockfp);
+ (void)Pclose(lockfp);
lockfp = NULL;
} else if (action == 1) {
/* Create the lock */
@@ -430,7 +432,7 @@ handle_spool_locks(action)
if ((lockfp = Popen(cmd, "r")) == NULL || getc(lockfp) != '1') {
lockfp = NULL;
free(cmd);
- return (0);
+ return(0);
}
lock_pid = fp_head->pid; /* new entries added at head */
@@ -438,10 +440,10 @@ handle_spool_locks(action)
} else {
fprintf(stderr, "handle_spool_locks: unknown action %d\n",
action);
- return (-1);
+ return(-1);
}
- return (1);
+ return(1);
}
int