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)
debug notes:
++++++++++++++++++++++++++++++++++++++++++++++++++++
failed: ambiguous redirect
++++++++++++++++++++++++++++++++++++++++++++++++++++
++++ test input:
export target="outfile1 outfile2"
echo hello > $target
echo $?
echo hi >> $target
echo $?
cat < $target
echo $?
ls
echo $?
++++ Got output:
hello
0
hi
0
echo $?
ls
echo $?
++++ But expected:
minishell: $target: ambiguous redirect
1
minishell: $target: ambiguous redirect
1
minishell: $target: ambiguous redirect
1
0
Reproduced this with rr record --cahos, see
/home/khais/.local/share/rr/minishell-48
$ export target="outfile1 outfile2"
$ echo hi > $target
hi
Break in simple_cmd_execute, second command has no redirections when it should
have some, presumably this comes from some uninitialized memory somewhere.
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
before:
```
$ ()
minishell: syntax error near unexpected token `)'
minishell: syntax error near unexpected token `)'
```
after:
```
$ ()
minishell: syntax error near unexpected token `)'
```
This probably fixes a few bugs as well, but I didn't look too hard. It just
seemed nicer to have a consistent way to report errors.
before:
$ >>>>>
minishell: syntax error near unexpected token `newline'
after:
$ >>>>>
minishell: syntax error near unexpected token `>>'
>> is now correctly detected as an operator, and not a word