stable shit
This commit is contained in:
parent
480adc8c90
commit
f4ddc36d62
BIN
minishell2
BIN
minishell2
Binary file not shown.
43
minishell2.c
43
minishell2.c
|
@ -11,13 +11,22 @@
|
|||
#include "readcmd.h"
|
||||
#include "jobs.h"
|
||||
|
||||
extern int errno;
|
||||
|
||||
struct cmdline *cmd;
|
||||
|
||||
int pid_fils;
|
||||
|
||||
int job_id = 0;
|
||||
list jobs;
|
||||
|
||||
int prompting = 0;
|
||||
jmp_buf goto_prompt;
|
||||
|
||||
char initcd[256], currentcd[256];
|
||||
|
||||
|
||||
|
||||
void handler_sigchld(int signal_num, siginfo_t *info)
|
||||
{
|
||||
cell *job = trouver(&jobs, info->si_pid);
|
||||
|
@ -28,7 +37,7 @@ void handler_sigchld(int signal_num, siginfo_t *info)
|
|||
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);
|
||||
job_id--;
|
||||
|
||||
|
@ -39,11 +48,12 @@ void handler_sigchld(int signal_num, siginfo_t *info)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
initialiser(&jobs);
|
||||
|
||||
extern int errno;
|
||||
getcwd(initcd, sizeof(initcd));
|
||||
|
||||
// gestion des signaux
|
||||
struct sigaction action;
|
||||
|
@ -58,7 +68,8 @@ int main(int argc, char *argv[])
|
|||
sigsetjmp(goto_prompt, 1);
|
||||
|
||||
prompting = 1;
|
||||
printf(">>> ");
|
||||
getcwd(currentcd, sizeof(currentcd));
|
||||
printf("%s >>> ", currentcd);
|
||||
cmd = readcmd();
|
||||
prompting = 0;
|
||||
|
||||
|
@ -74,6 +85,28 @@ int main(int argc, char *argv[])
|
|||
{ // "exit"
|
||||
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();
|
||||
if (pid_fils == -1)
|
||||
|
@ -103,7 +136,7 @@ int main(int argc, char *argv[])
|
|||
{ // foreground
|
||||
int wait_code;
|
||||
pid_t id_fils = waitpid(pid_fils, &wait_code, 0); // on attend la fin de l'exec du fils
|
||||
|
||||
|
||||
if (id_fils == -1)
|
||||
{ // wait fail ?
|
||||
fprintf(stderr, "ERROR: waiting for %d failed, (%d) %s\n", wait_code, errno, strerror(errno));
|
||||
|
|
Loading…
Reference in a new issue