Introduce udev object cleanup functions

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2013-10-13 17:56:55 -04:00
parent b506291ff1
commit 1ca208fb4f
18 changed files with 222 additions and 352 deletions
+1 -4
View File
@@ -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)
+2 -4
View File
@@ -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);
+3 -7
View File
@@ -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)
+2 -5
View File
@@ -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);
+37
View File
@@ -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)
+12 -21
View File
@@ -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) {