mirror of
https://github.com/FAUSheppy/colorredstderr-mirror
synced 2025-12-09 16:38:32 +01:00
Overwrite tracked file descriptors when exporting COLORED_STDERR_FDS.
If the list of tracked file descriptors is modified to contain unwanted values (e.g. when a parent process closes or redirects stderr), this makes it possible to set the tracked file descriptors back to a given list. This problem occurred with startx which somehow closes or redirects stderr. As COLORED_STDERR_FDS was set in the shell running startx, this disabled coloring stderr for all processes started in the X11 session. This is no longer an issue. As COLORED_STDERR_FDS is set in the shell configuration file, it automatically sets the list to the correct value when a shell is opened in the terminal emulator once X11 is running.
This commit is contained in:
@@ -169,9 +169,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);
|
||||
|
||||
dup2(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 };
|
||||
|
||||
dup2(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;
|
||||
}
|
||||
|
||||
|
||||
@@ -292,13 +321,13 @@ int main(int argc unused, char **argv) {
|
||||
} else if (!skip--) {
|
||||
puts("argv[0] = |./example_exec|");
|
||||
puts("environ[0] = |TEST=54|");
|
||||
puts("environ[2] = |COLORED_STDERR_FDS=2,|");
|
||||
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_FDS=2,|");
|
||||
puts("environ[2] = |COLORED_STDERR_PRIVATE_FDS=2,|");
|
||||
puts("");
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user