diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-01-04 18:09:57 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-01-04 18:09:57 +0800 |
| commit | 92ca8063f354d515e500b7cf99fb9cdca98c39d3 (patch) | |
| tree | 142e6d9ada3d511663c6c0540196d270c69c0227 /src/user/sh.cc | |
| parent | a64d25c07b31d57f8706073e11cd774d0880d6dd (diff) | |
| parent | 3886749b1c8d79d4701bf6b8e66249c4e1491648 (diff) | |
| download | lume-92ca8063f354d515e500b7cf99fb9cdca98c39d3.tar.gz lume-92ca8063f354d515e500b7cf99fb9cdca98c39d3.tar.xz | |
Merge pull request #6 from Richard-Qin-001/dev/shell
A basically complete operating system has been implemented
Diffstat (limited to 'src/user/sh.cc')
| -rw-r--r-- | src/user/sh.cc | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/user/sh.cc b/src/user/sh.cc index b4122f7..760f29e 100644 --- a/src/user/sh.cc +++ b/src/user/sh.cc @@ -67,11 +67,26 @@ struct RedirCommand : public Command void run() override { close(fd); - if (open(file, mode) < 0) + + int newfd = open(file, mode); + + if (newfd < 0) { printf("open %s failed\n", file); exit(1); } + + if (newfd != fd) + { + + if (dup(newfd) != fd) + { + printf("Redirection failed: could not move fd %d to %d\n", newfd, fd); + exit(1); + } + close(newfd); + } + sub_cmd->run(); } }; @@ -348,15 +363,6 @@ int main() { static char buf[100]; - // int fd; - // while ((fd = open("console", O_RDWR)) >= 0) - // { - // if (fd >= 3) - // { - // close(fd); - // break; - // } - // } printf(ANSI_GREEN"\n[Lume Shell] Welcome! \n"ANSI_RESET); printf(ANSI_YELLOW "[Lume Shell] Start your journey of exploration!"ANSI_RESET); |
