Use closefrom, don't iterate over file descriptors from 3 to 20.

This commit is contained in:
tls 2006-04-03 16:13:34 +00:00
parent bd13d3ce50
commit 76f2334c55
4 changed files with 10 additions and 19 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cmds.c,v 1.27 2006/04/03 16:03:50 tls Exp $ */
/* $NetBSD: cmds.c,v 1.28 2006/04/03 16:13:34 tls Exp $ */
/*
* Copyright (c) 1983, 1993
@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)cmds.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: cmds.c,v 1.27 2006/04/03 16:03:50 tls Exp $");
__RCSID("$NetBSD: cmds.c,v 1.28 2006/04/03 16:13:34 tls Exp $");
#endif /* not lint */
#include "tip.h"
@ -230,12 +230,9 @@ pipefile(char dummy)
;
}
} else {
int f;
dup2(pdes[0], 0);
close(pdes[0]);
for (f = 3; f < 20; f++)
close(f);
closefrom(3);
execute(buf);
printf("can't execl!\r\n");
exit(0);
@ -495,11 +492,8 @@ pipeout(char c)
while ((p = wait(&status)) > 0 && p != cpid)
;
} else {
int i;
dup2(FD, 1);
for (i = 3; i < 20; i++)
close(i);
closefrom(3);
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
execute(buf);
@ -546,12 +540,9 @@ consh(char c)
while ((p = wait(&status)) > 0 && p != cpid)
;
} else {
int i;
dup2(FD, 0);
dup2(FD, 1);
for (i = 3; i < 20; i++)
close(i);
closefrom(3);
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
execute(buf);

View File

@ -1,4 +1,4 @@
/* $NetBSD: tip.c,v 1.42 2006/04/03 16:03:50 tls Exp $ */
/* $NetBSD: tip.c,v 1.43 2006/04/03 16:13:34 tls Exp $ */
/*
* Copyright (c) 1983, 1993
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\
#if 0
static char sccsid[] = "@(#)tip.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: tip.c,v 1.42 2006/04/03 16:03:50 tls Exp $");
__RCSID("$NetBSD: tip.c,v 1.43 2006/04/03 16:13:34 tls Exp $");
#endif /* not lint */
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: tip.h,v 1.26 2006/04/03 16:03:50 tls Exp $ */
/* $NetBSD: tip.h,v 1.27 2006/04/03 16:13:34 tls Exp $ */
/*
* Copyright (c) 1989, 1993

View File

@ -1,4 +1,4 @@
/* $NetBSD: tipout.c,v 1.12 2006/04/03 16:03:50 tls Exp $ */
/* $NetBSD: tipout.c,v 1.13 2006/04/03 16:13:34 tls Exp $ */
/*
* Copyright (c) 1983, 1993
@ -35,7 +35,7 @@
#if 0
static char sccsid[] = "@(#)tipout.c 8.1 (Berkeley) 6/6/93";
#endif
__RCSID("$NetBSD: tipout.c,v 1.12 2006/04/03 16:03:50 tls Exp $");
__RCSID("$NetBSD: tipout.c,v 1.13 2006/04/03 16:13:34 tls Exp $");
#endif /* not lint */
#include "tip.h"