v2 ?
This commit is contained in:
parent
ba0df8b7cd
commit
5b3e7f5ed4
BIN
.vscode/launch
vendored
Executable file
BIN
.vscode/launch
vendored
Executable file
Binary file not shown.
32
minishell.c
32
minishell.c
|
@ -15,6 +15,8 @@ int prompting = 0;
|
|||
int job_id = 1;
|
||||
list jobs;
|
||||
|
||||
jmp_buf start;
|
||||
|
||||
void handler_print(int signal_num, siginfo_t *info)
|
||||
{
|
||||
if (contiens(&jobs, info->si_pid))
|
||||
|
@ -29,16 +31,10 @@ void handler_print(int signal_num, siginfo_t *info)
|
|||
}
|
||||
}
|
||||
|
||||
void handler_int(int signal_num, siginfo_t *info)
|
||||
void handler_restart(int signal_num, siginfo_t *info)
|
||||
{
|
||||
printf("test\n");
|
||||
longjmp(start, signal_num);
|
||||
}
|
||||
|
||||
void handler_stop(int signal_num, siginfo_t *info)
|
||||
{
|
||||
printf("bye\n");
|
||||
longjmp(end, signal_num);
|
||||
printf("\n");
|
||||
siglongjmp(start, signal_num);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
@ -50,10 +46,12 @@ int main(int argc, char *argv[])
|
|||
|
||||
// gestion de SIGCHLD
|
||||
struct sigaction action;
|
||||
sigemptyset(&action.sa_mask);
|
||||
action.sa_flags = SA_SIGINFO; //| SA_RESTART;
|
||||
action.sa_handler = handler_print;
|
||||
sigemptyset(&action.sa_mask);
|
||||
sigaction(SIGCHLD, &action, NULL);
|
||||
action.sa_handler = handler_restart;
|
||||
sigaction(SIGINT, &action, NULL);
|
||||
|
||||
// variables de "pwd"
|
||||
char initcd[256], currentcd[256];
|
||||
|
@ -62,6 +60,12 @@ int main(int argc, char *argv[])
|
|||
// loop principal
|
||||
while (1)
|
||||
{
|
||||
|
||||
if (sigsetjmp(start, 1) == 2)
|
||||
{ // si on provient du jump
|
||||
continue;
|
||||
}
|
||||
|
||||
getcwd(currentcd, 256);
|
||||
|
||||
printf("%s >>> ", currentcd);
|
||||
|
@ -70,12 +74,16 @@ int main(int argc, char *argv[])
|
|||
struct cmdline *cmd = readcmd();
|
||||
prompting = 0;
|
||||
|
||||
if (cmd == NULL || cmd->seq[0] == NULL)
|
||||
if (cmd == NULL)
|
||||
{ // on quitte le shell, EOF
|
||||
break;
|
||||
}
|
||||
else if (cmd->seq[0] == NULL)
|
||||
{ // ligne vide, on skip
|
||||
continue;
|
||||
}
|
||||
else if (!strcmp(cmd->seq[0][0], "exit"))
|
||||
{ // on quitte le shell
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (!strcmp(cmd->seq[0][0], "cd"))
|
||||
|
|
Loading…
Reference in a new issue