summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-10-12 20:28:21 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-10-13 17:56:55 -0400
commit1ca208fb4f93e5869704af1812cbff7130a2fc03 (patch)
tree689343b99c76e4d34c625197762de97e8435571d /src/shared
parentb506291ff195e03ce793ac925cc2d158f0b452b5 (diff)
Introduce udev object cleanup functions
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/fdset.h5
-rw-r--r--src/shared/install.c6
-rw-r--r--src/shared/set.h10
-rw-r--r--src/shared/strv.h7
-rw-r--r--src/shared/udev-util.h37
-rw-r--r--src/shared/util.h33
6 files changed, 57 insertions, 41 deletions
diff --git a/src/shared/fdset.h b/src/shared/fdset.h
index 1a2600518..6277e464d 100644
--- a/src/shared/fdset.h
+++ b/src/shared/fdset.h
@@ -49,8 +49,5 @@ int fdset_iterate(FDSet *s, Iterator *i);
#define FDSET_FOREACH(fd, fds, i) \
for ((i) = ITERATOR_FIRST, (fd) = fdset_iterate((fds), &(i)); (fd) >= 0; (fd) = fdset_iterate((fds), &(i)))
-static inline void fdset_freep(FDSet **fds) {
- if (*fds)
- fdset_free(*fds);
-}
+define_trivial_cleanup_func(FDSet*, fdset_free)
#define _cleanup_fdset_free_ _cleanup_(fdset_freep)
diff --git a/src/shared/install.c b/src/shared/install.c
index 5a780fe91..3bced1a5e 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -44,10 +44,8 @@ typedef struct {
Hashmap *have_installed;
} InstallContext;
-#define _cleanup_lookup_paths_free_ \
- __attribute__((cleanup(lookup_paths_free)))
-#define _cleanup_install_context_done_ \
- __attribute__((cleanup(install_context_done)))
+#define _cleanup_lookup_paths_free_ _cleanup_(lookup_paths_free)
+#define _cleanup_install_context_done_ _cleanup_(install_context_done)
static int lookup_paths_init_from_scope(LookupPaths *paths, UnitFileScope scope) {
assert(paths);
diff --git a/src/shared/set.h b/src/shared/set.h
index e5d46e9a8..a291470c1 100644
--- a/src/shared/set.h
+++ b/src/shared/set.h
@@ -28,19 +28,13 @@
* for each set use. */
#include "hashmap.h"
+#include "util.h"
typedef struct Set Set;
Set *set_new(hash_func_t hash_func, compare_func_t compare_func);
void set_free(Set* s);
-static inline void set_freep(Set **s) {
- set_free(*s);
-}
-
void set_free_free(Set *s);
-static inline void set_free_freep(Set **s) {
- set_free_free(*s);
-}
Set* set_copy(Set *s);
int set_ensure_allocated(Set **s, hash_func_t hash_func, compare_func_t compare_func);
@@ -79,5 +73,7 @@ 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_trivial_cleanup_func(Set*, set_free)
+define_trivial_cleanup_func(Set*, set_free_free)
#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 d1f2a0ef3..4d117f82c 100644
--- a/src/shared/strv.h
+++ b/src/shared/strv.h
@@ -24,16 +24,13 @@
#include <stdarg.h>
#include <stdbool.h>
-#include "macro.h"
+#include "util.h"
char *strv_find(char **l, const char *name) _pure_;
char *strv_find_prefix(char **l, const char *name) _pure_;
void strv_free(char **l);
-static inline void strv_freep(char ***l) {
- strv_free(*l);
-}
-
+define_trivial_cleanup_func(char**, strv_free)
#define _cleanup_strv_free_ _cleanup_(strv_freep)
char **strv_copy(char * const *l);
diff --git a/src/shared/udev-util.h b/src/shared/udev-util.h
new file mode 100644
index 000000000..bff8f5fbf
--- /dev/null
+++ b/src/shared/udev-util.h
@@ -0,0 +1,37 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+ This file is part of systemd.
+
+ Copyright 2013 Zbigniew Jędrzejewski-Szmek
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include "udev.h"
+#include "util.h"
+
+define_trivial_cleanup_func(struct udev*, udev_unref)
+define_trivial_cleanup_func(struct udev_device*, udev_device_unref)
+define_trivial_cleanup_func(struct udev_enumerate*, udev_enumerate_unref)
+define_trivial_cleanup_func(struct udev_event*, udev_event_unref)
+define_trivial_cleanup_func(struct udev_rules*, udev_rules_unref)
+
+#define _cleanup_udev_unref_ _cleanup_(udev_unrefp)
+#define _cleanup_udev_device_unref_ _cleanup_(udev_device_unrefp)
+#define _cleanup_udev_enumerate_unref_ _cleanup_(udev_enumerate_unrefp)
+#define _cleanup_udev_event_unref_ _cleanup_(udev_event_unrefp)
+#define _cleanup_udev_rules_unref_ _cleanup_(udev_rules_unrefp)
diff --git a/src/shared/util.h b/src/shared/util.h
index 09e556d01..99a138cd8 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -556,42 +556,33 @@ static inline void freep(void *p) {
free(*(void**) p);
}
-static inline void fclosep(FILE **f) {
- if (*f)
- fclose(*f);
-}
-
-static inline void pclosep(FILE **f) {
- if (*f)
- pclose(*f);
-}
+#define define_trivial_cleanup_func(type, func) \
+ static inline void func##p(type *p) { \
+ if (*p) \
+ func(*p); \
+ } \
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 umaskp(mode_t *u) {
umask(*u);
}
-static inline void endmntentp(FILE **f) {
- if (*f)
- endmntent(*f);
-}
+define_trivial_cleanup_func(FILE*, fclose)
+define_trivial_cleanup_func(FILE*, pclose)
+define_trivial_cleanup_func(DIR*, closedir)
+define_trivial_cleanup_func(FILE*, endmntent)
#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)
+#define _cleanup_fclose_ _cleanup_(fclosep)
+#define _cleanup_pclose_ _cleanup_(pclosep)
+#define _cleanup_closedir_ _cleanup_(closedirp)
#define _cleanup_endmntent_ _cleanup_(endmntentp)
_malloc_ _alloc_(1, 2) static inline void *malloc_multiply(size_t a, size_t b) {