journal,shared: add _cleanup_journal_close_
This commit is contained in:
@@ -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;
|
||||
return r;
|
||||
|
||||
finish:
|
||||
if (j)
|
||||
sd_journal_close(j);
|
||||
|
||||
return r;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *const output_mode_table[_OUTPUT_MODE_MAX] = {
|
||||
|
||||
@@ -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 { \
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user