summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/logs-show.c14
-rw-r--r--src/shared/macro.h1
-rw-r--r--src/shared/util.h5
3 files changed, 11 insertions, 9 deletions
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index 43386841ba..8897a10c2b 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -941,7 +941,7 @@ int show_journal_by_unit(
OutputFlags flags,
bool system) {
- sd_journal *j = NULL;
+ sd_journal _cleanup_journal_close_ *j = NULL;
int r;
int jflags = SD_JOURNAL_LOCAL_ONLY | system * SD_JOURNAL_SYSTEM_ONLY;
@@ -954,24 +954,20 @@ int show_journal_by_unit(
r = sd_journal_open(&j, jflags);
if (r < 0)
- goto finish;
+ return r;
if (system)
r = add_matches_for_unit(j, unit);
else
r = add_matches_for_user_unit(j, unit, uid);
if (r < 0)
- goto finish;
+ return r;
r = show_journal(f, j, mode, n_columns, not_before, how_many, flags);
if (r < 0)
- goto finish;
-
-finish:
- if (j)
- sd_journal_close(j);
+ return r;
- return r;
+ return 0;
}
static const char *const output_mode_table[_OUTPUT_MODE_MAX] = {
diff --git a/src/shared/macro.h b/src/shared/macro.h
index 055919048c..90a663b9ce 100644
--- a/src/shared/macro.h
+++ b/src/shared/macro.h
@@ -203,6 +203,7 @@ static inline size_t IOVEC_INCREMENT(struct iovec *i, unsigned n, size_t k) {
#define _cleanup_set_free_ __attribute__((cleanup(set_freep)))
#define _cleanup_set_free_free_ __attribute__((cleanup(set_free_freep)))
#define _cleanup_strv_free_ __attribute__((cleanup(strv_freep)))
+#define _cleanup_journal_close_ __attribute__((cleanup(journal_closep)))
#define VA_FORMAT_ADVANCE(format, ap) \
do { \
diff --git a/src/shared/util.h b/src/shared/util.h
index 8ac4bbc249..4be0b61773 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -36,6 +36,7 @@
#include <dirent.h>
#include <sys/resource.h>
#include <stddef.h>
+#include <systemd/sd-journal.h>
#include "macro.h"
#include "time-util.h"
@@ -531,6 +532,10 @@ static inline void umaskp(mode_t *u) {
umask(*u);
}
+static inline void journal_closep(sd_journal **j) {
+ sd_journal_close(*j);
+}
+
_malloc_ static inline void *malloc_multiply(size_t a, size_t b) {
if (_unlikely_(b == 0 || a > ((size_t) -1) / b))
return NULL;