]> ruderich.org/simon Gitweb - coloredstderr/coloredstderr.git/blob - README
constants.h: Fix indentation.
[coloredstderr/coloredstderr.git] / README
1 README
2 ======
3
4 coloredstderr is a small library which uses 'LD_PRELOAD' to color stderr.
5
6
7 Like all solutions using 'LD_PRELOAD' it only works with dynamically linked
8 binaries. Statically linked binaries, for example valgrind, are not supported.
9 setuid binaries are also not supported ('LD_PRELOAD' disabled for security
10 reasons).
11
12
13 It was inspired by stderred [2]. Similar solutions (using 'LD_PRELOAD')
14 include:
15
16 - stderred [1], but doesn't `follow' dups (I somehow missed it when looking
17   for existing implementations)
18 - stderred [2], but only hooks `write()`
19
20 [1]: https://github.com/sickill/stderred
21 [2]: https://github.com/trapd00r/stderred
22
23 Most other existing solutions use a second process which colors its input and
24 pipe stderr to it. However this creates different runtime behaviour resulting
25 in a different ordering of the output. Partial lines (no newline) also often
26 cause problems.
27
28
29 DEPENDENCIES
30 ------------
31
32 - C99 compiler (variable length arrays)
33 - dynamic linker/loader which supports 'LD_PRELOAD' (e.g. GNU/Linux's or
34   FreeBSD's ld.so)
35
36
37 INSTALLATION
38 ------------
39
40     ./configure && make && make check
41
42 Then either install the library with `make install` or just copy it from
43 `src/.libs/` to wherever you want to install it:
44
45     rm -f /destination/path/for/library/libcoloredstderr.so
46     cp -L src/.libs/libcoloredstderr.so /destination/path/for/library/
47
48 *Important:* If you install `libcoloredstderr.so` manually, make sure _not_ to
49 use plain `cp` to overwrite an existing `libcoloredstderr.so` file which is in
50 use! Doing so will crash most processes which were started with 'LD_PRELOAD'
51 set to this file. This is not a bug in coloredstderr, but a general problem.
52 `cp` truncates the file which causes the `mmap()` ed library to be in an
53 inconsistent state causing a segmentation fault when using any functions of
54 the library. Just remove the file first and then copy it. `make install`
55 handles the install in this way and is therefore not affected.
56
57 As a simple safeguard, `make` builds and installs the `libcoloredstderr.so`
58 file non-writable to prevent accidental overwrites. Even if the overwrite is
59 forced with `cp -f`, the file is unlinked and recreated by `cp` because the
60 file is non-writable, preventing the problem.
61
62
63 USAGE
64 -----
65
66 Set 'LD_PRELOAD' to include the _absolute_ path to `libcoloredstderr.so`:
67
68     LD_PRELOAD=/absolute/path/to/libcoloredstderr.so
69
70 The 'COLORED_STDERR_FDS' environment variable must be set to the file
71 descriptors which should be colored (comma separated list). Normally this is
72 just 2 (stderr):
73
74     COLORED_STDERR_FDS=2,
75
76 The trailing comma is important!
77
78
79 A default setup could look like this:
80
81     LD_PRELOAD="$HOME/bin/libcoloredstderr.so"
82     COLORED_STDERR_FDS=2,
83     export LD_PRELOAD COLORED_STDERR_FDS
84
85
86 The following additional environment variables are available:
87
88 - 'COLORED_STDERR_PRE'
89   String to write before each write to stderr, defaults to "\033[31m" (red).
90 - 'COLORED_STDERR_POST'
91   String to write after each write to stderr, defaults to "\033[0m" (reset
92   color).
93 - 'COLORED_STDERR_FORCE_WRITE'
94   If set to an non-empty value add pre/post strings even when not writing to a
95   terminal, e.g. when writing to a file. By default, only writes to a terminal
96   are colored.
97 - 'COLORED_STDERR_IGNORED_BINARIES'
98   Comma separated list of binary names/paths which should not be tracked
99   (including their children). Useful for `reset` which writes to the terminal
100   but fails to work if the output is colored. See below for an example.
101
102 All environment variables starting with 'COLORED_STDERR_PRIVATE_*' are
103 internal variables used by the implementation and should not be set manually.
104 See the source for details.
105
106
107 To set custom colors as pre/post strings you can use the `$''` feature of Bash
108 and Zsh:
109
110     export COLORED_STDERR_PRE=$'\033[91m' # bright red
111     export COLORED_STDERR_POST=$'\033[0m' # default
112
113 Or to be more compatible you can use the following which should work in any
114 Bourne shell:
115
116     esc=`printf '\033'`
117     COLORED_STDERR_PRE="${esc}[91m" # bright red
118     COLORED_STDERR_POST="${esc}[0m" # default
119     export COLORED_STDERR_PRE COLORED_STDERR_POST
120
121 Fix `reset`; its writes to the terminal must be unaltered. `reset` is
122 symbolic-link to `tset` on some systems, adapt as necessary:
123
124     COLORED_STDERR_IGNORED_BINARIES=/usr/bin/tset
125     export COLORED_STDERR_IGNORED_BINARIES
126
127
128 DEBUG
129 -----
130
131 To enable debug mode, configure coloredstderr with '--enable-debug'.
132
133 *Important:* Debug mode enables `assert()`s in the code which might abort the
134 process using 'LD_PRELOAD' if an error condition is detected!
135
136 Debug mode is slower than normal mode. To log only warnings without the
137 overhead of debug mode use '--enable-warnings'. `assert()`s are not enabled
138 with '--enable-warnings', so it's safe to use.
139
140 Debug messages are appended to the file `colored_stderr_debug_log.txt` in the
141 current working directory _if_ it exists. Be careful, this file might grow
142 very quickly.
143
144 *Important:* Warnings are written to `$HOME/colored_stderr_warning_log.txt`
145 even if it _does not_ exist (only if debug or warning mode is enabled)! If it
146 doesn't exist it's created. An existing file isn't overwritten, but the
147 warnings are appended at the end.
148
149
150 KNOWN ISSUES
151 ------------
152
153 - `{fputc,putc,putchar}_unlocked()` are not hooked with glibc when writing to
154   stdout (which might be redirected to stderr). Can't be fixed as the compiler
155   inlines the code into the program without calling any function.
156 - Test `test_stdio.sh` fails on FreeBSD because it does handle the above
157   correctly (no inlining), but the test is designed for GNU/Linux.
158 - 'COLORED_STDERR_IGNORED_BINARIES' requires the `/proc` file system.
159   Suggestions welcome.
160 - Output of `strace` is not always colored correctly as the output from
161   `coloredstderr` is traced and displayed as well.
162
163
164 BUGS
165 ----
166
167 If you find any bugs not mentioned in this document please report them to
168 <simon@ruderich.org> with coloredstderr in the subject.
169
170
171 AUTHORS
172 -------
173
174 Written by Simon Ruderich <simon@ruderich.org>.
175
176
177 LICENSE
178 -------
179
180 coloredstderr is licensed under GPL version 3 or later.
181
182 Copyright (C) 2013  Simon Ruderich
183
184 This program is free software: you can redistribute it and/or modify
185 it under the terms of the GNU General Public License as published by
186 the Free Software Foundation, either version 3 of the License, or
187 (at your option) any later version.
188
189 This program is distributed in the hope that it will be useful,
190 but WITHOUT ANY WARRANTY; without even the implied warranty of
191 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
192 GNU General Public License for more details.
193
194 You should have received a copy of the GNU General Public License
195 along with this program.  If not, see <http://www.gnu.org/licenses/>.