summaryrefslogtreecommitdiffstats
path: root/src/shared/logs-show.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* tree-wide: drop doubled empty linesYu Watanabe2024-10-071-2/+0
|
* time-util: rework localtime_or_gmtime() into localtime_or_gmtime_usec()Lennart Poettering2024-09-051-44/+56
| | | | | | | | | | | | We typically want to deal in usec_t, hence let's change the prototype accordingly, and do proper range checks. Also, make sure are not confused by negative times. Do something similar for mktime_or_timegm(). This is a more comprehensive alternative to #34065 Replaces: #34065
* logs-show: extend journal_get_boots() and friends to find invocation IDsYu Watanabe2024-08-011-52/+190
| | | | Currently the extended features are not used, but will be used later.
* logs-show: introduce several helper functionsYu Watanabe2024-08-011-28/+62
| | | | Currently these are not used, but will be used later.
* logs-show: rename BootId -> LogIdYu Watanabe2024-08-011-37/+37
| | | | | | | The struct itself is generic, and can be used for other ID. Let's rename it to more generic one. No functional change, just refactoring and preparation for later commits.
* Revert "logs-show: use _SOURCE_MONOTONIC_TIMESTAMP when ↵Yu Watanabe2024-06-191-18/+10
| | | | | | | | | | | | _SOURCE_BOOTTIME_TIMESTAMP field exists" This reverts commit f5bdecba08fd3ee11bebc635ea9d17fd97bd33d7. Some kmsg sent before sleep may be received by systemd-journald after sleep. In that case, map_clock_usec() does not provide correct timestamp. So, _SOURCE_MONOTONIC_TIMESTAMP field is anyway unreliable. Let's not use the field.
* logs-show: use _SOURCE_MONOTONIC_TIMESTAMP when _SOURCE_BOOTTIME_TIMESTAMP ↵Yu Watanabe2024-06-181-10/+18
| | | | | | | field exists With the previous commit, now the _SOURCE_MONOTONIC_TIMESTAMP field is usable but only when _SOURCE_BOOTTIME_TIMESTAMP exists.
* logs-show: do not use _SOURCE_MONOTONIC_TIMESTAMP fieldYu Watanabe2024-06-181-0/+6
| | | | | | | | | | The timestamp is not in CLOCK_MONOTONIC, but CLOCK_BOOTTIME, while header monotonic timestamp is in CLOCK_MONOTONIC. Hence, we cannot adjust timestamp by comparing with header monotonic timestamp and _SOURCE_MONOTONIC_TIMESTAMP field. Fixes a regression caused by affde1d7e79a634ee6053dbd4a57b3b51b74c170. Fixes #33293.
* libsystemd: turn json.[ch] into a public APILennart Poettering2024-06-121-25/+25
| | | | | | | | | | | | | | | This is preparation for making our Varlink API a public API. Since our Varlink API is built on top of our JSON API we need to make that public first (it's a nice API, but JSON APIs there are already enough, this is purely about the Varlink angle). I made most of the json.h APIs public, and just placed them in sd-json.h. Sometimes I wasn't so sure however, since the underlying data structures would have to be made public too. If in doubt I didn#t risk it, and moved the relevant API to src/libsystemd/sd-json/json-util.h instead (without any sd_* symbol prefixes). This is mostly a giant search/replace patch.
* journalctl: make --list-boots support -n/--lines= optionYu Watanabe2024-05-101-3/+15
| | | | Also mention that -r/--reverse is supported by the command.
* logs-show: use GREEDY_REALLOC_APPEND()Yu Watanabe2024-05-101-3/+1
|
* logs-show: fix stored timestamp when advance_older is trueYu Watanabe2024-05-101-2/+2
| | | | | Currently, the parsed timestamp is only used when advance_older is false. Hence, this does not change any behavior. But, let's fix it anyway.
* journalctl: fix support of --boot=ID±offset formatYu Watanabe2024-05-101-48/+48
| | | | | | | | | | | Fixes a regression introduced by e44f06065bf20e8d0e4adacff61350ebd36f299e. After the offending commit, if a boot ID suffixed with an offset is specified to --boot=, the boot ID was ignored. This fixes the issue. To fix the issue, this merges journal_find_boot_by_id() and journal_find_boot_by_offset().
* logs-show: flush matches before and after finding bootsYu Watanabe2024-05-101-0/+5
| | | | | | | | | | | | Otherwise, if several matches already set, then the first seek to head or tail may move the cursor to an invalid place, hence they provide wrong ID(s). Also, reading journal after calling these function may provide unexpected data. Currently, the caller does not install any matches before calling the functions, and does not read any journal entry after journal_get_boots() succeeds or journal_find_boot_by_offset() succeeds with 0. Hence, this should not change any behavior. Just for safety.
* logs-show: add missing strempty()Yu Watanabe2024-05-101-1/+1
| | | | Follow-up for 8e976dc9209853d5d4d2db3016289f2a5ab99fd9.
* logs-show: drop uid argument from add_matches_for_user_units()Yu Watanabe2024-05-101-3/+3
| | | | | It is always equivalent to getuid(). Let's call getuid() in the function instead.
* logs-show: adjust source timestamp with header timestampYu Watanabe2024-05-011-43/+79
| | | | | | | | | | | | | | | Previously, _SOURCE_REALTIME_TIMESTAMP was only used for realtime timestamp, and _SOURCE_MONOTONIC_TIMESTAMP was for monotonic. This make these journal field used more aggressively. If we need realtime timestamp, but an entry has only _SOURCE_MONOTONIC_TIMESTAMP, then now realtime timestamp is calculated based on _SOURCE_MONOTONIC_TIMESTAMP and the header dual timestamp. Similary, monotonic timestamp is obtained from _SOURCE_REALTIME_TIMESTAMP and the header dual timestamp. This should change shown timestamps not so much in most cases, but may be improve the situation such as #32492.
* logs-show: make output_timestamp_realtime() only take realtime timestampYu Watanabe2024-05-011-25/+14
| | | | | No functional change, just refactoring and preparation for later commits.
* sd-journal: make sure sd_journal_add_match() also accepts SIZE_MAX as sizeLennart Poettering2024-04-101-6/+6
| | | | | | | | | | | | | | | | In many of our internal functions that take a pointer + a size we have introduced the rule that SIZE_MAX as size means: take strlen(). sd_journal_add_match() has something similar, but the special value is 0, not SIZE_MAX. This is a bit ugly, since a zero size data block is theoretically fine. The only reason sd_journal_add_match() gets away with using this special value is because valid matches must consist of at least 2 chars, hence cannot be zero. But let's make this more robust and less surprising when compared to the rest of our code, and *also* accept SIZE_MAX to mean strlen(). No actual code changes, just some clean-up.
* Merge pull request #31965 from yuwata/logs-show-cleanupsLuca Boccassi2024-03-271-76/+12
|\ | | | | logs-show: several cleanups
| * logs-show: read the current boot ID if nothing specified for add_match_boot_id()Yu Watanabe2024-03-261-3/+14
| | | | | | | | No functional change, just refactoring.
| * sd-id128: move get_boot_id_for_machine() to id128-util.cYu Watanabe2024-03-261-79/+4
| | | | | | | | | | | | | | And rename it to id128_get_boot_for_machine(). This also splits out id128_get_boot() from sd_id128_get_boot(), and make id128_get_boot_for_machine() use it.
* | shared/logs-show: restore infinite loop avoidance for corrupted journalsZbigniew Jędrzejewski-Szmek2024-03-271-1/+2
|/ | | | | | | Fixes a bug introduced in e44f06065bf20e8d0e4adacff61350ebd36f299e: it was supposed to be a refactoring, but unfortunately FOREACH_ARRAY is implemented using a for loop, so when the 'goto finish' was replaced by 'break', it only broke the inner loop, leading to a infinite loop.
* logs-show: use journal_add_matchf() and journal_add_match_pair()Yu Watanabe2024-03-251-50/+23
|
* logs-show: get timestamp and boot ID only when necessaryYu Watanabe2024-02-111-132/+121
| | | | | | | | | | | | | | | Previously, get_display_timestamp() is unconditionally called even if we will show logs in e.g. json format. This drops unnecessary call of get_display_timestamp(). This also makes journal fields in each entry parsed only once in output_short(). Still output_verbose() twice though. This should improve performance of dumping journals. Replaces #29365. Co-authored-by: Costa Tsaousis <costa@netdata.cloud>
* tree-wide: set SD_JOURNAL_ASSUME_IMMUTABLE where appropriateYu Watanabe2024-02-111-1/+4
| | | | Co-authored-by: Costa Tsaousis <costa@netdata.cloud>
* tree-wide: add short comments for namespace_open() and namespace_enter()Yu Watanabe2024-01-191-1/+1
| | | | Also use -EBADF when unspecified.
* journalctl: add --exclude-identifier optionSergei Zhmylev2024-01-041-0/+3
|
* process-util: add new FORK_DEATHSIG_SIGKILL flag, rename FORK_DEATHSIG → ↵Lennart Poettering2023-11-021-1/+1
| | | | | | | | | | | | | | | | | | FORK_DEATHSIG_SIGTERM Sometimes it makes sense to hard kill a client if we die. Let's hence add a third FORK_DEATHSIG flag for this purpose: FORK_DEATHSIG_SIGKILL. To make things less confusing this also renames FORK_DEATHSIG to FORK_DEATHSIG_SIGTERM to make clear it sends SIGTERM. We already had FORK_DEATHSIG_SIGINT, hence this makes things nicely symmetric. A bunch of users are switched over for FORK_DEATHSIG_SIGKILL where we know it's safe to abort things abruptly. This should make some kernel cases more robust, since we cannot get confused by signal masks or such. While we are at it, also fix a bunch of bugs where we didn't take FORK_DEATHSIG_SIGINT into account in safe_fork()
* fd-uitl: rename PIPE_EBADF → EBADF_PAIR, and add EBADF_TRIPLETLennart Poettering2023-10-261-1/+1
| | | | | | | | We use it for more than just pipe() arrays. For example also for socketpair(). Hence let's give it a generic name. Also add EBADF_TRIPLET to mirror this for things like stdin/stdout/stderr arrays, which we use a bunch of times.
* journalctl: find boot ID more gracefully in corrupted journalYu Watanabe2023-10-021-28/+99
| | | | | | | | | | | | | | | | In discover_next_boot(), first we find a new boot ID based on the value stored in the entry object. Then, find the tail (or head when we are going upwards) entry of the boot based on the _BOOT_ID= field data. If boot IDs of an entry in the entry object and _BOOT_ID field data are inconsistent, which may happen on corrupted journal, then previously discover_next_boot() failed with -ENODATA. This makes the function check if the two boot IDs in each entry are consistent, and skip the entry if not. Fixes the failure of `journalctl -b -1` for 'truncated' journal: https://github.com/systemd/systemd/pull/29334#issuecomment-1736567951
* show-logs: add assert and fix local variable typeнаб2023-09-281-3/+4
| | | | | Follows-up for: 0693e6b246053d31c0eb405c6abe9db8a4d00aaf #29355
* Merge pull request #29134 from nabijaczleweli/short-iso-timestampLuca Boccassi2023-09-271-12/+13
|\ | | | | journalctl -o short-iso[-precise]: timezone as +02:00 instead of +0200
| * journalctl -o short-iso[-precise]: timezone as +02:00 instead of +0200наб2023-09-261-12/+13
| |
* | logs-show: use sd_journal_step_one()Yu Watanabe2023-09-261-10/+4
| |
* | logs-show: move journal_find_boot_by_offset() and friends from journalctl.cYu Watanabe2023-09-261-0/+206
|/
* logs-show: use json_variant_append_array()Yu Watanabe2023-07-131-39/+26
|
* logs-show: Rename json_data to JsonData and add typedefDaan De Meyer2023-07-121-9/+9
|
* json: free array in json_variant_unref_many()Daan De Meyer2023-07-121-47/+41
| | | | | | This allows using it with CLEANUP_ARRAY(). For the 2 call sites where we don't need to free the array, we do a regular for loop calling json_variant_unref() instead.
* journalctl: add --truncate-newline optionzhmylove2023-06-161-0/+3
|
* logs-show: introduce add_match_boot_id() helper functionYu Watanabe2023-05-261-3/+11
|
* tree-wide: Handle EADDRNOTAVAIL as journal corruptionDaan De Meyer2023-05-021-6/+6
| | | | | Journal corruption is not only indicated by EBADMSG but also by EADDRNOTAVAIL so treat that as corruption in a few more cases.
* tree-wide: port various places to find_line_startswith()Lennart Poettering2023-03-241-8/+3
|
* logs-show: show seqnum info in export+json output modeLennart Poettering2023-02-081-7/+30
|
* logs-show: rename "ts" paramater/variable to "display_ts"Lennart Poettering2023-02-071-67/+93
| | | | | | | | | | | | | | | | When displaying log data we deal with two kind of timestamps: the one we use for display (typically the source timestamp if available), and the one we use internally (typically the reception timestamp of journald). The user-facing output modes generally use the display timestamp, the ones intended for further processing (i.e. json + export outputs) do not, and directly query the timestamps of the entry, ignoring the source. This gets a bit confusing, since it's not always clear why we use which timestamp where. Let's address that by renaming the generic "ts" parameter/variable to "display_ts" to emphasize that the stored timestamp are "corrected" timestamps for display only. No real code change, just some renaming.
* logs-show: add a splash of colour to verbose outputLennart Poettering2023-01-211-17/+32
|
* logs-show: minor modernizationsLennart Poettering2023-01-211-21/+27
|
* logs-show: move strlen() handling into update_json_data() so that we can use ↵Lennart Poettering2023-01-211-6/+11
| | | | SD_ID128_TO_STRING()
* journalctl: don't convert between strv/Set for each log lineLennart Poettering2023-01-201-7/+2
| | | | | | | | If output fields are specified, let's store this in a Set right-away, instead of converting between strv and Set again and again for each line. This is not only faster, but also simpler and shorter.
* logs-show: use json_variant_unref_many() where appropriateLennart Poettering2023-01-201-5/+1
|