perfect mmmmm

This commit is contained in:
Laureηt 2021-05-23 16:23:44 +02:00
parent d24359b275
commit 6f30c8aa00

View file

@ -89,7 +89,7 @@ int main(int argc, char *argv[])
} }
if ((pid_fils = fork()) == -1) if ((pid_fils = fork()) == -1)
{ // fork fail ? { // fork failed ?
fprintf(stderr, "ERROR: forking failed, (%d) %s\n", errno, strerror(errno)); fprintf(stderr, "ERROR: forking failed, (%d) %s\n", errno, strerror(errno));
exit(errno); exit(errno);
} }
@ -133,7 +133,7 @@ int main(int argc, char *argv[])
close(pipes[0][0]); close(pipes[0][0]);
} }
else if (dup2(pipes[i - 1][0], STDIN_FILENO) == -1) else if (dup2(pipes[i - 1][0], STDIN_FILENO) == -1)
{ // dup2 fail { // dup2 failed ?
fprintf(stderr, "ERROR: dup2 error, (%d) %s\n", errno, strerror(errno)); fprintf(stderr, "ERROR: dup2 error, (%d) %s\n", errno, strerror(errno));
exit(errno); exit(errno);
} }
@ -143,7 +143,7 @@ int main(int argc, char *argv[])
close(pipes[i][1]); close(pipes[i][1]);
} }
else if (dup2(pipes[i][1], STDOUT_FILENO) == -1) else if (dup2(pipes[i][1], STDOUT_FILENO) == -1)
{ // dup2 fail { // dup2 failed ?
fprintf(stderr, "ERROR: dup2 error, (%d) %s\n", errno, strerror(errno)); fprintf(stderr, "ERROR: dup2 error, (%d) %s\n", errno, strerror(errno));
exit(errno); exit(errno);
} }
@ -178,12 +178,12 @@ int main(int argc, char *argv[])
for (int i = 0; i <= nb_pipe; i++) for (int i = 0; i <= nb_pipe; i++)
{ // on attend chaque sous-fils { // on attend chaque sous-fils
if (waitpid(sous_fils[i], &wait_code, 0) == -1) if (waitpid(sous_fils[i], &wait_code, 0) == -1)
{ // wait fail ? { // wait failed ?
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));
exit(errno); exit(errno);
} // TODO: factoriser dans une fonction, cf dessous ? } // TODO: factoriser dans une fonction, cf dessous ?
if (wait_code) if (wait_code)
{ // execvp fail ? { // execvp failed ?
fprintf(stderr, "ERROR: child failed, (%d) %s\n", wait_code, strerror(wait_code)); fprintf(stderr, "ERROR: child failed, (%d) %s\n", wait_code, strerror(wait_code));
} }
} }
@ -206,12 +206,12 @@ int main(int argc, char *argv[])
else else
{ // foreground { // foreground
if (waitpid(pid_fils, &wait_code, 0) == -1) if (waitpid(pid_fils, &wait_code, 0) == -1)
{ // wait fail ? { // wait failed ?
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));
exit(errno); exit(errno);
} }
if (wait_code) if (wait_code)
{ // execvp fail ? { // execvp failed ?
fprintf(stderr, "ERROR: child failed, (%d) %s\n", wait_code, strerror(wait_code)); fprintf(stderr, "ERROR: child failed, (%d) %s\n", wait_code, strerror(wait_code));
} }
} }