summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/journal/coredumpctl.c1
-rw-r--r--src/journal/journal-internal.h6
-rw-r--r--src/journal/test-journal-enum.c1
-rw-r--r--src/shared/logs-show.c1
-rw-r--r--src/shared/macro.h12
-rw-r--r--src/shared/set.h3
-rw-r--r--src/shared/strv.h2
-rw-r--r--src/shared/util.c20
-rw-r--r--src/shared/util.h41
9 files changed, 44 insertions, 43 deletions
diff --git a/src/journal/coredumpctl.c b/src/journal/coredumpctl.c
index 99ca269327..97d967db3c 100644
--- a/src/journal/coredumpctl.c
+++ b/src/journal/coredumpctl.c
@@ -35,6 +35,7 @@
#include "path-util.h"
#include "pager.h"
#include "macro.h"
+#include "journal-internal.h"
static enum {
ACTION_NONE,
diff --git a/src/journal/journal-internal.h b/src/journal/journal-internal.h
index 3accf14c05..ff8b34a951 100644
--- a/src/journal/journal-internal.h
+++ b/src/journal/journal-internal.h
@@ -132,3 +132,9 @@ struct sd_journal {
char *journal_make_match_string(sd_journal *j);
void journal_print_header(sd_journal *j);
+
+static inline void journal_closep(sd_journal **j) {
+ sd_journal_close(*j);
+}
+
+#define _cleanup_journal_close_ _cleanup_(journal_closep)
diff --git a/src/journal/test-journal-enum.c b/src/journal/test-journal-enum.c
index 88f583e6c7..bd1f5199e5 100644
--- a/src/journal/test-journal-enum.c
+++ b/src/journal/test-journal-enum.c
@@ -25,6 +25,7 @@
#include "sd-journal.h"
#include "macro.h"
#include "util.h"
+#include "journal-internal.h"
int main(int argc, char *argv[]) {
unsigned n = 0;
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index 8897a10c2b..5700321215 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -30,6 +30,7 @@
#include "util.h"
#include "utf8.h"
#include "hashmap.h"
+#include "journal-internal.h"
#define PRINT_THRESHOLD 128
#define JSON_THRESHOLD 4096
diff --git a/src/shared/macro.h b/src/shared/macro.h
index 99dc733853..cca41a3f6a 100644
--- a/src/shared/macro.h
+++ b/src/shared/macro.h
@@ -45,6 +45,7 @@
#define _weakref_(x) __attribute__((weakref(#x)))
#define _introspect_(x) __attribute__((section("introspect." x)))
#define _alignas_(x) __attribute__((aligned(__alignof(x))))
+#define _cleanup_(x) __attribute__((cleanup(x)))
/* automake test harness */
#define EXIT_TEST_SKIP 77
@@ -214,17 +215,6 @@ static inline size_t IOVEC_INCREMENT(struct iovec *i, unsigned n, size_t k) {
return k;
}
-#define _cleanup_free_ __attribute__((cleanup(freep)))
-#define _cleanup_fclose_ __attribute__((cleanup(fclosep)))
-#define _cleanup_pclose_ __attribute__((cleanup(pclosep)))
-#define _cleanup_close_ __attribute__((cleanup(closep)))
-#define _cleanup_closedir_ __attribute__((cleanup(closedirp)))
-#define _cleanup_umask_ __attribute__((cleanup(umaskp)))
-#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 { \
int _argtypes[128]; \
diff --git a/src/shared/set.h b/src/shared/set.h
index 38c4b58a80..8864f7b34e 100644
--- a/src/shared/set.h
+++ b/src/shared/set.h
@@ -77,3 +77,6 @@ char **set_get_strv(Set *s);
#define SET_FOREACH_BACKWARDS(e, s, i) \
for ((i) = ITERATOR_LAST, (e) = set_iterate_backwards((s), &(i)); (e); (e) = set_iterate_backwards((s), &(i)))
+
+#define _cleanup_set_free_ _cleanup_(set_freep)
+#define _cleanup_set_free_free_ _cleanup_(set_free_freep)
diff --git a/src/shared/strv.h b/src/shared/strv.h
index 4cd3865e1d..92696b02fa 100644
--- a/src/shared/strv.h
+++ b/src/shared/strv.h
@@ -34,6 +34,8 @@ static inline void strv_freep(char ***l) {
strv_free(*l);
}
+#define _cleanup_strv_free_ _cleanup_(strv_freep)
+
char **strv_copy(char * const *l) _malloc_;
unsigned strv_length(char * const *l);
diff --git a/src/shared/util.c b/src/shared/util.c
index 4eb64934ee..53caa7f9e5 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -5277,26 +5277,6 @@ int get_home_dir(char **_h) {
return 0;
}
-void fclosep(FILE **f) {
- if (*f)
- fclose(*f);
-}
-
-void pclosep(FILE **f) {
- if (*f)
- pclose(*f);
-}
-
-void closep(int *fd) {
- if (*fd >= 0)
- close_nointr_nofail(*fd);
-}
-
-void closedirp(DIR **d) {
- if (*d)
- closedir(*d);
-}
-
bool filename_is_safe(const char *p) {
if (isempty(p))
diff --git a/src/shared/util.h b/src/shared/util.h
index 683ff5a4fe..3aac165e67 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -38,7 +38,6 @@
#include <stddef.h>
#include <unistd.h>
-#include <systemd/sd-journal.h>
#include "macro.h"
#include "time-util.h"
@@ -527,19 +526,37 @@ static inline void freep(void *p) {
free(*(void**) p);
}
-void fclosep(FILE **f);
-void pclosep(FILE **f);
-void closep(int *fd);
-void closedirp(DIR **d);
-static inline void umaskp(mode_t *u) {
- umask(*u);
+static inline void fclosep(FILE **f) {
+ if (*f)
+ fclose(*f);
+}
+
+static inline void pclosep(FILE **f) {
+ if (*f)
+ pclose(*f);
+}
+
+static inline void closep(int *fd) {
+ if (*fd >= 0)
+ close_nointr_nofail(*fd);
+}
+
+static inline void closedirp(DIR **d) {
+ if (*d)
+ closedir(*d);
}
-static inline void journal_closep(sd_journal **j) {
- sd_journal_close(*j);
+static inline void umaskp(mode_t *u) {
+ umask(*u);
}
-#define _cleanup_globfree_ __attribute__((cleanup(globfree)))
+#define _cleanup_free_ _cleanup_(freep)
+#define _cleanup_fclose_ _cleanup_(fclosep)
+#define _cleanup_pclose_ _cleanup_(pclosep)
+#define _cleanup_close_ _cleanup_(closep)
+#define _cleanup_closedir_ _cleanup_(closedirp)
+#define _cleanup_umask_ _cleanup_(umaskp)
+#define _cleanup_globfree_ _cleanup_(globfree)
_malloc_ static inline void *malloc_multiply(size_t a, size_t b) {
if (_unlikely_(b == 0 || a > ((size_t) -1) / b))
@@ -608,7 +625,7 @@ int create_tmp_dir(char template[], char** dir_name);
static inline void *mempset(void *s, int c, size_t n) {
memset(s, c, n);
- return (char*)s + n;
+ return (uint8_t*)s + n;
}
char *hexmem(const void *p, size_t l);
@@ -619,7 +636,7 @@ char *strrep(const char *s, unsigned n);
void* greedy_realloc(void **p, size_t *allocated, size_t need);
#define GREEDY_REALLOC(array, allocated, need) \
- greedy_realloc((void**) &(array), &(allocated), (sizeof *array) * (need))
+ greedy_realloc((void**) &(array), &(allocated), sizeof((array)[0]) * (need))
static inline void _reset_errno_(int *saved_errno) {
errno = *saved_errno;