summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2024-08-20 23:40:40 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2024-08-20 23:40:40 +0000
commitcbbaf640930e293c05eb6f6921efbc899ef0befa (patch)
treeef809fe37eb2f7853f58d8cc5a2bdb4faf70ce73
parentf69df1459b01867f44502c0379f1fcc3b9b77016 (diff)
Now that we have dup2(), csh can use it instead of close()+dup().
Also, as used here, dup/dup2 will clear the close-on-exec flag, so delete the superfluous fcntl(F_SETFD,0) calls ok deraadt@
-rw-r--r--bin/csh/sem.c22
1 files changed, 7 insertions, 15 deletions
diff --git a/bin/csh/sem.c b/bin/csh/sem.c
index bb47e8925a6..f98ca94cdbe 100644
--- a/bin/csh/sem.c
+++ b/bin/csh/sem.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sem.c,v 1.24 2024/07/28 15:31:22 deraadt Exp $ */
+/* $OpenBSD: sem.c,v 1.25 2024/08/20 23:40:39 guenther Exp $ */
/* $NetBSD: sem.c,v 1.9 1995/09/27 00:38:50 jtc Exp $ */
/*-
@@ -537,8 +537,7 @@ doio(struct command *t, int *pipein, int *pipeout)
(void) dmove(fd, 0);
}
else if (flags & F_PIPEIN) {
- (void) close(0);
- (void) dup(pipein[0]);
+ (void) dup2(pipein[0], 0);
(void) close(pipein[0]);
(void) close(pipein[1]);
}
@@ -547,9 +546,7 @@ doio(struct command *t, int *pipein, int *pipeout)
(void) open(_PATH_DEVNULL, O_RDONLY);
}
else {
- (void) close(0);
- (void) dup(OLDSTD);
- (void) fcntl(STDIN_FILENO, F_SETFD, 0);
+ (void) dup2(OLDSTD, 0);
}
}
if (t->t_drit) {
@@ -577,22 +574,17 @@ doio(struct command *t, int *pipein, int *pipeout)
(void) dmove(fd, 1);
}
else if (flags & F_PIPEOUT) {
- (void) close(1);
- (void) dup(pipeout[1]);
+ (void) dup2(pipeout[1], 1);
}
else {
- (void) close(1);
- (void) dup(SHOUT);
- (void) fcntl(STDOUT_FILENO, F_SETFD, 0);
+ (void) dup2(SHOUT, 1);
}
- (void) close(2);
if (flags & F_STDERR) {
- (void) dup(1);
+ (void) dup2(1, 2);
}
else {
- (void) dup(SHERR);
- (void) fcntl(STDERR_FILENO, F_SETFD, 0);
+ (void) dup2(SHERR, 2);
}
didfds = 1;
}