summaryrefslogtreecommitdiff
path: root/src/shared/logs-show.c
AgeCommit message (Collapse)AuthorFilesLines
2019-11-04tree-wide: drop time.h when time-util.h is includedYu Watanabe1-1/+0
2019-11-04tree-wide: drop string.h when string-util.h or friends are includedYu Watanabe1-1/+0
2019-07-15tree-wide: drop duplicated blank linesYu Watanabe1-1/+0
``` $ for i in */*.[ch] */*/*.[ch]; do sed -e '/^$/ {N; s/\n$//g}' -i $i; done $ git checkout HEAD -- basic/linux shared/linux ```
2019-07-10shared/logs-show: urlify CONFIG_FILE in verbose modeZbigniew Jędrzejewski-Szmek1-5/+15
Now all short-*, verbose, with-unit modes are handled. cat, export, json-* are not, but those are usually used for post-processing, so I don't think it'd be useful there.
2019-07-10shared/logs-show: urlify CONFIG_FILE in short modeZbigniew Jędrzejewski-Szmek1-3/+34
v2: - check that the filename is terminated by ':', ' ', or EOS - fix grep highlight overlap check
2019-07-02shared/logs-show: indentationZbigniew Jędrzejewski-Szmek1-14/+14
2019-05-17shared/logs-show: show audit logs in blueZbigniew Jędrzejewski-Szmek1-6/+19
Audit logs always have _TRANSPORT=audit and no PRIORITY= field set. This means that they are shown in the default foreground color. There can be quite a lot of them, and they often repeat the same information that is already logged by applications, leading to a "wall of text" effect. Let's mark them with a different color. This splits the logs visually into "normal logs" and "audit logs".
2019-05-08basic/log: use colors to highlight messages like journalctlZbigniew Jędrzejewski-Szmek1-15/+2
2019-03-13util: split out namespace related stuff into a new namespace-util.[ch] pairLennart Poettering1-0/+1
Just some minor reorganiztion.
2019-01-17tree-wide: use '"' instead of '\"'Louis Taylor1-2/+2
The escape used previously was redundant and made things more confusing.
2018-12-05logs-show: use grey color for de-emphasizing journal log outputLennart Poettering1-0/+4
2018-12-04Merge pull request #11042 from yuwata/tiny-coding-style-fixesLennart Poettering1-1/+1
Tiny coding style fixes
2018-12-04tree-wide: add whitespace between type and variable nameYu Watanabe1-1/+1
2018-12-03output-mode: add generic helper to pick right JsonFormatFlags for given ↵Lennart Poettering1-4/+1
OutputMode
2018-11-22coccinelle: make use of SYNTHETIC_ERRNOZbigniew Jędrzejewski-Szmek1-28/+21
Ideally, coccinelle would strip unnecessary braces too. But I do not see any option in coccinelle for this, so instead, I edited the patch text using search&replace to remove the braces. Unfortunately this is not fully automatic, in particular it didn't deal well with if-else-if-else blocks and ifdefs, so there is an increased likelikehood be some bugs in such spots. I also removed part of the patch that coccinelle generated for udev, where we returns -1 for failure. This should be fixed independently.
2018-11-13tree-wide: port over other candidates for namespace_fork()Lennart Poettering1-6/+3
Let's always use the same, correct, way to join a namespace.
2018-10-11journalctl: port JSON output mode to new JSON APILennart Poettering1-157/+178
Also, while we are at it, beef it up, by adding json-seq support (i.e. https://tools.ietf.org/html/rfc7464). This is particularly useful in conjunction with jq's --seq switch.
2018-10-09logs-show: make highlight parameter const (#10311)Lennart Poettering1-7/+7
2018-06-14tree-wide: remove Lennart's copyright linesLennart Poettering1-3/+0
These lines are generally out-of-date, incomplete and unnecessary. With SPDX and git repository much more accurate and fine grained information about licensing and authorship is available, hence let's drop the per-file copyright notice. Of course, removing copyright lines of others is problematic, hence this commit only removes my own lines and leaves all others untouched. It might be nicer if sooner or later those could go away too, making git the only and accurate source of authorship information.
2018-06-14tree-wide: drop 'This file is part of systemd' blurbLennart Poettering1-2/+0
This part of the copyright blurb stems from the GPL use recommendations: https://www.gnu.org/licenses/gpl-howto.en.html The concept appears to originate in times where version control was per file, instead of per tree, and was a way to glue the files together. Ultimately, we nowadays don't live in that world anymore, and this information is entirely useless anyway, as people are very welcome to copy these files into any projects they like, and they shouldn't have to change bits that are part of our copyright header for that. hence, let's just get rid of this old cruft, and shorten our codebase a bit.
2018-05-31journal-remote: do not send _BOOT_ID twiceZbigniew Jędrzejewski-Szmek1-5/+4
Also remove the comma from the comment everywhere, I think the comma unnecessarilly put emphasis on the clause after the comma. Fixes #9090. Reproducer: systemd-journal-remote --split-mode=none -o /tmp/msg6.journal --trust=all --listen-http=8080 systemd-journal-upload -u http://localhost:8080 journalctl --file /tmp/msg6.journal -o verbose -n1
2018-05-31shared/logs-show: be more careful before using a _SOURCE_REALTIME_TIMESTAMP ↵Zbigniew Jędrzejewski-Szmek1-3/+1
entry journalctl -o short would display those entries, but journalctl -o short-full would refuse. If the entry is bad, just fall back to the receive-side realtime timestamp like we would if it was completely missing.
2018-05-31Always allow timestamps to be printedZbigniew Jędrzejewski-Szmek1-6/+1
If the timestamp is above 9999-12-30, (or 2038-something-something on 32 bit), use XXXX-XX-XX XX:XX:XX as the replacement. The problem with refusing to print timestamps is that our code accepts such timestamps, so we can't really just refuse to process them afterwards. Also, it makes journal files non-portable, because suddently we might completely refuse to print entries which are totally OK on a different machine.
2018-05-31shared/logs-show: use _cleanup_Zbigniew Jędrzejewski-Szmek1-21/+7
2018-05-31shared/logs-show: fix mixup between length-based memory duplication and ↵Zbigniew Jędrzejewski-Szmek1-2/+2
string operations We'd look for a '=' separator using memchr, i.e. ignoring any nul bytes in the string, but then do a strndup, which would terminate on any nul byte, and then again do a memcmp, which would access memory past the chunk allocated by strndup. Of course, we probably shouldn't allow keys with nul bytes in them. But we currently do, so there might be journal files like that out there. So let's fix the journal-reading code first.
2018-05-31shared/logs-show: export show_journal()Zbigniew Jędrzejewski-Szmek1-15/+20
This is a nice function to output some journal entries without much ado.
2018-05-31journal: rename output_journal to show_journal_entryZbigniew Jędrzejewski-Szmek1-2/+2
We have show_journal, and output_journal, and it's not immediately clear how they related. Rename the first to show that it just prints one entry.
2018-05-30tree-wide: make use of memory_startswith() at various placesLennart Poettering1-6/+3
2018-05-25journalctl: add with-unit modeLuca Boccassi1-5/+20
When dealing with a large number of template instances, for example when launching daemons per VRF, it is hard for operators to correlate log lines to arguments. Add a new with-unit mode which, if available, prefixes unit and user unit names when displaying its log messages instead of the syslog identifier. It will also use the full timestamp with timezones, like the short-full mode.
2018-04-19tree-wide: drop spurious newlines (#8764)Lennart Poettering1-2/+0
Double newlines (i.e. one empty lines) are great to structure code. But let's avoid triple newlines (i.e. two empty lines), quadruple newlines, quintuple newlines, …, that's just spurious whitespace. It's an easy way to drop 121 lines of code, and keeps the coding style of our sources a bit tigther.
2018-04-06tree-wide: drop license boilerplateZbigniew Jędrzejewski-Szmek1-13/+0
Files which are installed as-is (any .service and other unit files, .conf files, .policy files, etc), are left as is. My assumption is that SPDX identifiers are not yet that well known, so it's better to retain the extended header to avoid any doubt. I also kept any copyright lines. We can probably remove them, but it'd nice to obtain explicit acks from all involved authors before doing that.
2018-01-28Merge pull request #7881 from keszybz/pcreLennart Poettering1-17/+73
Add new --grep option to journalctl
2018-01-28journalctl: add highlighting for matched substringZbigniew Jędrzejewski-Szmek1-17/+73
Red is used for highligting, the same as grep does. Except when the line is highlighted red already, because it has high priority, in which case plain ansi highlight is used for the matched substring. Coloring is implemented for short and cat outputs, and not for other types. I guess we could also add it for verbose output in the future.
2018-01-22journal: Fix journal dumping for json, cat and export outputArmin Widegreen1-0/+13
Incorporating the fix from d00f1d57 into other output formats of journalctl. If journal files are corrupted, e.g. not cleanly closed, some journal entries can not be read by output options other than 'short' (default). If such entries has been identified, they will now just be skipped.
2018-01-04tree-wide: make use of wait_for_terminate_and_check() at various placesLennart Poettering1-4/+5
Using wait_for_terminate_and_check() instead of wait_for_terminate() let's us simplify, shorten and unify the return value checking and logging of waitid(). Hence, let's use it all over the place.
2017-12-25tree-wide: introduce new safe_fork() helper and port everything overLennart Poettering1-5/+4
This adds a new safe_fork() wrapper around fork() and makes use of it everywhere. The new wrapper does a couple of things we previously did manually and separately in a safer, more correct and automatic way: 1. Optionally resets signal handlers/mask in the child 2. Sets a name on all processes we fork off right after forking off (and the patch assigns useful names for all processes we fork off now, following a systematic naming scheme: always enclosed in () – in order to indicate that these are not proper, exec()ed processes, but only forked off children, and if the process is long-running with only our own code, without execve()'ing something else, it gets am "sd-" prefix.) 3. Optionally closes all file descriptors in the child 4. Optionally sets a PR_SET_DEATHSIG to SIGTERM in the child, in a safe way so that the parent dying before this happens being handled safely. 5. Optionally reopens the logs 6. Optionally connects stdin/stdout/stderr to /dev/null 7. Debug logs about the forked off processes.
2017-12-15tree-wide: add DEBUG_LOGGING macro that checks whether debug logging is on ↵Lennart Poettering1-1/+1
(#7645) This makes things a bit easier to read I think, and also makes sure we always use the _unlikely_ wrapper around it, which so far we used sometimes and other times we didn't. Let's clean that up.
2017-12-14tree-wide: make use of new STRLEN() macro everywhere (#7639)Lennart Poettering1-1/+3
Let's employ coccinelle to do this for us. Follow-up for #7625.
2017-11-19Add SPDX license identifiers to source files under the LGPLZbigniew Jędrzejewski-Szmek1-0/+1
This follows what the kernel is doing, c.f. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-10-27journalctl: add --output-fields= (#7181)Lars Karlitski1-22/+71
This option allows restricting the shown fields in the output modes that would normally show all fields. It allows clients that are only interested in a subset of the fields to access those more efficiently. Also, it makes the resulting size of the output more predictable. It has no effect on the various `short` output modes, because those already only show a subset of the fields.
2017-10-12shared: add vectorized parse_field() (#7056)Vito Caputo1-59/+48
By vectorizing parse_field() the chain of parse_field() calls in output_short() can be replaced with a single call receiving a description of the desired fields and their targets. While at it, eliminate the repeated strlen() calls performed on constant field names by making parse_field() receive the field length, and storing it in the ParseFieldVec at compile time. Also sort the output_short() fields so the short ones are tried first, for a minor efficiency gain. In addition to making the code less repetitive, gcc in my tests now inlines the parse_fieldv() call in output_short().
2017-10-04tree-wide: use IN_SET macro (#6977)Yu Watanabe1-1/+1
2017-07-31alloc-util: add new helpers memdup_suffix0() and newdup_suffix0()Lennart Poettering1-4/+3
These are similar to memdup() and newdup(), but reserve one extra NUL byte at the end of the new allocation and initialize it. It's useful when copying out data from fixed size character arrays where NUL termination can't be assumed.
2017-07-07shared: leave output_journal() output in buffer (#6304)Vito Caputo1-1/+0
e268b81e moved an fflush() from output_json() to the generic output_journal(), when it probably should have deleted all fflush() calls from logs-show.c altogether. The caller supplies the FILE * to these functions, and should be in charge of flushing as needed. The current implementation essentially defeats any buffering stdio was bringing to the table, resulting in extraneous tiny write() calls in commands like `journalctl -b`. This commit removes the fflush() call from output_journal(), and adds them to journalctl before waiting for more entries and at completion. This way in the hot path when journalctl loops on entries stdio can combine multiple entries into bulkier write() calls.
2017-05-19shared/logs-show: avoid printing "(null)" when timestamp is not specifiedZbigniew Jędrzejewski-Szmek1-3/+4
$ perl -e 'print("MESSAGE\n", pack("q<", 1), "A\n\nMESSAGE=test2\n")' > message.bin $ systemd-journal-remote -o /tmp/out.journal message.bin $ journalctl -o export --file /tmp/out.journal __CURSOR=s=b16c464c2db44384b29e75a564d8388e;i=1;b=6b0be47627bd4932913dc126012c21c0;m=0;t=0;x=b04263a253e357a __REALTIME_TIMESTAMP=0 __MONOTONIC_TIMESTAMP=0 _BOOT_ID=6b0be47627bd4932913dc126012c21c0 MESSAGE=A $ journalctl -o verbose --file /tmp/out.journal (null) [s=b16c464c2db44384b29e75a564d8388e;i=1;b=6b0be47627bd4932913dc126012c21c0;m=0;t=0;x=b04263a253e357a] MESSAGE=A This is changed to $ build/journalctl -o verbose --file /tmp/out.journal (no timestamp) [s=b16c464c2db44384b29e75a564d8388e;i=1;b=6b0be47627bd4932913dc126012c21c0;m=0;t=0;x=b04263a253e357a] MESSAGE=A We should deal gracefully with unexpected input.
2017-05-07Add short-iso-precise for journalctl output (#5884)Ian Wienand1-1/+14
This adds a short-iso-precise option for journalctl output. It is similar to short-iso, but includes microseconds.
2017-02-02time-util: refuse formatting/parsing times that we can't storeLennart Poettering1-0/+5
usec_t is always 64bit, which means it can cover quite a number of years. However, 4 digit year display and glibc limitations around time_t limit what we can actually parse and format. Let's make this explicit, so that we never end up formatting dates we can#t parse and vice versa. Note that this is really just about formatting/parsing. Internal calculations with times outside of the formattable range are not affected.
2016-11-07tree-wide: add PRI_[NU]SEC, and use time format strings moreZbigniew Jędrzejewski-Szmek1-6/+3
2016-11-07Rename formats-util.h to format-util.hZbigniew Jędrzejewski-Szmek1-1/+1
We don't have plural in the name of any other -util files and this inconsistency trips me up every time I try to type this file name from memory. "formats-util" is even hard to pronounce.
2016-11-03journalctl: fix memleakEvgeny Vereshchagin1-1/+1
bash-4.3# journalctl --no-hostname >/dev/null ================================================================= ==288==ERROR: LeakSanitizer: detected memory leaks Direct leak of 48492 byte(s) in 2694 object(s) allocated from: #0 0x7fb4aba13e60 in malloc (/lib64/libasan.so.3+0xc6e60) #1 0x7fb4ab5b2cc4 in malloc_multiply src/basic/alloc-util.h:70 #2 0x7fb4ab5b3194 in parse_field src/shared/logs-show.c:98 #3 0x7fb4ab5b4918 in output_short src/shared/logs-show.c:347 #4 0x7fb4ab5b7cb7 in output_journal src/shared/logs-show.c:977 #5 0x5650e29cd83d in main src/journal/journalctl.c:2581 #6 0x7fb4aabdb730 in __libc_start_main (/lib64/libc.so.6+0x20730) SUMMARY: AddressSanitizer: 48492 byte(s) leaked in 2694 allocation(s). Closes: #4568