stable shit

This commit is contained in:
Laureηt 2021-04-21 15:19:23 +02:00
parent 480adc8c90
commit f4ddc36d62
2 changed files with 38 additions and 5 deletions

Binary file not shown.

View file

@ -11,13 +11,22 @@
#include "readcmd.h" #include "readcmd.h"
#include "jobs.h" #include "jobs.h"
extern int errno;
struct cmdline *cmd; struct cmdline *cmd;
int pid_fils; int pid_fils;
int job_id = 0; int job_id = 0;
list jobs; list jobs;
int prompting = 0; int prompting = 0;
jmp_buf goto_prompt; jmp_buf goto_prompt;
char initcd[256], currentcd[256];
void handler_sigchld(int signal_num, siginfo_t *info) void handler_sigchld(int signal_num, siginfo_t *info)
{ {
cell *job = trouver(&jobs, info->si_pid); cell *job = trouver(&jobs, info->si_pid);
@ -28,7 +37,7 @@ void handler_sigchld(int signal_num, siginfo_t *info)
printf("\n"); printf("\n");
} }
printf("[%d] (%d) done: %s\n", job->id, job->pid, job->cmd); printf("[%d] %d done: %s\n", job->id, job->pid, job->cmd);
supprimer(&jobs, job->pid); supprimer(&jobs, job->pid);
job_id--; job_id--;
@ -39,11 +48,12 @@ void handler_sigchld(int signal_num, siginfo_t *info)
} }
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
initialiser(&jobs); initialiser(&jobs);
getcwd(initcd, sizeof(initcd));
extern int errno;
// gestion des signaux // gestion des signaux
struct sigaction action; struct sigaction action;
@ -58,7 +68,8 @@ int main(int argc, char *argv[])
sigsetjmp(goto_prompt, 1); sigsetjmp(goto_prompt, 1);
prompting = 1; prompting = 1;
printf(">>> "); getcwd(currentcd, sizeof(currentcd));
printf("%s >>> ", currentcd);
cmd = readcmd(); cmd = readcmd();
prompting = 0; prompting = 0;
@ -74,6 +85,28 @@ int main(int argc, char *argv[])
{ // "exit" { // "exit"
break; break;
} }
else if (!strcmp(cmd->seq[0][0], "jobs"))
{ // "jobs"
afficher(&jobs);
continue;
}
else if (!strcmp(cmd->seq[0][0], "cd"))
{ // "cd"
int ret = 0;
if (cmd->seq[0][1] == NULL)
{ // no path
ret = chdir(initcd);
}
else
{ // with path
ret = chdir(cmd->seq[0][1]);
}
if (ret)
{ // wrong path
fprintf(stderr, "ERROR: cd failed, (%d) %s\n", errno, strerror(errno));
}
continue;
}
pid_fils = fork(); pid_fils = fork();
if (pid_fils == -1) if (pid_fils == -1)
@ -103,7 +136,7 @@ int main(int argc, char *argv[])
{ // foreground { // foreground
int wait_code; int wait_code;
pid_t id_fils = waitpid(pid_fils, &wait_code, 0); // on attend la fin de l'exec du fils pid_t id_fils = waitpid(pid_fils, &wait_code, 0); // on attend la fin de l'exec du fils
if (id_fils == -1) if (id_fils == -1)
{ // wait fail ? { // wait fail ?
fprintf(stderr, "ERROR: waiting for %d failed, (%d) %s\n", wait_code, errno, strerror(errno)); fprintf(stderr, "ERROR: waiting for %d failed, (%d) %s\n", wait_code, errno, strerror(errno));