Commit graph

49 commits

Author SHA1 Message Date
9fcb34e1d5 feat(builtins/cd): on error, print path 2025-04-25 16:08:10 +02:00
29bbb5e572 fix(command_not_found): unset or empty PATH leads to No such file or directory error 2025-04-25 15:52:02 +02:00
527a624765 fix(exec): return code 126 when command is found but permission denied 2025-04-25 12:40:34 +02:00
5fb054d403 fix(redirection): restore std fds on redirection error
debug notes:
$ cat << eof > /root/outfile
hello
eof
minishell: open: Permission denied
minishell: hello: command not found
==42382==
==42382== FILE DESCRIPTORS: 9 open (3 std) at exit.
==42382== Open file descriptor 8: /dev/pts/3
==42382==    at 0x49A8C1B: dup (in /nix/store/nqb2ns2d1lahnd5ncwmn6k84qfd7vx2k-glibc-2.40-36/lib/libc.so.6)
==42382==    by 0x10C9CC: handle_redirections (src/executing/simple_cmd/handle_redirections.c:65)
==42382==    by 0x10CBF6: simple_cmd_execute (src/executing/simple_cmd/simple_cmd_execute.c:91)
==42382==    by 0x10B10C: cmd_execute (src/executing/cmd/cmd_execute.c:23)
==42382==    by 0x10A4DD: execute_command (src/minishell.c:37)
==42382==    by 0x10A3A2: main (src/minishell.c:89)
==42382==
==42382== Open file descriptor 7: /dev/pts/3
==42382==    at 0x49A8C1B: dup (in /nix/store/nqb2ns2d1lahnd5ncwmn6k84qfd7vx2k-glibc-2.40-36/lib/libc.so.6)
==42382==    by 0x10C9B9: handle_redirections (src/executing/simple_cmd/handle_redirections.c:64)
==42382==    by 0x10CBF6: simple_cmd_execute (src/executing/simple_cmd/simple_cmd_execute.c:91)
==42382==    by 0x10B10C: cmd_execute (src/executing/cmd/cmd_execute.c:23)
==42382==    by 0x10A4DD: execute_command (src/minishell.c:37)
==42382==    by 0x10A3A2: main (src/minishell.c:89)
==42382==
==42382== Open file descriptor 6: /dev/pts/3
==42382==    at 0x49A8C1B: dup (in /nix/store/nqb2ns2d1lahnd5ncwmn6k84qfd7vx2k-glibc-2.40-36/lib/libc.so.6)
==42382==    by 0x10C9CC: handle_redirections (src/executing/simple_cmd/handle_redirections.c:65)
==42382==    by 0x10CBF6: simple_cmd_execute (src/executing/simple_cmd/simple_cmd_execute.c:91)
==42382==    by 0x10B10C: cmd_execute (src/executing/cmd/cmd_execute.c:23)
==42382==    by 0x10A4DD: execute_command (src/minishell.c:37)
==42382==    by 0x10A3A2: main (src/minishell.c:89)
==42382==
==42382== Open file descriptor 5: /dev/pts/3
==42382==    at 0x49A8C1B: dup (in /nix/store/nqb2ns2d1lahnd5ncwmn6k84qfd7vx2k-glibc-2.40-36/lib/libc.so.6)
==42382==    by 0x10C9B9: handle_redirections (src/executing/simple_cmd/handle_redirections.c:64)
==42382==    by 0x10CBF6: simple_cmd_execute (src/executing/simple_cmd/simple_cmd_execute.c:91)
==42382==    by 0x10B10C: cmd_execute (src/executing/cmd/cmd_execute.c:23)
==42382==    by 0x10A4DD: execute_command (src/minishell.c:37)
==42382==    by 0x10A3A2: main (src/minishell.c:89)
==42382==
==42382== Open file descriptor 4: /dev/pts/3
==42382==    at 0x49A8C1B: dup (in /nix/store/nqb2ns2d1lahnd5ncwmn6k84qfd7vx2k-glibc-2.40-36/lib/libc.so.6)
==42382==    by 0x10C9A6: handle_redirections (src/executing/simple_cmd/handle_redirections.c:63)
==42382==    by 0x10CBF6: simple_cmd_execute (src/executing/simple_cmd/simple_cmd_execute.c:91)
==42382==    by 0x10B10C: cmd_execute (src/executing/cmd/cmd_execute.c:23)
==42382==    by 0x10A4DD: execute_command (src/minishell.c:37)
==42382==    by 0x10A3A2: main (src/minishell.c:89)
==42382==
==42382== Open file descriptor 3: /tmp/minishell_here_doc_78Ak8J9TeVu (deleted)
==42382==    at 0x49A8C1B: dup (in /nix/store/nqb2ns2d1lahnd5ncwmn6k84qfd7vx2k-glibc-2.40-36/lib/libc.so.6)
==42382==    by 0x10C9A6: handle_redirections (src/executing/simple_cmd/handle_redirections.c:63)
==42382==    by 0x10CBF6: simple_cmd_execute (src/executing/simple_cmd/simple_cmd_execute.c:91)
==42382==    by 0x10B10C: cmd_execute (src/executing/cmd/cmd_execute.c:23)
==42382==    by 0x10A4DD: execute_command (src/minishell.c:37)
==42382==    by 0x10A3A2: main (src/minishell.c:89)
2025-04-24 13:47:54 +02:00
9db47dc96d feat(redirection): print path of redirection target on redirection error 2025-04-24 13:42:31 +02:00
ac198727e9 feat(postprocess): show error when post-processing failure occurs 2025-04-24 12:45:00 +02:00
2180909285 fix(expansion/wildcard): do not remove quotes twice on non-pattern strings
There is still an issue with removing too many quotes when expanding variables
(see #138). This will be tackled in a later PR.
2025-04-24 12:45:00 +02:00
2dd20b21bc feat(redir): fieldsplit redir target, and handle ambiguous redirects 2025-04-24 12:44:33 +02:00
2ae001e00b fix(exec/redirections): did not correctly restore fds when executing builtins
This caused redirections to keep stdout redirected to the outfile, which caused
problems with displaying the prmpt.

The shell hangs, but exits with C-d

Builtins affected:
echo hi > outfile
pwd > outfile
env > outfile
2025-04-18 14:14:43 +02:00
c5e15903e0 fix(builtin/export): show error on invalid identifiers such as % and $ 2025-04-18 10:17:21 +02:00
efaf4708f9 fix(builtin/export): empty arguments were not identified as invalid identifiers 2025-04-18 10:03:09 +02:00
d44691a5b0 fix(exec): running a command with an absolute path which does not exist now gives correct error
Before, it gave "Is a directory" error, but now it correctly gives "No such file
or directory".
2025-04-18 09:25:11 +02:00
655ff36351 fix(susbt/variable): empty variables on their own are removed 2025-04-18 09:22:18 +02:00
5e6d7b3b4e fix(parsing/here_doc): segfault & invalid fd & premature exit 2025-04-17 11:25:59 +02:00
733ae1093a fix(exec): correctly exit subprocesses, do not keep multiple shells in parallel 2025-04-16 17:30:25 +02:00
2ea4afda4a clean: move around some imports 2025-04-16 16:41:54 +02:00
18225f3356 fix(executing): return code on unknown cmd was unchanged, is now set to 127 2025-04-16 15:00:20 +02:00
81ba53237c parsing: do not reset last_return_value at start of parsing
we need to preserve it, to be able to show the return value from the last command
2025-04-15 15:45:29 +02:00
0579d1f2fc
env: correctly handle write errors such as /dev/full
The exit status of 125 for env in case of failure is documented in env(1).
2025-04-15 15:19:27 +02:00
ffaf2582a3
pwd: correctly handle write errors 2025-04-15 15:19:27 +02:00
cfc95994de
echo: correctly handle write errors such as /dev/full 2025-04-15 15:19:27 +02:00
81febcfcdd
debug: show command about to be executed in debug mode 2025-04-15 15:19:27 +02:00
ba9751e089
do postprocessing for each simple_cmd before execution 2025-04-15 15:13:17 +02:00
386d2bcb3a
exec: correct error and return value when cmd is a directory
minishell: /: Is a directory
$? = 126
2025-04-15 15:11:50 +02:00
bb1390aac5
simple_cmd_execute: handle redirections
I am very uncertain on if this is actually correct, but I am unable to test it
very much atm
2025-04-15 15:11:50 +02:00
425722801b
refactor(do_waitpid): put into own file for easier acces from other modules 2025-04-15 15:11:26 +02:00
881c7f264c
signal: if a command is terminated by SIGQUIT, display that it core dumped 2025-04-15 15:11:11 +02:00
0cfa2677c5
fix(echo): echo - was treated as echo -n
Small logic error on my part
2025-04-15 15:03:13 +02:00
d40560bb37
unset: implement unset 2025-04-15 15:03:13 +02:00
1ef8b7a0ae
env: implement builtin env 2025-04-15 15:03:13 +02:00
0de583cf45
echo: implement builtin echo 2025-04-15 15:03:13 +02:00
715c2aced8
exit: handle invalid and large arguments 2025-04-15 15:03:13 +02:00
f1c132337b
exit: work for simple arguments
This does not address non-integer arguments, or extremly high/low arguments.
2025-04-15 15:03:13 +02:00
24ba87abba
exec: retain exit status of commands, including if they were signaled 2025-04-15 15:01:19 +02:00
5b7367925f
simple_cmd refactor: put subprocess functions in own file
This clears some space for new functions later
2025-04-15 14:41:44 +02:00
cea8043ec9
simple_cmd executing: show error in case execve fails
We don't have to check the return status, since execve only returns on failure.

Fixes #52
2025-04-15 14:41:43 +02:00
Jérôme Guélen
10a3c9c411
parse-cmd: Various fixes and a rotation of the parsing tree 2025-04-08 12:14:38 +02:00
0a80b9fbe3
simple_cmd executing refactor: put builtin related utilities into own file 2025-04-01 16:38:41 +02:00
ba4192bf8d
export: set correct exit status 2025-04-01 15:58:56 +02:00
3cdf7c3f76
export: handle invalid identifiers 2025-04-01 15:54:46 +02:00
299e016a27
export: handle simple cases 2025-04-01 14:39:02 +02:00
7153df9305
cd: print error if cd is called with too many arguments 2025-03-31 20:06:34 +02:00
f1b2e1e22d
cd: handle empty argument 2025-03-31 17:07:46 +02:00
8f3c15f096
cd: when going to $HOME, show error message if it is unset 2025-03-31 16:58:21 +02:00
d66ca10a0c
cd: with no arg, go to $HOME 2025-03-31 16:40:22 +02:00
e93e6efb93
builtins: cd: implement cd to absolute paths 2025-03-31 16:34:48 +02:00
5ce4a2b85f
builtin: implement pwd 2025-03-31 14:54:40 +02:00
66ea1328aa
simple_cmd executing: print error message on command not found 2025-03-28 16:58:13 +01:00
befe219436
simple_cmd executing: works with arguments and env
Does not handle redirections at all, no special facilities are in place to allow
nofork or builtin execution.
2025-03-28 14:50:37 +01:00