summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-06-07 11:00:35 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-06-07 11:22:15 +0200
commit85b0ff8abf29cd90d02ef22bac036b370e4d5b59 (patch)
tree7ae170cc1e3418d8c0cbd02dbf2480a109e9e5b3 /src
parentsd-hwdb: fix NULL arg to %s in error messages (diff)
downloadsystemd-85b0ff8abf29cd90d02ef22bac036b370e4d5b59.tar.xz
systemd-85b0ff8abf29cd90d02ef22bac036b370e4d5b59.zip
sd-journal: fix NULL arg to %s in error messages and hashmap lookup
The lookup "works", but is not useful. It was introduced in 9c66f528138f4fc856b3e9e137245b7048d5747d. And printf will NULL args is invalid was introduced in 5d1ce25728856956c1fbfe05b491067f83bd2216 when support for fds was initally added :(
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd/sd-journal/sd-journal.c50
1 files changed, 28 insertions, 22 deletions
diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c
index 705a35de3f..5a94a51377 100644
--- a/src/libsystemd/sd-journal/sd-journal.c
+++ b/src/libsystemd/sd-journal/sd-journal.c
@@ -1277,6 +1277,7 @@ static int add_any_file(
assert(fd >= 0 || path);
if (fd < 0) {
+ assert(path); /* For gcc. */
if (j->toplevel_fd >= 0)
/* If there's a top-level fd defined make the path relative, explicitly, since otherwise
* openat() ignores the first argument. */
@@ -1299,53 +1300,58 @@ static int add_any_file(
}
if (fstat(fd, &st) < 0) {
- r = log_debug_errno(errno, "Failed to fstat file '%s': %m", path);
+ r = log_debug_errno(errno, "Failed to fstat %s: %m", path ?: "fd");
goto finish;
}
r = stat_verify_regular(&st);
if (r < 0) {
- log_debug_errno(r, "Refusing to open '%s', as it is not a regular file.", path);
+ log_debug_errno(r, "Refusing to open %s: %m", path ?: "fd");
goto finish;
}
- f = ordered_hashmap_get(j->files, path);
- if (f) {
- if (stat_inode_same(&f->last_stat, &st)) {
-
- /* We already track this file, under the same path and with the same device/inode numbers, it's
- * hence really the same. Mark this file as seen in this generation. This is used to GC old
- * files in process_q_overflow() to detect journal files that are still there and discern them
- * from those which are gone. */
+ if (path) {
+ f = ordered_hashmap_get(j->files, path);
+ if (f) {
+ if (stat_inode_same(&f->last_stat, &st)) {
+ /* We already track this file, under the same path and with the same
+ * device/inode numbers, it's hence really the same. Mark this file as seen
+ * in this generation. This is used to GC old files in process_q_overflow()
+ * to detect journal files that are still there and discern them from those
+ * which are gone. */
+
+ f->last_seen_generation = j->generation;
+ r = 0;
+ goto finish;
+ }
- f->last_seen_generation = j->generation;
- r = 0;
- goto finish;
+ /* So we tracked a file under this name, but it has a different inode/device. In that
+ * case, it got replaced (probably due to rotation?), let's drop it hence from our
+ * list. */
+ remove_file_real(j, f);
+ f = NULL;
}
-
- /* So we tracked a file under this name, but it has a different inode/device. In that case, it got
- * replaced (probably due to rotation?), let's drop it hence from our list. */
- remove_file_real(j, f);
- f = NULL;
}
if (ordered_hashmap_size(j->files) >= JOURNAL_FILES_MAX) {
- log_debug("Too many open journal files, not adding %s.", path);
+ log_debug("Too many open journal files, not adding %s.", path ?: "fd");
r = -ETOOMANYREFS;
goto finish;
}
r = journal_file_open(fd, path, O_RDONLY, 0, 0, 0, NULL, j->mmap, NULL, &f);
if (r < 0) {
- log_debug_errno(r, "Failed to open journal file %s: %m", path);
+ log_debug_errno(r, "Failed to open journal file %s: %m", path ?: "from fd");
goto finish;
}
/* journal_file_dump(f); */
+ /* journal_file_open() generates an replacement fname if necessary, so we can use f->path. */
r = ordered_hashmap_put(j->files, f->path, f);
if (r < 0) {
- f->close_fd = false; /* make sure journal_file_close() doesn't close the caller's fd (or our own). We'll let the caller do that, or ourselves */
+ f->close_fd = false; /* Make sure journal_file_close() doesn't close the caller's fd
+ * (or our own). The caller or we will do that ourselves. */
(void) journal_file_close(f);
goto finish;
}
@@ -1368,7 +1374,7 @@ finish:
safe_close(fd);
if (r < 0) {
- k = journal_put_error(j, r, path);
+ k = journal_put_error(j, r, path); /* path==NULL is OK. */
if (k < 0)
return k;
}