From 58eed4a5791cc99859a2591a59f3e0de0a2dc1ab Mon Sep 17 00:00:00 2001 From: dzwdz Date: Thu, 7 Sep 2023 01:31:09 +0200 Subject: user: fix stdio stream pos; remove the shell pipe redir workaround --- src/cmd/shell/shell.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) (limited to 'src/cmd/shell') 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"); } } -- cgit v1.2.3