This commit is contained in:
Laureηt 2021-04-20 22:19:58 +02:00
parent ba0df8b7cd
commit 5b3e7f5ed4
4 changed files with 20 additions and 12 deletions

BIN
.vscode/launch vendored Executable file

Binary file not shown.

BIN
minishell

Binary file not shown.

View file

@ -15,6 +15,8 @@ int prompting = 0;
int job_id = 1; int job_id = 1;
list jobs; list jobs;
jmp_buf start;
void handler_print(int signal_num, siginfo_t *info) void handler_print(int signal_num, siginfo_t *info)
{ {
if (contiens(&jobs, info->si_pid)) 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"); printf("\n");
longjmp(start, signal_num); siglongjmp(start, signal_num);
}
void handler_stop(int signal_num, siginfo_t *info)
{
printf("bye\n");
longjmp(end, signal_num);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -50,10 +46,12 @@ int main(int argc, char *argv[])
// gestion de SIGCHLD // gestion de SIGCHLD
struct sigaction action; struct sigaction action;
sigemptyset(&action.sa_mask);
action.sa_flags = SA_SIGINFO; //| SA_RESTART; action.sa_flags = SA_SIGINFO; //| SA_RESTART;
action.sa_handler = handler_print; action.sa_handler = handler_print;
sigemptyset(&action.sa_mask);
sigaction(SIGCHLD, &action, NULL); sigaction(SIGCHLD, &action, NULL);
action.sa_handler = handler_restart;
sigaction(SIGINT, &action, NULL);
// variables de "pwd" // variables de "pwd"
char initcd[256], currentcd[256]; char initcd[256], currentcd[256];
@ -62,6 +60,12 @@ int main(int argc, char *argv[])
// loop principal // loop principal
while (1) while (1)
{ {
if (sigsetjmp(start, 1) == 2)
{ // si on provient du jump
continue;
}
getcwd(currentcd, 256); getcwd(currentcd, 256);
printf("%s >>> ", currentcd); printf("%s >>> ", currentcd);
@ -70,12 +74,16 @@ int main(int argc, char *argv[])
struct cmdline *cmd = readcmd(); struct cmdline *cmd = readcmd();
prompting = 0; 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 { // ligne vide, on skip
continue; continue;
} }
else if (!strcmp(cmd->seq[0][0], "exit")) else if (!strcmp(cmd->seq[0][0], "exit"))
{ // on quitte le shell {
break; break;
} }
else if (!strcmp(cmd->seq[0][0], "cd")) else if (!strcmp(cmd->seq[0][0], "cd"))

BIN
readcmd Executable file

Binary file not shown.