From 61a5953a0f3b0eca0dcd6802871f17a45a2bc0ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Sun, 23 May 2021 11:58:39 +0200 Subject: [PATCH] feat: piping working --- .vscode/launch.json | 5 +- .vscode/settings.json | 4 +- minishell | Bin 34016 -> 27168 bytes minishell.c | 121 ++++++++++++++++++++++++++++++++++++++---- test.sh | 2 +- 5 files changed, 118 insertions(+), 14 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index f798eb3..d957525 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -20,7 +20,10 @@ "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true - } + }, + // { + // "text": "-gdb-set follow-fork-mode child" + // } ], "preLaunchTask": "C/C++: gcc build active file", "miDebuggerPath": "/usr/bin/gdb" diff --git a/.vscode/settings.json b/.vscode/settings.json index 3f0c39b..eba2745 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,9 +1,11 @@ { "files.associations": { + "*.html": "django-html", "signal.h": "c", "readcmd.h": "c", "stdlib.h": "c", "wait.h": "c", - "*.bak": "c" + "*.bak": "c", + "*.tcc": "c" } } \ No newline at end of file diff --git a/minishell b/minishell index 839a7712b26b0e6631cbb47cc54939fc86f90c94..a6d1e3b708419c8509f561d416e872284511cb89 100755 GIT binary patch literal 27168 zcmeHQf1Fd*mA@GX0>aFwfFmMA`Qe~44k`!;m>CEJ3p(;caV=&-l9`ESCe!>-U_r)) zv1Zdj`b%xKE!*x|f9}WHt!u5oC@!J8wP>x3Xxpjv#|xu&r0S;Dn*E-0?|pd*iQ7;2 zv-{7^)ycW%d(S!d+;e}t_wGwB+g&S{RoHAor(t5TAg<|Ti8xik?u{w~;uQ15SbRxsFlQL6Wz_LRek09p@ssEq^Sz8I6oBJIQOFSL;hKzU`Kq@tWERg&YF8sT{K*G z0n3wL_4uPPwfypRqM}Rm5~lTS!dAdnC>|o5NOm0lDD0&FgHhkAzvF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B{qCA>j6XIWx88` ztJXL0Y$K?lS>G7)@(g{m4`g7-2x^$A|9;T%YMc(^|1q7vfzz}e9$GkWp zLtmrT0~z{epTfXGBdB4f|KHI1j+-;JpoViChN7GJYblG5WwZQ7%3b&CJ>F8`S!z7#tkBJ397EJ9rB`iWq(KUEPxlsfEpN1)Q_V*T6r6oQOk*lje-;RtG|F|X;n}jj zlhNQaWx0QoNu%EE^*rN!l^HiXGG(vO`ntO+C7ic4s-)K$*c5K`4Sb*0cNBHv12?Kf zrd^|FG!MGEnRP07Sl^#Q*>R diff --git a/minishell.c b/minishell.c index de2ffe3..01e9e0b 100644 --- a/minishell.c +++ b/minishell.c @@ -27,6 +27,9 @@ char initcd[256], currentcd[256]; int file_in, file_out; +int pipes[256][2]; +int sous_fils[256]; + void handler_sigchld(int sig_num) { do @@ -34,7 +37,7 @@ void handler_sigchld(int sig_num) pid_fils = waitpid(-1, &wait_code, WNOHANG | WUNTRACED | WCONTINUED); if ((pid_fils == -1) && (errno != ECHILD)) { // wait fail ? - fprintf(stderr, "ERROR: waiting for child failed, (%d) %s\n", errno, strerror(errno)); + fprintf(stderr, "ERROR: waiting for %d failed, (%d) %s\n", pid_fils, errno, strerror(errno)); exit(errno); } @@ -127,6 +130,7 @@ int main(int argc, char *argv[]) cmd = readcmd(); prompting = 0; + // TODO: créer fonction "builtin" ? if (cmd == NULL) { // EOF break; @@ -222,33 +226,129 @@ int main(int argc, char *argv[]) continue; } - pid_fils = fork(); - if (pid_fils == -1) + // compter le nombre de commandes séparées par des pipes + int nb_pipe = -1; + char ***cursor = cmd->seq; + while (*cursor) + { + cursor++; + nb_pipe++; + } + if (nb_pipe < 0) + { // counting failed ? + fprintf(stderr, "ERROR: counting pipes failed"); + exit(1); + } + + if ((pid_fils = fork()) == -1) { // fork fail ? fprintf(stderr, "ERROR: forking failed, (%d) %s\n", errno, strerror(errno)); exit(errno); } - if (pid_fils == 0) { // instructions du fils action.sa_handler = SIG_IGN; - sigaction(SIGTSTP, &action, NULL); // on igonre SIGTSTP + sigaction(SIGTSTP, &action, NULL); // on ignore SIGTSTP sigaction(SIGINT, &action, NULL); // on ignore SIGINT if (cmd->in) - { + { // "<" file_in = open(cmd->in, O_RDONLY); dup2(file_in, 0); } if (cmd->out) - { + { // ">" file_out = open(cmd->out, O_CREAT | O_TRUNC | O_WRONLY, 0640); dup2(file_out, 1); } - execvp(cmd->seq[0][0], cmd->seq[0]); - fprintf(stderr, "ERROR: execvp failed, (%d) %s\n", errno, strerror(errno)); - exit(errno); // si execvp échoue on exit avec une erreur + if (nb_pipe > 0) + { // "|" présent(s) dans la commande + for (int i = 0; i <= nb_pipe; i++) + { // on crée itérativement nb_pipe fils et pipes + if (pipe(pipes[i]) < 0) + { // pipe failed ? + fprintf(stderr, "ERROR: pipe error, (%d) %s\n", errno, strerror(errno)); + exit(errno); + } + + if ((sous_fils[i] = fork()) < 0) + { // fork failed ? + fprintf(stderr, "ERROR: fork error, (%d) %s\n", errno, strerror(errno)); + exit(errno); + } + else if (sous_fils[i] == 0) + { // instructions des sous-fils + + if (i == 0) + { // premier sous-fils + close(pipes[0][0]); + } + else if (dup2(pipes[i - 1][0], STDIN_FILENO) == -1) + { // dup2 fail + fprintf(stderr, "ERROR: dup2 error, (%d) %s\n", errno, strerror(errno)); + exit(errno); + } + + if (i == nb_pipe) + { // dernier sous-fils + close(pipes[i][1]); + } + else if (dup2(pipes[i][1], STDOUT_FILENO) == -1) + { // dup2 fail + fprintf(stderr, "ERROR: dup2 error, (%d) %s\n", errno, strerror(errno)); + exit(errno); + } + + for (int j = 0; j <= i; j++) + { // on ferme les pipes non nécéssaires + if (j <= i - 2) + { // on ferme tous les pipes que l'on utilise pas + close(pipes[j][0]); + close(pipes[j][1]); + } + else if (j == i - 1) + { // on ferme l'écriture du pipe précédent + close(pipes[j][1]); + } + else if (j == i) + { // on ferme la lecture de son propre pipe + close(pipes[j][0]); + } + } + + execvp(cmd->seq[i][0], cmd->seq[i]); + fprintf(stderr, "ERROR: execvp failed, (%d) %s\n", errno, strerror(errno)); + exit(errno); // si execvp échoue on exit avec une erreur + } + } + for (int i = 0; i <= nb_pipe; i++) + { // on ferme tous les pipes pour le fils + close(pipes[i][0]); + close(pipes[i][1]); + } + for (int i = 0; i <= nb_pipe; i++) + { // on attend chaque sous-fils + pid_t id = waitpid(sous_fils[i], &wait_code, 0); + + if (id == -1) + { // wait fail ? + fprintf(stderr, "ERROR: waiting for %d failed, (%d) %s\n", wait_code, errno, strerror(errno)); + exit(errno); + } + if (wait_code) + { // execvp fail ? + fprintf(stderr, "ERROR: child failed, (%d) %s\n", wait_code, strerror(wait_code)); + } + } + exit(0); // on termine le fils + } + else + { // pas de piping + execvp(cmd->seq[0][0], cmd->seq[0]); + fprintf(stderr, "ERROR: execvp failed, (%d) %s\n", errno, strerror(errno)); + exit(errno); // si execvp échoue on exit avec une erreur + } } else { // instructions du père @@ -266,7 +366,6 @@ int main(int argc, char *argv[]) fprintf(stderr, "ERROR: waiting for %d failed, (%d) %s\n", wait_code, errno, strerror(errno)); exit(errno); } - if (wait_code) { // execvp fail ? fprintf(stderr, "ERROR: child failed, (%d) %s\n", wait_code, strerror(wait_code)); diff --git a/test.sh b/test.sh index 9359f1a..60e6a64 100644 --- a/test.sh +++ b/test.sh @@ -1,2 +1,2 @@ sleep 4 -printf "\n\n --- bonjour --- \n\n" \ No newline at end of file +printf "\n\n --- bonjour --- \n\n"