X-Git-Url: https://ruderich.org/simon/gitweb/?p=coloredstderr%2Fcoloredstderr.git;a=blobdiff_plain;f=tests%2Fexample_exec.c;h=1220f853618bd326539de885c8f58735c31327f2;hp=bd12b5a71f7b5f5ce42436144d966b5a192e3e6c;hb=219a9882ba55e2dc60f0ab40a2a3afcc7130417c;hpb=afca2864dc6464201dfe32134ae20e0107297836 diff --git a/tests/example_exec.c b/tests/example_exec.c index bd12b5a..1220f85 100644 --- a/tests/example_exec.c +++ b/tests/example_exec.c @@ -19,11 +19,15 @@ #include +/* For execvpe(). */ +#define _GNU_SOURCE + #include #include #include #include +#include "example.h" #include "../src/compiler.h" @@ -120,7 +124,7 @@ int main(int argc unused, char **argv) { printf("\nCHECKING COLORING.\n\n"); fflush(stdout); - dup2(2, 3); + xdup2(2, 3); char *args[] = { argv0, NULL }; char *envp[] = { ldpreload, NULL }; @@ -128,24 +132,24 @@ int main(int argc unused, char **argv) { execve(argv[0], args, envp); return EXIT_FAILURE; } else if (!skip--) { - dup2(2, 4); + xdup2(2, 4); execl(argv[0], argv0, NULL); return EXIT_FAILURE; } else if (!skip--) { - dup2(2, 5); + xdup2(2, 5); execlp(argv[0], argv0, NULL); return EXIT_FAILURE; } else if (!skip--) { - dup2(2, 6); + xdup2(2, 6); char *envp[] = { ldpreload, NULL }; execle(argv[0], argv0, NULL, envp); return EXIT_FAILURE; } else if (!skip--) { - dup2(2, 7); + xdup2(2, 7); /* Test closing a few descriptors. */ close(5); @@ -156,7 +160,7 @@ int main(int argc unused, char **argv) { execv(argv[0], args); return EXIT_FAILURE; } else if (!skip--) { - dup2(2, 8); + xdup2(2, 8); /* And a few more. */ close(7); @@ -166,9 +170,38 @@ int main(int argc unused, char **argv) { execvp(argv[0], args); return EXIT_FAILURE; - } else { + + /* Test handling of COLORED_STDERR_FDS. */ + + } else if (!skip--) { + /* And the rest. */ close(3); close(8); + + xdup2(2, 5); + + char *args[] = { argv0, NULL }; + char *envp[] = { ldpreload, "COLORED_STDERR_FDS=5,", NULL }; + + execve(argv[0], args, envp); + return EXIT_FAILURE; + } else if (!skip--) { + char *args[] = { argv0, NULL }; + char *envp[] = { ldpreload, NULL }; + + xdup2(5, 6); + close(5); + + execve(argv[0], args, envp); + return EXIT_FAILURE; + } else if (!skip--) { + close(6); + + char *args[] = { argv0, NULL }; + setenv("COLORED_STDERR_FDS", "2,", 1); + + execv(argv[0], args); + return EXIT_FAILURE; } @@ -269,6 +302,35 @@ int main(int argc unused, char **argv) { execvp(argv[0], args); return EXIT_FAILURE; + +#ifdef HAVE_EXECVPE + /* execvpe(3), but not testing the p(ath) part */ + } else if (!skip--) { + char *args[] = { argv0, NULL }; + char *envp[] = { "TEST=54", ldpreload, NULL }; + + execvpe(argv[0], args, envp); + return EXIT_FAILURE; + } else if (!skip--) { + char *args[] = { argv0, "foo", "bar", NULL }; + char *envp[] = { "TEST=55", ldpreload, NULL }; + + execvpe(argv[0], args, envp); + return EXIT_FAILURE; +#else + /* Fake output to let the test pass. */ + } else if (!skip--) { + puts("argv[0] = |./example_exec|"); + puts("environ[0] = |TEST=54|"); + puts("environ[2] = |COLORED_STDERR_PRIVATE_FDS=2,|"); + puts(""); + puts("argv[0] = |./example_exec|"); + puts("argv[1] = |foo|"); + puts("argv[2] = |bar|"); + puts("environ[0] = |TEST=55|"); + puts("environ[2] = |COLORED_STDERR_PRIVATE_FDS=2,|"); + puts(""); +#endif } printf("Done.\n");