Commit graph

405 commits

Author SHA1 Message Date
d08c9a6727
tests: check simple noops 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
6f75f2d181
connec_cmd_execute: naive recursive pipe implementation (does not handle redirection) 2025-04-15 15:11:26 +02:00
df73b3d0c7
connec_cmd_execute: handle && and || 2025-04-15 15:11:26 +02:00
8feacccb15
group_cmd_execute: fork and passthrough to cmd_execute 2025-04-15 15:11:26 +02:00
425722801b
refactor(do_waitpid): put into own file for easier acces from other modules 2025-04-15 15:11:26 +02:00
f9f8a804a3
cmd_execute: execute simple commands 2025-04-15 15:11:11 +02:00
7af032539a
cmd_execute: initial scafholding 2025-04-15 15:11:11 +02:00
881c7f264c
signal: if a command is terminated by SIGQUIT, display that it core dumped 2025-04-15 15:11:11 +02:00
ceee5f99d4
signal: SIGQUIT prints ^\ to the terminal, and does not redisplay the prompt 2025-04-15 15:10:40 +02:00
10e8738336
signal: handle redisplaying the prompt correctly 2025-04-15 15:10:40 +02:00
3a309062d8
refactor(signal): remove unneded function
excve already resets signal handling to the default
2025-04-15 15:09:39 +02:00
cb8f64367d
minishell: exit with last command exit status 2025-04-15 15:09:39 +02:00
67b2347df9
signal: keep waiting for process to exit on SIGQUIT
the SA_RESTART flag causes syscalls such as waitpid to be resumed after a signal
is handled, which is what we want.
2025-04-15 15:08:06 +02:00
f0145d26f4
signal: do not exit shell on SIGINT, ignore SIGQUIT 2025-04-15 15:08:06 +02:00
be183b99ee
minishell: do wildcard expansion 2025-04-15 15:06:46 +02:00
f06f6e26e2
fix(expand_star): memory leak
You have to call closedir().

I also removed the errno checking to make some space, I don't think it is needed
when looking at the errors returned by these functions.
2025-04-15 15:05:52 +02:00
32e3976774
field splitting: implement field splitting 2025-04-15 15:05:52 +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
9e79a0829a
fix: do not read ahead in STDIN
The Open Group Base Specifications Issue 8 IEEE Std 1003.1-2024 sh — shell, the
standard command language interpreter says:

> When the shell is using standard input and it invokes a command that also uses
> standard input, the shell shall ensure that the standard input file pointer
> points directly after the command it has read when the command begins
> execution. It shall not read ahead in such a manner that any characters
> intended to be read by the invoked command are consumed by the shell (whether
> interpreted by the shell or not) or that characters that are not read by the
> invoked command are not seen by the shell.

We used the default BUFFER_SIZE for get_next_line of 1024, which caused us to
read ahead farther than was allowed by the Open Group Base Specification.

Setting BUFFER_SIZE=1 ensures that we don't read too far ahead, since
get_next_line will always immediatly stop once a newline is found.

This is for me the simplest way to solve this issue.
2025-04-15 14:41:44 +02:00
0842fdfe1d
fix: double free when getting command path for empty command
```
minishell$ ""
```
leads to the following error:
```
=================================================================
==1158770==ERROR: AddressSanitizer: attempting double-free on 0x5060000020c0 in thread T0:
    #0 0x5649fcb5b8a8 in free.part.0 asan_malloc_linux.cpp.o
    #1 0x5649fcbac549 in deal_with_filled_path /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp.c:119:3
    #2 0x5649fcbac38b in filepath_from_env /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp.c:165:10
    #3 0x5649fcbac220 in get_cmdpath /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp.c:186:10
    #4 0x5649fcba8664 in simple_cmd_execute /home/khais/src/42/common_env/minishell/src/executing/simple_cmd/simple_cmd_execute.c:71:8
    #5 0x5649fcba6e4c in execute_command /home/khais/src/42/common_env/minishell/src/minishell.c:49:2
    #6 0x5649fcba6ce5 in main /home/khais/src/42/common_env/minishell/src/minishell.c:92:3
    #7 0x7fb4f2dcd27d in __libc_start_call_main (/nix/store/nqb2ns2d1lahnd5ncwmn6k84qfd7vx2k-glibc-2.40-36/lib/libc.so.6+0x2a27d) (BuildId: 704cab5816f130c494208e8cc24d87a386ef085b)
    #8 0x7fb4f2dcd338 in __libc_start_main@GLIBC_2.2.5 (/nix/store/nqb2ns2d1lahnd5ncwmn6k84qfd7vx2k-glibc-2.40-36/lib/libc.so.6+0x2a338) (BuildId: 704cab5816f130c494208e8cc24d87a386ef085b)
    #9 0x5649fca6f394 in _start (/home/khais/src/42/common_env/minishell/minishell+0x2b394)

0x5060000020c0 is located 0 bytes inside of 58-byte region [0x5060000020c0,0x5060000020fa)
freed by thread T0 here:
    #0 0x5649fcb5b8a8 in free.part.0 asan_malloc_linux.cpp.o
    #1 0x5649fcbac669 in select_path /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp.c:81:3
    #2 0x5649fcbac524 in deal_with_filled_path /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp.c:116:9
    #3 0x5649fcbac38b in filepath_from_env /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp.c:165:10
    #4 0x5649fcbac220 in get_cmdpath /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp.c:186:10
    #5 0x5649fcba8664 in simple_cmd_execute /home/khais/src/42/common_env/minishell/src/executing/simple_cmd/simple_cmd_execute.c:71:8
    #6 0x5649fcba6e4c in execute_command /home/khais/src/42/common_env/minishell/src/minishell.c:49:2
    #7 0x5649fcba6ce5 in main /home/khais/src/42/common_env/minishell/src/minishell.c:92:3
    #8 0x7fb4f2dcd27d in __libc_start_call_main (/nix/store/nqb2ns2d1lahnd5ncwmn6k84qfd7vx2k-glibc-2.40-36/lib/libc.so.6+0x2a27d) (BuildId: 704cab5816f130c494208e8cc24d87a386ef085b)

previously allocated by thread T0 here:
    #0 0x5649fcb5c897 in malloc (/home/khais/src/42/common_env/minishell/minishell+0x118897)
    #1 0x5649fcbac6be in alloc_path /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp_utils.c:34:9
    #2 0x5649fcbac4e9 in deal_with_filled_path /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp.c:113:15
    #3 0x5649fcbac38b in filepath_from_env /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp.c:165:10
    #4 0x5649fcbac220 in get_cmdpath /home/khais/src/42/common_env/minishell/src/subst/simple_filename_exp.c:186:10
    #5 0x5649fcba8664 in simple_cmd_execute /home/khais/src/42/common_env/minishell/src/executing/simple_cmd/simple_cmd_execute.c:71:8
    #6 0x5649fcba6e4c in execute_command /home/khais/src/42/common_env/minishell/src/minishell.c:49:2
    #7 0x5649fcba6ce5 in main /home/khais/src/42/common_env/minishell/src/minishell.c:92:3
    #8 0x7fb4f2dcd27d in __libc_start_call_main (/nix/store/nqb2ns2d1lahnd5ncwmn6k84qfd7vx2k-glibc-2.40-36/lib/libc.so.6+0x2a27d) (BuildId: 704cab5816f130c494208e8cc24d87a386ef085b)

SUMMARY: AddressSanitizer: double-free asan_malloc_linux.cpp.o in free.part.0
==1158770==ABORTING
```

Looks like select_path frees filepath sometimes, no idea why. Removing these
lines didn't break any tests.

I'm pushing this to get a second opinion
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
4de1d0024a parsing: refactor out the last two functions needed to pass the norm 2025-04-15 14:41:43 +02:00
5e84e9a111 parsing: remove (at least some) dead code 2025-04-15 14:41:43 +02:00
218be08049 parsing: refactor group_cmd_parse into own file 2025-04-15 14:41:43 +02:00
b7871be426 parsing: refactor minishell_optional_pipeline_parse into own file 2025-04-15 14:41:43 +02:00
811ce3ef8e parsing: refactor minishell_simple_cmd_parse into own file 2025-04-15 14:41:43 +02:00
e033909819 makefile: generate depfiles for the correct object files
The depfiles were completely ineffective.

Now this is fixed.

The -MT argument sets the path for the dependenency root. By default it is set
only to a filename, and thus does not include the full path of the file.
2025-04-15 14:41:43 +02:00
9a58198303 parsing: refactor minishell_redirect_parse to own file 2025-04-15 14:41:43 +02:00
d4197fec38 parsing: create specialised function to create a t_cmd 2025-04-15 14:41:43 +02:00
fde0bf4dc9 parsing: refactor: simple norm linecount gains 2025-04-15 14:41:43 +02:00
055dabc546 parsing: add newline at end of error message 2025-04-15 14:41:43 +02:00
dbba36dc44 parsing: split minishell_group_or_simple_parse 2025-04-15 14:41:43 +02:00
86e658fcca parsing: rename minishell_group_or_smp_parse -> minishell_group_or_simple_parse 2025-04-15 14:41:43 +02:00
283458b24f parsing: put redirect specific functions into own file 2025-04-15 14:41:43 +02:00
54f6c2a609 parsing: remove debugs 2025-04-15 14:41:43 +02:00
0c489f25bb parsing: fix some easy leaks 2025-04-15 14:41:43 +02:00
d40b6c3586
debug, destroy all new types (also some code for testing it) 2025-04-15 14:41:43 +02:00
53693e171e parsing: do not use a builder struct
since only one field was being used, just pass that field around
2025-04-14 14:53:31 +02:00
7425195350 norm: fix all easy issues 2025-04-14 14:44:42 +02:00
1c9653a5a5 parsing: parse redirections 2025-04-14 14:44:42 +02:00
1866da6ea6
fix: make it compile 2025-04-11 16:57:31 +02:00
Jérôme Guélen
4baad88a44
parse-cmd: Only redirections left to parse. 2025-04-10 18:57:04 +02:00