diff --git a/exec.c b/exec.c index 4f0cd04..136be1a 100644 --- a/exec.c +++ b/exec.c @@ -2,7 +2,7 @@ * @Author: 1ridic * @Date: 2022-09-18 14:14:23 * @Last Modified by: 1ridic - * @Last Modified time: 2022-09-18 23:31:39 + * @Last Modified time: 2022-09-20 22:24:51 */ #include "builtin.h" #include @@ -31,17 +31,13 @@ int forkExec(char **args) { /* fork error */ perror("dish"); } else { - extern char volatile isWaiting; - isWaiting = 1; /* parent process: wait child process*/ int stat_val; waitpid(pid, &stat_val, 0); if (WIFEXITED(stat_val)) { - isWaiting = 0; return WEXITSTATUS(stat_val); } else if (WIFSIGNALED(stat_val)) { - isWaiting = 1; return WTERMSIG(stat_val); } } diff --git a/loop.c b/loop.c index 1460839..790306b 100644 --- a/loop.c +++ b/loop.c @@ -2,7 +2,7 @@ * @Author: 1ridic * @Date: 2022-09-18 14:13:53 * @Last Modified by: 1ridic - * @Last Modified time: 2022-09-18 23:32:02 + * @Last Modified time: 2022-09-20 22:26:59 */ #include #include @@ -15,6 +15,20 @@ int status; +void SIGINT_Handler(int dummy) { +#ifdef DEBUG + fprintf(stdout,"\ndebug: SIGINT\n"); +#endif + /* Move to a new line */ + fprintf(stdout,"\n"); + /* Regenerate the prompt on a newline */ + rl_on_new_line(); + /* Clear the previous text */ + rl_replace_line("", 0); + rl_redisplay(); + return; +} + int loop() { char *line; diff --git a/loop.h b/loop.h index d5f4c48..dbe9333 100644 --- a/loop.h +++ b/loop.h @@ -1,11 +1,12 @@ /* * @Author: 1ridic * @Date: 2022-09-18 14:14:19 - * @Last Modified by: 1ridic - * @Last Modified time: 2022-09-18 14:14:19 + * @Last Modified by: 1ridic + * @Last Modified time: 2022-09-20 22:24:24 */ #ifndef _LOOP_H_ #define _LOOP_H_ #include "config.h" +void SIGINT_Handler(int dummy); int loop(); #endif \ No newline at end of file diff --git a/main.c b/main.c index 4403875..6553d99 100644 --- a/main.c +++ b/main.c @@ -2,7 +2,7 @@ * @Author: 1ridic * @Date: 2022-09-18 14:13:59 * @Last Modified by: 1ridic - * @Last Modified time: 2022-09-18 23:21:37 + * @Last Modified time: 2022-09-20 22:23:59 */ #include #include @@ -11,22 +11,10 @@ #include #include "loop.h" -char volatile isWaiting = 0; -void intHandler(int dummy) { -#ifdef DEBUG - fprintf(stdout,"\ndebug: enter soft-irq. isWaiting=%d\n",isWaiting); -#endif - if (isWaiting==1) { - return; - } - fprintf(stderr,"\nSIGINT exit.\n"); - exit(EXIT_FAILURE); - -} int main(int argc, char *argv[]) { /* soft irq */ - signal(SIGINT, intHandler); + signal(SIGINT, SIGINT_Handler); /* clear screen */ fprintf(stdout,"\033[H\033[J"); #ifdef DEBUG