sophiakoulen / minishell

A simplified bash-like shell, with pipes, redirections and variable expansion.
3 stars 1 forks source link

heredoc signal responding #132

Open znichola opened 1 year ago

znichola commented 1 year ago
bash-3.2$ <<a cat | echo 1
> 
bash-3.2$ exit
exit
➜  tests git:(main) ✗ ../minishell 
minishell$ <<a cat 
> ^C
> ^C
> ^C
> ^C

minishell$ <<a cat | ls
> ^C
launch_tests.sh         run_basic_test.sh       run_issues_test.sh      test_framework.sh
run_ast_tests.sh        run_export_test.sh      run_wildcard_test.sh
minishell$ 
sophiakoulen commented 1 year ago

It feels like changing when we call silent_signals() does not work. Also, that wouldn't be enough. If we want to handle it properly, we'd need to be able to jump out of command preparation. How can we implement this without jumping directly to another part of our program without using goto or siglongjump? The heredoc function would need to constantly check if we've been interrupted, right?

sophiakoulen commented 1 year ago

I got an idea, it's to set a global g_interrupted in our signal handler and stop command preparation when g_interrupted is 1.

znichola commented 1 year ago

hmm, I feel like this is starting to get a bit hacky. I tried having a look at changing the position of the silent signals and termios, we could copy the standard behaviour for a ctrl+C and just write a newline with no ctrl characters printed by correctly setting up our signals only around the execution and not setup.

...

now that i think about it we could kindof hijack the global we have and make a new signal handeller for ctrl+C that's only for prepare_pipeline, we read the global retn and if it's something like 0xFFF way above standard signals we know we've been interrupted by the special signal so stop heredoc getting and set retn value to 1 which bash does .

znichola commented 1 year ago

I've added my changes to the ctrlC branch. But I think this could safely be demoded to a small-bug.