summaryrefslogtreecommitdiff
path: root/src/cmd/shell
diff options
context:
space:
mode:
authordzwdz2023-09-07 01:31:09 +0200
committerdzwdz2023-09-07 01:31:09 +0200
commit58eed4a5791cc99859a2591a59f3e0de0a2dc1ab (patch)
tree091e5379a94674d9643188978d6c19776f05f94c /src/cmd/shell
parent9c3ee3807c93945380e58379d5d0a415d9d88521 (diff)
user: fix stdio stream pos; remove the shell pipe redir workaround
Diffstat (limited to 'src/cmd/shell')
-rw-r--r--src/cmd/shell/shell.c26
1 files changed, 2 insertions, 24 deletions
diff --git a/src/cmd/shell/shell.c b/src/cmd/shell/shell.c
index d87527c..b5ad907 100644
--- a/src/cmd/shell/shell.c
+++ b/src/cmd/shell/shell.c
@@ -101,30 +101,8 @@ void run_args(int argc, char **argv, struct redir *redir) {
if (!f) {
err(1, "couldn't open %s for redirection", redir->stdout);
}
-
- /* a workaround for file offsets not being preserved across exec()s.
- * TODO document that weird behaviour of exec() */
- hid_t p[2];
- if (_sys_pipe(p, 0) < 0) {
- errx(1, "couldn't create redirection pipe");
- }
- if (!_sys_fork(FORK_NOREAP, NULL)) {
- /* the child forwards data from the pipe to the file */
- const size_t buflen = 512;
- char *buf = malloc(buflen);
- if (!buf) err(1, "when redirecting");
- close(p[1]);
- for (;;) {
- long len = _sys_read(p[0], buf, buflen, 0);
- if (len <= 0) exit(0);
- fwrite(buf, 1, len, f);
- if (ferror(f)) exit(0);
- }
- }
-
- fclose(f);
- close(p[0]);
- if (_sys_dup(p[1], 1, 0) < 0) {
+ // TODO fileno error checking
+ if (_sys_dup(fileno(f), 1, 0) < 0) {
errx(1, "dup() failed when redirecting");
}
}