#include "logs-show.h"
#include "log.h"
#include "util.h"
+#include "utf8.h"
#define PRINT_THRESHOLD 128
-static bool contains_unprintable(const void *p, size_t l) {
- const char *j;
-
- for (j = p; j < (const char *) p + l; j++)
- if (*j < ' ' || *j >= 127)
- return true;
-
- return false;
-}
-
static int parse_field(const void *data, size_t length, const char *field, char **target, size_t *target_size) {
size_t fl, nl;
void *buf;
if (l > PRINT_THRESHOLD)
return false;
- if (contains_unprintable(p, l))
+ if (!utf8_is_printable_n(p, l))
return false;
return true;
if (show_all)
printf(": %.*s\n", (int) message_len, message);
- else if (contains_unprintable(message, message_len)) {
+ else if (!utf8_is_printable_n(message, message_len)) {
char bytes[FORMAT_BYTES_MAX];
printf(": [%s blob data]\n", format_bytes(bytes, sizeof(bytes), message_len));
} else if (message_len + n < n_columns)
SD_JOURNAL_FOREACH_DATA(j, data, length) {
if (!show_all && (length > PRINT_THRESHOLD ||
- contains_unprintable(data, length))) {
+ !utf8_is_printable_n(data, length))) {
const char *c;
char bytes[FORMAT_BYTES_MAX];
memcmp(data, "_BOOT_ID=", 9) == 0)
continue;
- if (contains_unprintable(data, length)) {
+ if (!utf8_is_printable_n(data, length)) {
const char *c;
uint64_t le64;
}
static void json_escape(const char* p, size_t l) {
-
- if (contains_unprintable(p, l)) {
+ if (!utf8_is_printable_n(p, l)) {
bool not_first = false;
fputs("[ ", stdout);
usec_t not_before,
unsigned how_many,
bool show_all,
- bool follow) {
+ bool follow,
+ bool warn_cutoff) {
char *m = NULL;
sd_journal *j = NULL;
int r;
- int fd;
unsigned line = 0;
bool need_seek = false;
if (r < 0)
goto finish;
- fd = sd_journal_get_fd(j);
- if (fd < 0)
- goto finish;
-
r = sd_journal_add_match(j, m, strlen(m));
if (r < 0)
goto finish;
goto finish;
}
+ if (warn_cutoff && line < how_many && not_before > 0) {
+ sd_id128_t boot_id;
+ usec_t cutoff;
+
+ /* Check whether the cutoff line is too early */
+
+ r = sd_id128_get_boot(&boot_id);
+ if (r < 0)
+ goto finish;
+
+ r = sd_journal_get_cutoff_monotonic_usec(j, boot_id, &cutoff, NULL);
+ if (r < 0)
+ goto finish;
+
+ if (not_before < cutoff)
+ printf("Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.\n");
+
+ warn_cutoff = false;
+ }
+
if (!follow)
break;
- r = fd_wait_for_event(fd, POLLIN, (usec_t) -1);
- if (r < 0)
- goto finish;
-
- r = sd_journal_process(j);
+ r = sd_journal_wait(j, (usec_t) -1);
if (r < 0)
goto finish;