Compare commits

..

1 Commits

Author SHA1 Message Date
Lennart Poettering 33b4ed9bd8
Merge db8a5ef5da into 710653d3bc 2025-04-17 21:22:12 +02:00
57 changed files with 334 additions and 426 deletions

3
NEWS
View File

@ -96,9 +96,6 @@ CHANGES WITH 258 in spe:
continue to work, update to xf86-input-evdev >= 2.11.0 and continue to work, update to xf86-input-evdev >= 2.11.0 and
xf86-input-libinput >= 1.5.0 before updating to systemd >= 258. xf86-input-libinput >= 1.5.0 before updating to systemd >= 258.
* The meson option 'integration-tests' has been deprecated, and will be
removed in a future release.
— <place>, <date> — <place>, <date>
CHANGES WITH 257: CHANGES WITH 257:

View File

@ -77,20 +77,6 @@ ENV{DDC_DEVICE}=="?*", TAG+="uaccess"
# media player raw devices (for user-mode drivers, Android SDK, etc.) # media player raw devices (for user-mode drivers, Android SDK, etc.)
SUBSYSTEM=="usb", ENV{ID_MEDIA_PLAYER}=="?*", TAG+="uaccess" SUBSYSTEM=="usb", ENV{ID_MEDIA_PLAYER}=="?*", TAG+="uaccess"
# Android devices (ADB DbC, ADB, Fastboot)
# Used to interact with devices over Android Debug Bridge and Fastboot protocols, see:
# * https://developer.android.com/tools/adb
# * https://source.android.com/docs/setup/test/running
# * https://source.android.com/docs/setup/test/flash
#
# The bInterfaceClass and bInterfaceSubClass used are documented in source code here:
# * https://android.googlesource.com/platform/packages/modules/adb/+/d0db47dcdf941673f405e1095e6ffb5e565902e5/adb.h#199
# * https://android.googlesource.com/platform/system/core/+/7199051aaf0ddfa2849650933119307327d8669c/fastboot/fastboot.cpp#244
#
# Since it's using a generic vendor specific interface class, this can potentially result
# in a rare case where non-ADB/Fastboot device ends up with an ID_DEBUG_APPLIANCE="android".
SUBSYSTEM=="usb", ENV{ID_USB_INTERFACES}=="*:dc0201:*|*:ff4201:*|*:ff4203:*", ENV{ID_DEBUG_APPLIANCE}="android"
# software-defined radio communication devices # software-defined radio communication devices
ENV{ID_SOFTWARE_RADIO}=="?*", TAG+="uaccess" ENV{ID_SOFTWARE_RADIO}=="?*", TAG+="uaccess"
@ -125,7 +111,4 @@ SUBSYSTEM=="hidraw", ENV{ID_HARDWARE_WALLET}=="1", TAG+="uaccess"
# As defined in https://en.wikipedia.org/wiki/3Dconnexion # As defined in https://en.wikipedia.org/wiki/3Dconnexion
SUBSYSTEM=="hidraw", ENV{ID_INPUT_3D_MOUSE}=="1", TAG+="uaccess" SUBSYSTEM=="hidraw", ENV{ID_INPUT_3D_MOUSE}=="1", TAG+="uaccess"
# Debug interfaces (e.g. Android Debug Bridge)
ENV{ID_DEBUG_APPLIANCE}=="?*", TAG+="uaccess"
LABEL="uaccess_end" LABEL="uaccess_end"

View File

@ -31,7 +31,7 @@ static void log_syntax_callback(const char *unit, int level, void *userdata) {
r = set_put_strdup(s, unit); r = set_put_strdup(s, unit);
if (r < 0) { if (r < 0) {
set_free(*s); set_free_free(*s);
*s = POINTER_MAX; *s = POINTER_MAX;
} }
} }
@ -265,7 +265,7 @@ static int verify_unit(Unit *u, bool check_man, const char *root) {
static void set_destroy_ignore_pointer_max(Set **s) { static void set_destroy_ignore_pointer_max(Set **s) {
if (*s == POINTER_MAX) if (*s == POINTER_MAX)
return; return;
set_free(*s); set_free_free(*s);
} }
int verify_units( int verify_units(

View File

@ -1001,13 +1001,13 @@ int fd_verify_safe_flags_full(int fd, int extra_flags) {
if (flags < 0) if (flags < 0)
return -errno; return -errno;
unexpected_flags = flags & ~(O_ACCMODE_STRICT|O_NOFOLLOW|RAW_O_LARGEFILE|extra_flags); unexpected_flags = flags & ~(O_ACCMODE|O_NOFOLLOW|RAW_O_LARGEFILE|extra_flags);
if (unexpected_flags != 0) if (unexpected_flags != 0)
return log_debug_errno(SYNTHETIC_ERRNO(EREMOTEIO), return log_debug_errno(SYNTHETIC_ERRNO(EREMOTEIO),
"Unexpected flags set for extrinsic fd: 0%o", "Unexpected flags set for extrinsic fd: 0%o",
(unsigned) unexpected_flags); (unsigned) unexpected_flags);
return flags & (O_ACCMODE_STRICT | extra_flags); /* return the flags variable, but remove the noise */ return flags & (O_ACCMODE | extra_flags); /* return the flags variable, but remove the noise */
} }
int read_nr_open(void) { int read_nr_open(void) {
@ -1132,7 +1132,7 @@ int fds_are_same_mount(int fd1, int fd2) {
} }
const char* accmode_to_string(int flags) { const char* accmode_to_string(int flags) {
switch (flags & O_ACCMODE_STRICT) { switch (flags & O_ACCMODE) {
case O_RDONLY: case O_RDONLY:
return "ro"; return "ro";
case O_WRONLY: case O_WRONLY:

View File

@ -1036,7 +1036,7 @@ int open_mkdir_at_full(int dirfd, const char *path, int flags, XOpenFlags xopen_
if (flags & ~(O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_EXCL|O_NOATIME|O_NOFOLLOW|O_PATH)) if (flags & ~(O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_EXCL|O_NOATIME|O_NOFOLLOW|O_PATH))
return -EINVAL; return -EINVAL;
if ((flags & O_ACCMODE_STRICT) != O_RDONLY) if ((flags & O_ACCMODE) != O_RDONLY)
return -EINVAL; return -EINVAL;
/* Note that O_DIRECTORY|O_NOFOLLOW is implied, but we allow specifying it anyway. The following /* Note that O_DIRECTORY|O_NOFOLLOW is implied, but we allow specifying it anyway. The following

View File

@ -88,10 +88,8 @@ OrderedHashmap* _ordered_hashmap_new(const struct hash_ops *hash_ops HASHMAP_DE
#define hashmap_new(ops) _hashmap_new(ops HASHMAP_DEBUG_SRC_ARGS) #define hashmap_new(ops) _hashmap_new(ops HASHMAP_DEBUG_SRC_ARGS)
#define ordered_hashmap_new(ops) _ordered_hashmap_new(ops HASHMAP_DEBUG_SRC_ARGS) #define ordered_hashmap_new(ops) _ordered_hashmap_new(ops HASHMAP_DEBUG_SRC_ARGS)
#define hashmap_free_and_replace(a, b) \ #define hashmap_free_and_replace(a, b) \
free_and_replace_full(a, b, hashmap_free) free_and_replace_full(a, b, hashmap_free)
#define ordered_hashmap_free_and_replace(a, b) \
free_and_replace_full(a, b, ordered_hashmap_free)
HashmapBase* _hashmap_free(HashmapBase *h, free_func_t default_free_key, free_func_t default_free_value); HashmapBase* _hashmap_free(HashmapBase *h, free_func_t default_free_key, free_func_t default_free_value);
static inline Hashmap* hashmap_free(Hashmap *h) { static inline Hashmap* hashmap_free(Hashmap *h) {

View File

@ -43,9 +43,3 @@
#ifndef AT_HANDLE_FID #ifndef AT_HANDLE_FID
#define AT_HANDLE_FID AT_REMOVEDIR #define AT_HANDLE_FID AT_REMOVEDIR
#endif #endif
/* On musl, O_ACCMODE is defined as (03|O_SEARCH), unlike glibc which defines it as
* (O_RDONLY|O_WRONLY|O_RDWR). Additionally, O_SEARCH is simply defined as O_PATH. This changes the behaviour
* of O_ACCMODE in certain situations, which we don't want. This definition is copied from glibc and works
* around the problems with musl's definition. */
#define O_ACCMODE_STRICT (O_RDONLY|O_WRONLY|O_RDWR)

View File

@ -267,7 +267,7 @@ static int acquire_path(const char *path, int flags, mode_t mode) {
assert(path); assert(path);
if (IN_SET(flags & O_ACCMODE_STRICT, O_WRONLY, O_RDWR)) if (IN_SET(flags & O_ACCMODE, O_WRONLY, O_RDWR))
flags |= O_CREAT; flags |= O_CREAT;
fd = open(path, flags|O_NOCTTY, mode); fd = open(path, flags|O_NOCTTY, mode);
@ -291,9 +291,9 @@ static int acquire_path(const char *path, int flags, mode_t mode) {
if (r < 0) if (r < 0)
return r; return r;
if ((flags & O_ACCMODE_STRICT) == O_RDONLY) if ((flags & O_ACCMODE) == O_RDONLY)
r = shutdown(fd, SHUT_WR); r = shutdown(fd, SHUT_WR);
else if ((flags & O_ACCMODE_STRICT) == O_WRONLY) else if ((flags & O_ACCMODE) == O_WRONLY)
r = shutdown(fd, SHUT_RD); r = shutdown(fd, SHUT_RD);
else else
r = 0; r = 0;

View File

@ -38,10 +38,11 @@ static VacuumCandidate* vacuum_candidate_free(VacuumCandidate *c) {
} }
DEFINE_TRIVIAL_CLEANUP_FUNC(VacuumCandidate*, vacuum_candidate_free); DEFINE_TRIVIAL_CLEANUP_FUNC(VacuumCandidate*, vacuum_candidate_free);
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR( static Hashmap* vacuum_candidate_hashmap_free(Hashmap *h) {
vacuum_candidate_hash_ops, return hashmap_free_with_destructor(h, vacuum_candidate_free);
void, trivial_hash_func, trivial_compare_func, }
VacuumCandidate, vacuum_candidate_free);
DEFINE_TRIVIAL_CLEANUP_FUNC(Hashmap*, vacuum_candidate_hashmap_free);
static int uid_from_file_name(const char *filename, uid_t *uid) { static int uid_from_file_name(const char *filename, uid_t *uid) {
const char *p, *e, *u; const char *p, *e, *u;
@ -140,7 +141,7 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) {
} }
for (;;) { for (;;) {
_cleanup_hashmap_free_ Hashmap *h = NULL; _cleanup_(vacuum_candidate_hashmap_freep) Hashmap *h = NULL;
VacuumCandidate *worst = NULL; VacuumCandidate *worst = NULL;
uint64_t sum = 0; uint64_t sum = 0;
@ -170,6 +171,10 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) {
if (exclude_fd >= 0 && stat_inode_same(&exclude_st, &st)) if (exclude_fd >= 0 && stat_inode_same(&exclude_st, &st))
continue; continue;
r = hashmap_ensure_allocated(&h, NULL);
if (r < 0)
return log_oom();
t = timespec_load(&st.st_mtim); t = timespec_load(&st.st_mtim);
c = hashmap_get(h, UID_TO_PTR(uid)); c = hashmap_get(h, UID_TO_PTR(uid));
@ -192,7 +197,7 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) {
return r; return r;
n->oldest_mtime = t; n->oldest_mtime = t;
r = hashmap_ensure_put(&h, &vacuum_candidate_hash_ops, UID_TO_PTR(uid), n); r = hashmap_put(h, UID_TO_PTR(uid), n);
if (r < 0) if (r < 0)
return log_oom(); return log_oom();

View File

@ -91,7 +91,7 @@ static void device_unref_many(sd_device **devices, size_t n) {
static void device_enumerator_unref_devices(sd_device_enumerator *enumerator) { static void device_enumerator_unref_devices(sd_device_enumerator *enumerator) {
assert(enumerator); assert(enumerator);
hashmap_clear(enumerator->devices_by_syspath); hashmap_clear_with_destructor(enumerator->devices_by_syspath, sd_device_unref);
device_unref_many(enumerator->devices, enumerator->n_devices); device_unref_many(enumerator->devices, enumerator->n_devices);
enumerator->devices = mfree(enumerator->devices); enumerator->devices = mfree(enumerator->devices);
enumerator->n_devices = 0; enumerator->n_devices = 0;
@ -471,11 +471,6 @@ failed:
return r; return r;
} }
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
device_hash_ops_by_syspath,
char, path_hash_func, path_compare,
sd_device, sd_device_unref);
int device_enumerator_add_device(sd_device_enumerator *enumerator, sd_device *device) { int device_enumerator_add_device(sd_device_enumerator *enumerator, sd_device *device) {
const char *syspath; const char *syspath;
int r; int r;
@ -487,7 +482,7 @@ int device_enumerator_add_device(sd_device_enumerator *enumerator, sd_device *de
if (r < 0) if (r < 0)
return r; return r;
r = hashmap_ensure_put(&enumerator->devices_by_syspath, &device_hash_ops_by_syspath, syspath, device); r = hashmap_ensure_put(&enumerator->devices_by_syspath, &string_hash_ops, syspath, device);
if (IN_SET(r, -EEXIST, 0)) if (IN_SET(r, -EEXIST, 0))
return 0; return 0;
if (r < 0) if (r < 0)

View File

@ -692,8 +692,8 @@ int device_clone_with_db(sd_device *device, sd_device **ret) {
void device_cleanup_tags(sd_device *device) { void device_cleanup_tags(sd_device *device) {
assert(device); assert(device);
device->all_tags = set_free(device->all_tags); device->all_tags = set_free_free(device->all_tags);
device->current_tags = set_free(device->current_tags); device->current_tags = set_free_free(device->current_tags);
device->property_tags_outdated = true; device->property_tags_outdated = true;
device->tags_generation++; device->tags_generation++;
} }
@ -701,7 +701,7 @@ void device_cleanup_tags(sd_device *device) {
void device_cleanup_devlinks(sd_device *device) { void device_cleanup_devlinks(sd_device *device) {
assert(device); assert(device);
set_free(device->devlinks); set_free_free(device->devlinks);
device->devlinks = NULL; device->devlinks = NULL;
device->property_devlinks_outdated = true; device->property_devlinks_outdated = true;
device->devlinks_generation++; device->devlinks_generation++;

View File

@ -98,7 +98,7 @@ DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
JournalFile, journal_file_close); JournalFile, journal_file_close);
static int mmap_prot_from_open_flags(int flags) { static int mmap_prot_from_open_flags(int flags) {
switch (flags & O_ACCMODE_STRICT) { switch (flags & O_ACCMODE) {
case O_RDONLY: case O_RDONLY:
return PROT_READ; return PROT_READ;
case O_WRONLY: case O_WRONLY:
@ -4075,10 +4075,10 @@ int journal_file_open(
assert(mmap_cache); assert(mmap_cache);
assert(ret); assert(ret);
if (!IN_SET((open_flags & O_ACCMODE_STRICT), O_RDONLY, O_RDWR)) if (!IN_SET((open_flags & O_ACCMODE), O_RDONLY, O_RDWR))
return -EINVAL; return -EINVAL;
if ((open_flags & O_ACCMODE_STRICT) == O_RDONLY && FLAGS_SET(open_flags, O_CREAT)) if ((open_flags & O_ACCMODE) == O_RDONLY && FLAGS_SET(open_flags, O_CREAT))
return -EINVAL; return -EINVAL;
if (fname && (open_flags & O_CREAT) && !endswith(fname, ".journal")) if (fname && (open_flags & O_CREAT) && !endswith(fname, ".journal"))

View File

@ -1,6 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once #pragma once
#include <fcntl.h>
#include <inttypes.h> #include <inttypes.h>
#include <sys/uio.h> #include <sys/uio.h>
@ -14,7 +15,6 @@
#include "compress.h" #include "compress.h"
#include "hashmap.h" #include "hashmap.h"
#include "journal-def.h" #include "journal-def.h"
#include "missing_fcntl.h"
#include "mmap-cache.h" #include "mmap-cache.h"
#include "sparse-endian.h" #include "sparse-endian.h"
#include "time-util.h" #include "time-util.h"
@ -391,5 +391,5 @@ static inline uint32_t COMPRESSION_TO_HEADER_INCOMPATIBLE_FLAG(Compression c) {
static inline bool journal_file_writable(JournalFile *f) { static inline bool journal_file_writable(JournalFile *f) {
assert(f); assert(f);
return (f->open_flags & O_ACCMODE_STRICT) != O_RDONLY; return (f->open_flags & O_ACCMODE) != O_RDONLY;
} }

View File

@ -46,21 +46,11 @@ static GenericNetlinkFamily *genl_family_free(GenericNetlinkFamily *f) {
DEFINE_TRIVIAL_CLEANUP_FUNC(GenericNetlinkFamily*, genl_family_free); DEFINE_TRIVIAL_CLEANUP_FUNC(GenericNetlinkFamily*, genl_family_free);
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
genl_family_hash_ops_by_name,
char, string_hash_func, string_compare_func,
GenericNetlinkFamily, genl_family_free);
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
genl_family_hash_ops_by_id,
void, trivial_hash_func, trivial_compare_func,
GenericNetlinkFamily, genl_family_free);
void genl_clear_family(sd_netlink *nl) { void genl_clear_family(sd_netlink *nl) {
assert(nl); assert(nl);
nl->genl_family_by_name = hashmap_free(nl->genl_family_by_name); nl->genl_family_by_name = hashmap_free_with_destructor(nl->genl_family_by_name, genl_family_free);
nl->genl_family_by_id = hashmap_free(nl->genl_family_by_id); nl->genl_family_by_id = hashmap_free_with_destructor(nl->genl_family_by_id, genl_family_free);
} }
static int genl_family_new_unsupported( static int genl_family_new_unsupported(
@ -90,7 +80,7 @@ static int genl_family_new_unsupported(
if (!f->name) if (!f->name)
return -ENOMEM; return -ENOMEM;
r = hashmap_ensure_put(&nl->genl_family_by_name, &genl_family_hash_ops_by_name, f->name, f); r = hashmap_ensure_put(&nl->genl_family_by_name, &string_hash_ops, f->name, f);
if (r < 0) if (r < 0)
return r; return r;
@ -200,11 +190,11 @@ static int genl_family_new(
return r; return r;
} }
r = hashmap_ensure_put(&nl->genl_family_by_id, &genl_family_hash_ops_by_id, UINT_TO_PTR(f->id), f); r = hashmap_ensure_put(&nl->genl_family_by_id, NULL, UINT_TO_PTR(f->id), f);
if (r < 0) if (r < 0)
return r; return r;
r = hashmap_ensure_put(&nl->genl_family_by_name, &genl_family_hash_ops_by_name, f->name, f); r = hashmap_ensure_put(&nl->genl_family_by_name, &string_hash_ops, f->name, f);
if (r < 0) { if (r < 0) {
hashmap_remove(nl->genl_family_by_id, UINT_TO_PTR(f->id)); hashmap_remove(nl->genl_family_by_id, UINT_TO_PTR(f->id));
return r; return r;

View File

@ -6,5 +6,5 @@
struct udev_device; struct udev_device;
struct udev_device* udev_device_new(struct udev *udev, sd_device *device); struct udev_device *udev_device_new(struct udev *udev, sd_device *device);
sd_device* udev_device_get_sd_device(struct udev_device *udev_device); sd_device *udev_device_get_sd_device(struct udev_device *udev_device);

View File

@ -120,7 +120,7 @@ _public_ dev_t udev_device_get_devnum(struct udev_device *udev_device) {
* *
* Returns: the driver name string, or #NULL if there is no driver attached. * Returns: the driver name string, or #NULL if there is no driver attached.
**/ **/
_public_ const char* udev_device_get_driver(struct udev_device *udev_device) { _public_ const char *udev_device_get_driver(struct udev_device *udev_device) {
const char *driver; const char *driver;
int r; int r;
@ -141,7 +141,7 @@ _public_ const char* udev_device_get_driver(struct udev_device *udev_device) {
* *
* Returns: the devtype name of the udev device, or #NULL if it cannot be determined * Returns: the devtype name of the udev device, or #NULL if it cannot be determined
**/ **/
_public_ const char* udev_device_get_devtype(struct udev_device *udev_device) { _public_ const char *udev_device_get_devtype(struct udev_device *udev_device) {
const char *devtype; const char *devtype;
int r; int r;
@ -165,7 +165,7 @@ _public_ const char* udev_device_get_devtype(struct udev_device *udev_device) {
* *
* Returns: the subsystem name of the udev device, or #NULL if it cannot be determined * Returns: the subsystem name of the udev device, or #NULL if it cannot be determined
**/ **/
_public_ const char* udev_device_get_subsystem(struct udev_device *udev_device) { _public_ const char *udev_device_get_subsystem(struct udev_device *udev_device) {
const char *subsystem; const char *subsystem;
int r; int r;
@ -187,7 +187,7 @@ _public_ const char* udev_device_get_subsystem(struct udev_device *udev_device)
* *
* Returns: the property string, or #NULL if there is no such property. * Returns: the property string, or #NULL if there is no such property.
**/ **/
_public_ const char* udev_device_get_property_value(struct udev_device *udev_device, const char *key) { _public_ const char *udev_device_get_property_value(struct udev_device *udev_device, const char *key) {
const char *value; const char *value;
int r; int r;
@ -200,7 +200,7 @@ _public_ const char* udev_device_get_property_value(struct udev_device *udev_dev
return value; return value;
} }
struct udev_device* udev_device_new(struct udev *udev, sd_device *device) { struct udev_device *udev_device_new(struct udev *udev, sd_device *device) {
_cleanup_(udev_list_freep) struct udev_list *properties = NULL, *all_tags = NULL, *current_tags = NULL, *sysattrs = NULL, *devlinks = NULL; _cleanup_(udev_list_freep) struct udev_list *properties = NULL, *all_tags = NULL, *current_tags = NULL, *sysattrs = NULL, *devlinks = NULL;
struct udev_device *udev_device; struct udev_device *udev_device;
@ -254,7 +254,7 @@ struct udev_device* udev_device_new(struct udev *udev, sd_device *device) {
* *
* Returns: a new udev device, or #NULL, if it does not exist * Returns: a new udev device, or #NULL, if it does not exist
**/ **/
_public_ struct udev_device* udev_device_new_from_syspath(struct udev *udev, const char *syspath) { _public_ struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath) {
_cleanup_(sd_device_unrefp) sd_device *device = NULL; _cleanup_(sd_device_unrefp) sd_device *device = NULL;
int r; int r;
@ -281,7 +281,7 @@ _public_ struct udev_device* udev_device_new_from_syspath(struct udev *udev, con
* *
* Returns: a new udev device, or #NULL, if it does not exist * Returns: a new udev device, or #NULL, if it does not exist
**/ **/
_public_ struct udev_device* udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum) { _public_ struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum) {
_cleanup_(sd_device_unrefp) sd_device *device = NULL; _cleanup_(sd_device_unrefp) sd_device *device = NULL;
int r; int r;
@ -310,7 +310,7 @@ _public_ struct udev_device* udev_device_new_from_devnum(struct udev *udev, char
* *
* Returns: a new udev device, or #NULL, if it does not exist * Returns: a new udev device, or #NULL, if it does not exist
**/ **/
_public_ struct udev_device* udev_device_new_from_device_id(struct udev *udev, const char *id) { _public_ struct udev_device *udev_device_new_from_device_id(struct udev *udev, const char *id) {
_cleanup_(sd_device_unrefp) sd_device *device = NULL; _cleanup_(sd_device_unrefp) sd_device *device = NULL;
int r; int r;
@ -336,7 +336,7 @@ _public_ struct udev_device* udev_device_new_from_device_id(struct udev *udev, c
* *
* Returns: a new udev device, or #NULL, if it does not exist * Returns: a new udev device, or #NULL, if it does not exist
**/ **/
_public_ struct udev_device* udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname) { _public_ struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname) {
_cleanup_(sd_device_unrefp) sd_device *device = NULL; _cleanup_(sd_device_unrefp) sd_device *device = NULL;
int r; int r;
@ -361,7 +361,7 @@ _public_ struct udev_device* udev_device_new_from_subsystem_sysname(struct udev
* *
* Returns: a new udev device, or #NULL, if it does not exist * Returns: a new udev device, or #NULL, if it does not exist
**/ **/
_public_ struct udev_device* udev_device_new_from_environment(struct udev *udev) { _public_ struct udev_device *udev_device_new_from_environment(struct udev *udev) {
_cleanup_(sd_device_unrefp) sd_device *device = NULL; _cleanup_(sd_device_unrefp) sd_device *device = NULL;
int r; int r;
@ -372,7 +372,7 @@ _public_ struct udev_device* udev_device_new_from_environment(struct udev *udev)
return udev_device_new(udev, device); return udev_device_new(udev, device);
} }
static struct udev_device* device_new_from_parent(struct udev_device *child) { static struct udev_device *device_new_from_parent(struct udev_device *child) {
sd_device *parent; sd_device *parent;
int r; int r;
@ -403,7 +403,7 @@ static struct udev_device* device_new_from_parent(struct udev_device *child) {
* *
* Returns: a new udev device, or #NULL, if it no parent exist. * Returns: a new udev device, or #NULL, if it no parent exist.
**/ **/
_public_ struct udev_device* udev_device_get_parent(struct udev_device *udev_device) { _public_ struct udev_device *udev_device_get_parent(struct udev_device *udev_device) {
assert_return_errno(udev_device, NULL, EINVAL); assert_return_errno(udev_device, NULL, EINVAL);
if (!udev_device->parent_set) { if (!udev_device->parent_set) {
@ -436,11 +436,7 @@ _public_ struct udev_device* udev_device_get_parent(struct udev_device *udev_dev
* *
* Returns: a new udev device, or #NULL if no matching parent exists. * Returns: a new udev device, or #NULL if no matching parent exists.
**/ **/
_public_ struct udev_device* udev_device_get_parent_with_subsystem_devtype( _public_ struct udev_device *udev_device_get_parent_with_subsystem_devtype(struct udev_device *udev_device, const char *subsystem, const char *devtype) {
struct udev_device *udev_device,
const char *subsystem,
const char *devtype) {
sd_device *parent; sd_device *parent;
int r; int r;
@ -471,13 +467,13 @@ _public_ struct udev_device* udev_device_get_parent_with_subsystem_devtype(
* *
* Returns: the udev library context * Returns: the udev library context
**/ **/
_public_ struct udev* udev_device_get_udev(struct udev_device *udev_device) { _public_ struct udev *udev_device_get_udev(struct udev_device *udev_device) {
assert_return_errno(udev_device, NULL, EINVAL); assert_return_errno(udev_device, NULL, EINVAL);
return udev_device->udev; return udev_device->udev;
} }
static struct udev_device* udev_device_free(struct udev_device *udev_device) { static struct udev_device *udev_device_free(struct udev_device *udev_device) {
assert(udev_device); assert(udev_device);
sd_device_unref(udev_device->device); sd_device_unref(udev_device->device);
@ -521,7 +517,7 @@ DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(struct udev_device, udev_device, udev_devic
* *
* Returns: the devpath of the udev device * Returns: the devpath of the udev device
**/ **/
_public_ const char* udev_device_get_devpath(struct udev_device *udev_device) { _public_ const char *udev_device_get_devpath(struct udev_device *udev_device) {
const char *devpath; const char *devpath;
int r; int r;
@ -543,7 +539,7 @@ _public_ const char* udev_device_get_devpath(struct udev_device *udev_device) {
* *
* Returns: the sys path of the udev device * Returns: the sys path of the udev device
**/ **/
_public_ const char* udev_device_get_syspath(struct udev_device *udev_device) { _public_ const char *udev_device_get_syspath(struct udev_device *udev_device) {
const char *syspath; const char *syspath;
int r; int r;
@ -564,7 +560,7 @@ _public_ const char* udev_device_get_syspath(struct udev_device *udev_device) {
* *
* Returns: the name string of the device * Returns: the name string of the device
**/ **/
_public_ const char* udev_device_get_sysname(struct udev_device *udev_device) { _public_ const char *udev_device_get_sysname(struct udev_device *udev_device) {
const char *sysname; const char *sysname;
int r; int r;
@ -585,7 +581,7 @@ _public_ const char* udev_device_get_sysname(struct udev_device *udev_device) {
* *
* Returns: the trailing number string of the device name * Returns: the trailing number string of the device name
**/ **/
_public_ const char* udev_device_get_sysnum(struct udev_device *udev_device) { _public_ const char *udev_device_get_sysnum(struct udev_device *udev_device) {
const char *sysnum; const char *sysnum;
int r; int r;
@ -609,7 +605,7 @@ _public_ const char* udev_device_get_sysnum(struct udev_device *udev_device) {
* *
* Returns: the device node file name of the udev device, or #NULL if no device node exists * Returns: the device node file name of the udev device, or #NULL if no device node exists
**/ **/
_public_ const char* udev_device_get_devnode(struct udev_device *udev_device) { _public_ const char *udev_device_get_devnode(struct udev_device *udev_device) {
const char *devnode; const char *devnode;
int r; int r;
@ -635,7 +631,7 @@ _public_ const char* udev_device_get_devnode(struct udev_device *udev_device) {
* *
* Returns: the first entry of the device node link list * Returns: the first entry of the device node link list
**/ **/
_public_ struct udev_list_entry* udev_device_get_devlinks_list_entry(struct udev_device *udev_device) { _public_ struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev_device *udev_device) {
assert_return_errno(udev_device, NULL, EINVAL); assert_return_errno(udev_device, NULL, EINVAL);
if (device_get_devlinks_generation(udev_device->device) != udev_device->devlinks_generation || if (device_get_devlinks_generation(udev_device->device) != udev_device->devlinks_generation ||
@ -665,7 +661,7 @@ _public_ struct udev_list_entry* udev_device_get_devlinks_list_entry(struct udev
* *
* Returns: the first entry of the property list * Returns: the first entry of the property list
**/ **/
_public_ struct udev_list_entry* udev_device_get_properties_list_entry(struct udev_device *udev_device) { _public_ struct udev_list_entry *udev_device_get_properties_list_entry(struct udev_device *udev_device) {
assert_return_errno(udev_device, NULL, EINVAL); assert_return_errno(udev_device, NULL, EINVAL);
if (device_get_properties_generation(udev_device->device) != udev_device->properties_generation || if (device_get_properties_generation(udev_device->device) != udev_device->properties_generation ||
@ -693,7 +689,7 @@ _public_ struct udev_list_entry* udev_device_get_properties_list_entry(struct ud
* *
* Returns: the kernel action value, or #NULL if there is no action value available. * Returns: the kernel action value, or #NULL if there is no action value available.
**/ **/
_public_ const char* udev_device_get_action(struct udev_device *udev_device) { _public_ const char *udev_device_get_action(struct udev_device *udev_device) {
sd_device_action_t action; sd_device_action_t action;
assert_return_errno(udev_device, NULL, EINVAL); assert_return_errno(udev_device, NULL, EINVAL);
@ -739,7 +735,7 @@ _public_ unsigned long long int udev_device_get_usec_since_initialized(struct ud
* *
* Returns: the content of a sys attribute file, or #NULL if there is no sys attribute value. * Returns: the content of a sys attribute file, or #NULL if there is no sys attribute value.
**/ **/
_public_ const char* udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr) { _public_ const char *udev_device_get_sysattr_value(struct udev_device *udev_device, const char *sysattr) {
const char *value; const char *value;
int r; int r;
@ -784,7 +780,7 @@ _public_ int udev_device_set_sysattr_value(struct udev_device *udev_device, cons
* *
* Returns: the first entry of the property list * Returns: the first entry of the property list
**/ **/
_public_ struct udev_list_entry* udev_device_get_sysattr_list_entry(struct udev_device *udev_device) { _public_ struct udev_list_entry *udev_device_get_sysattr_list_entry(struct udev_device *udev_device) {
assert_return_errno(udev_device, NULL, EINVAL); assert_return_errno(udev_device, NULL, EINVAL);
if (!udev_device->sysattrs_read) { if (!udev_device->sysattrs_read) {
@ -836,7 +832,7 @@ _public_ int udev_device_get_is_initialized(struct udev_device *udev_device) {
* *
* Returns: the first entry of the tag list * Returns: the first entry of the tag list
**/ **/
_public_ struct udev_list_entry* udev_device_get_tags_list_entry(struct udev_device *udev_device) { _public_ struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_device *udev_device) {
assert_return_errno(udev_device, NULL, EINVAL); assert_return_errno(udev_device, NULL, EINVAL);
if (device_get_tags_generation(udev_device->device) != udev_device->all_tags_generation || if (device_get_tags_generation(udev_device->device) != udev_device->all_tags_generation ||
@ -854,7 +850,7 @@ _public_ struct udev_list_entry* udev_device_get_tags_list_entry(struct udev_dev
return udev_list_get_entry(udev_device->all_tags); return udev_list_get_entry(udev_device->all_tags);
} }
_public_ struct udev_list_entry* udev_device_get_current_tags_list_entry(struct udev_device *udev_device) { _public_ struct udev_list_entry *udev_device_get_current_tags_list_entry(struct udev_device *udev_device) {
assert_return_errno(udev_device, NULL, EINVAL); assert_return_errno(udev_device, NULL, EINVAL);
if (device_get_tags_generation(udev_device->device) != udev_device->current_tags_generation || if (device_get_tags_generation(udev_device->device) != udev_device->current_tags_generation ||
@ -893,7 +889,7 @@ _public_ int udev_device_has_current_tag(struct udev_device *udev_device, const
return sd_device_has_current_tag(udev_device->device, tag) > 0; return sd_device_has_current_tag(udev_device->device, tag) > 0;
} }
sd_device* udev_device_get_sd_device(struct udev_device *udev_device) { sd_device *udev_device_get_sd_device(struct udev_device *udev_device) {
assert(udev_device); assert(udev_device);
return udev_device->device; return udev_device->device;

View File

@ -49,7 +49,7 @@ struct udev_enumerate {
* *
* Returns: an enumeration context. * Returns: an enumeration context.
**/ **/
_public_ struct udev_enumerate* udev_enumerate_new(struct udev *udev) { _public_ struct udev_enumerate *udev_enumerate_new(struct udev *udev) {
_cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL; _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
_cleanup_(udev_list_freep) struct udev_list *list = NULL; _cleanup_(udev_list_freep) struct udev_list *list = NULL;
struct udev_enumerate *udev_enumerate; struct udev_enumerate *udev_enumerate;
@ -81,7 +81,7 @@ _public_ struct udev_enumerate* udev_enumerate_new(struct udev *udev) {
return udev_enumerate; return udev_enumerate;
} }
static struct udev_enumerate* udev_enumerate_free(struct udev_enumerate *udev_enumerate) { static struct udev_enumerate *udev_enumerate_free(struct udev_enumerate *udev_enumerate) {
assert(udev_enumerate); assert(udev_enumerate);
udev_list_free(udev_enumerate->devices_list); udev_list_free(udev_enumerate->devices_list);
@ -117,7 +117,7 @@ DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(struct udev_enumerate, udev_enumerate, udev
* *
* Returns: a pointer to the context. * Returns: a pointer to the context.
*/ */
_public_ struct udev* udev_enumerate_get_udev(struct udev_enumerate *udev_enumerate) { _public_ struct udev *udev_enumerate_get_udev(struct udev_enumerate *udev_enumerate) {
assert_return_errno(udev_enumerate, NULL, EINVAL); assert_return_errno(udev_enumerate, NULL, EINVAL);
return udev_enumerate->udev; return udev_enumerate->udev;
@ -131,7 +131,7 @@ _public_ struct udev* udev_enumerate_get_udev(struct udev_enumerate *udev_enumer
* *
* Returns: a udev_list_entry. * Returns: a udev_list_entry.
*/ */
_public_ struct udev_list_entry* udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate) { _public_ struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate) {
struct udev_list_entry *e; struct udev_list_entry *e;
assert_return_errno(udev_enumerate, NULL, EINVAL); assert_return_errno(udev_enumerate, NULL, EINVAL);

View File

@ -34,7 +34,7 @@ struct udev_hwdb {
* *
* Returns: a hwdb context. * Returns: a hwdb context.
**/ **/
_public_ struct udev_hwdb* udev_hwdb_new(struct udev *udev) { _public_ struct udev_hwdb *udev_hwdb_new(struct udev *udev) {
_cleanup_(udev_list_freep) struct udev_list *list = NULL; _cleanup_(udev_list_freep) struct udev_list *list = NULL;
_cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb_internal = NULL; _cleanup_(sd_hwdb_unrefp) sd_hwdb *hwdb_internal = NULL;
struct udev_hwdb *hwdb; struct udev_hwdb *hwdb;
@ -61,7 +61,7 @@ _public_ struct udev_hwdb* udev_hwdb_new(struct udev *udev) {
return hwdb; return hwdb;
} }
static struct udev_hwdb* udev_hwdb_free(struct udev_hwdb *hwdb) { static struct udev_hwdb *udev_hwdb_free(struct udev_hwdb *hwdb) {
assert(hwdb); assert(hwdb);
sd_hwdb_unref(hwdb->hwdb); sd_hwdb_unref(hwdb->hwdb);
@ -102,7 +102,7 @@ DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(struct udev_hwdb, udev_hwdb, udev_hwdb_free
* *
* Returns: a udev_list_entry. * Returns: a udev_list_entry.
*/ */
_public_ struct udev_list_entry* udev_hwdb_get_properties_list_entry(struct udev_hwdb *hwdb, const char *modalias, unsigned flags) { _public_ struct udev_list_entry *udev_hwdb_get_properties_list_entry(struct udev_hwdb *hwdb, const char *modalias, unsigned flags) {
const char *key, *value; const char *key, *value;
struct udev_list_entry *e; struct udev_list_entry *e;

View File

@ -7,10 +7,10 @@
struct udev_list; struct udev_list;
struct udev_list* udev_list_new(bool unique); struct udev_list *udev_list_new(bool unique);
void udev_list_cleanup(struct udev_list *list); void udev_list_cleanup(struct udev_list *list);
struct udev_list* udev_list_free(struct udev_list *list); struct udev_list *udev_list_free(struct udev_list *list);
DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_list*, udev_list_free); DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_list *, udev_list_free);
struct udev_list_entry* udev_list_get_entry(struct udev_list *list); struct udev_list_entry *udev_list_get_entry(struct udev_list *list);
struct udev_list_entry* udev_list_entry_add(struct udev_list *list, const char *name, const char *value); struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *name, const char *value);

View File

@ -4,6 +4,7 @@
#include "hashmap.h" #include "hashmap.h"
#include "libudev-list-internal.h" #include "libudev-list-internal.h"
#include "list.h" #include "list.h"
#include "sort-util.h"
/** /**
* SECTION:libudev-list * SECTION:libudev-list
@ -33,7 +34,7 @@ struct udev_list {
bool uptodate:1; bool uptodate:1;
}; };
static struct udev_list_entry* udev_list_entry_free(struct udev_list_entry *entry) { static struct udev_list_entry *udev_list_entry_free(struct udev_list_entry *entry) {
if (!entry) if (!entry)
return NULL; return NULL;
@ -51,14 +52,9 @@ static struct udev_list_entry* udev_list_entry_free(struct udev_list_entry *entr
return mfree(entry); return mfree(entry);
} }
DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_list_entry*, udev_list_entry_free); DEFINE_TRIVIAL_CLEANUP_FUNC(struct udev_list_entry *, udev_list_entry_free);
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR( struct udev_list *udev_list_new(bool unique) {
udev_list_entry_hash_ops,
char, string_hash_func, string_compare_func,
struct udev_list_entry, udev_list_entry_free);
struct udev_list* udev_list_new(bool unique) {
struct udev_list *list; struct udev_list *list;
list = new(struct udev_list, 1); list = new(struct udev_list, 1);
@ -72,26 +68,36 @@ struct udev_list* udev_list_new(bool unique) {
return list; return list;
} }
struct udev_list_entry* udev_list_entry_add(struct udev_list *list, const char *name, const char *value) { struct udev_list_entry *udev_list_entry_add(struct udev_list *list, const char *_name, const char *_value) {
_cleanup_(udev_list_entry_freep) struct udev_list_entry *entry = NULL; _cleanup_(udev_list_entry_freep) struct udev_list_entry *entry = NULL;
_cleanup_free_ char *name = NULL, *value = NULL;
assert(list); assert(list);
assert(name); assert(_name);
entry = new0(struct udev_list_entry, 1); name = strdup(_name);
if (!name)
return NULL;
if (_value) {
value = strdup(_value);
if (!value)
return NULL;
}
entry = new(struct udev_list_entry, 1);
if (!entry) if (!entry)
return NULL; return NULL;
if (strdup_to(&entry->name, name) < 0) *entry = (struct udev_list_entry) {
return NULL; .name = TAKE_PTR(name),
.value = TAKE_PTR(value),
if (strdup_to(&entry->value, value) < 0) };
return NULL;
if (list->unique) { if (list->unique) {
udev_list_entry_free(hashmap_get(list->unique_entries, entry->name)); udev_list_entry_free(hashmap_get(list->unique_entries, entry->name));
if (hashmap_ensure_put(&list->unique_entries, &udev_list_entry_hash_ops, entry->name, entry) < 0) if (hashmap_ensure_put(&list->unique_entries, &string_hash_ops, entry->name, entry) < 0)
return NULL; return NULL;
list->uptodate = false; list->uptodate = false;
@ -109,13 +115,13 @@ void udev_list_cleanup(struct udev_list *list) {
if (list->unique) { if (list->unique) {
list->uptodate = false; list->uptodate = false;
hashmap_clear(list->unique_entries); hashmap_clear_with_destructor(list->unique_entries, udev_list_entry_free);
} else } else
LIST_FOREACH(entries, i, list->entries) LIST_FOREACH(entries, i, list->entries)
udev_list_entry_free(i); udev_list_entry_free(i);
} }
struct udev_list* udev_list_free(struct udev_list *list) { struct udev_list *udev_list_free(struct udev_list *list) {
if (!list) if (!list)
return NULL; return NULL;
@ -125,7 +131,11 @@ struct udev_list* udev_list_free(struct udev_list *list) {
return mfree(list); return mfree(list);
} }
struct udev_list_entry* udev_list_get_entry(struct udev_list *list) { static int udev_list_entry_compare_func(struct udev_list_entry * const *a, struct udev_list_entry * const *b) {
return strcmp((*a)->name, (*b)->name);
}
struct udev_list_entry *udev_list_get_entry(struct udev_list *list) {
if (!list) if (!list)
return NULL; return NULL;
@ -141,10 +151,18 @@ struct udev_list_entry* udev_list_get_entry(struct udev_list *list) {
LIST_PREPEND(entries, list->entries, hashmap_first(list->unique_entries)); LIST_PREPEND(entries, list->entries, hashmap_first(list->unique_entries));
else { else {
_cleanup_free_ struct udev_list_entry **buf = NULL; _cleanup_free_ struct udev_list_entry **buf = NULL;
struct udev_list_entry *entry, **p;
if (hashmap_dump_sorted(list->unique_entries, (void***) &buf, /* ret_n = */ NULL) < 0) buf = new(struct udev_list_entry *, n);
if (!buf)
return NULL; return NULL;
p = buf;
HASHMAP_FOREACH(entry, list->unique_entries)
*p++ = entry;
typesafe_qsort(buf, n, udev_list_entry_compare_func);
for (size_t j = n; j > 0; j--) for (size_t j = n; j > 0; j--)
LIST_PREPEND(entries, list->entries, buf[j-1]); LIST_PREPEND(entries, list->entries, buf[j-1]);
} }
@ -163,7 +181,7 @@ struct udev_list_entry* udev_list_get_entry(struct udev_list *list) {
* *
* Returns: udev_list_entry, #NULL if no more entries are available. * Returns: udev_list_entry, #NULL if no more entries are available.
*/ */
_public_ struct udev_list_entry* udev_list_entry_get_next(struct udev_list_entry *list_entry) { _public_ struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *list_entry) {
if (!list_entry) if (!list_entry)
return NULL; return NULL;
if (list_entry->list->unique && !list_entry->list->uptodate) if (list_entry->list->unique && !list_entry->list->uptodate)
@ -180,7 +198,7 @@ _public_ struct udev_list_entry* udev_list_entry_get_next(struct udev_list_entry
* *
* Returns: udev_list_entry, #NULL if no matching entry is found. * Returns: udev_list_entry, #NULL if no matching entry is found.
*/ */
_public_ struct udev_list_entry* udev_list_entry_get_by_name(struct udev_list_entry *list_entry, const char *name) { _public_ struct udev_list_entry *udev_list_entry_get_by_name(struct udev_list_entry *list_entry, const char *name) {
if (!list_entry) if (!list_entry)
return NULL; return NULL;
if (!list_entry->list->unique || !list_entry->list->uptodate) if (!list_entry->list->unique || !list_entry->list->uptodate)
@ -196,7 +214,7 @@ _public_ struct udev_list_entry* udev_list_entry_get_by_name(struct udev_list_en
* *
* Returns: the name string of this entry. * Returns: the name string of this entry.
*/ */
_public_ const char* udev_list_entry_get_name(struct udev_list_entry *list_entry) { _public_ const char *udev_list_entry_get_name(struct udev_list_entry *list_entry) {
if (!list_entry) if (!list_entry)
return NULL; return NULL;
return list_entry->name; return list_entry->name;
@ -210,7 +228,7 @@ _public_ const char* udev_list_entry_get_name(struct udev_list_entry *list_entry
* *
* Returns: the value string of this entry. * Returns: the value string of this entry.
*/ */
_public_ const char* udev_list_entry_get_value(struct udev_list_entry *list_entry) { _public_ const char *udev_list_entry_get_value(struct udev_list_entry *list_entry) {
if (!list_entry) if (!list_entry)
return NULL; return NULL;
return list_entry->value; return list_entry->value;

View File

@ -63,7 +63,7 @@ static MonitorNetlinkGroup monitor_netlink_group_from_string(const char *name) {
* *
* Returns: a new udev monitor, or #NULL, in case of an error * Returns: a new udev monitor, or #NULL, in case of an error
**/ **/
_public_ struct udev_monitor* udev_monitor_new_from_netlink(struct udev *udev, const char *name) { _public_ struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char *name) {
_cleanup_(sd_device_monitor_unrefp) sd_device_monitor *m = NULL; _cleanup_(sd_device_monitor_unrefp) sd_device_monitor *m = NULL;
struct udev_monitor *udev_monitor; struct udev_monitor *udev_monitor;
MonitorNetlinkGroup g; MonitorNetlinkGroup g;
@ -133,7 +133,7 @@ _public_ int udev_monitor_set_receive_buffer_size(struct udev_monitor *udev_moni
return sd_device_monitor_set_receive_buffer_size(udev_monitor->monitor, (size_t) size); return sd_device_monitor_set_receive_buffer_size(udev_monitor->monitor, (size_t) size);
} }
static struct udev_monitor* udev_monitor_free(struct udev_monitor *udev_monitor) { static struct udev_monitor *udev_monitor_free(struct udev_monitor *udev_monitor) {
assert(udev_monitor); assert(udev_monitor);
sd_device_monitor_unref(udev_monitor->monitor); sd_device_monitor_unref(udev_monitor->monitor);
@ -169,7 +169,7 @@ DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(struct udev_monitor, udev_monitor, udev_mon
* *
* Returns: the udev library context * Returns: the udev library context
**/ **/
_public_ struct udev* udev_monitor_get_udev(struct udev_monitor *udev_monitor) { _public_ struct udev *udev_monitor_get_udev(struct udev_monitor *udev_monitor) {
assert_return(udev_monitor, NULL); assert_return(udev_monitor, NULL);
return udev_monitor->udev; return udev_monitor->udev;
@ -236,7 +236,7 @@ static int udev_monitor_receive_sd_device(struct udev_monitor *udev_monitor, sd_
* *
* Returns: a new udev device, or #NULL, in case of an error * Returns: a new udev device, or #NULL, in case of an error
**/ **/
_public_ struct udev_device* udev_monitor_receive_device(struct udev_monitor *udev_monitor) { _public_ struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monitor) {
_cleanup_(sd_device_unrefp) sd_device *device = NULL; _cleanup_(sd_device_unrefp) sd_device *device = NULL;
int r; int r;

View File

@ -40,7 +40,7 @@ struct udev_queue {
* *
* Returns: the udev queue context, or #NULL on error. * Returns: the udev queue context, or #NULL on error.
**/ **/
_public_ struct udev_queue* udev_queue_new(struct udev *udev) { _public_ struct udev_queue *udev_queue_new(struct udev *udev) {
struct udev_queue *udev_queue; struct udev_queue *udev_queue;
udev_queue = new(struct udev_queue, 1); udev_queue = new(struct udev_queue, 1);
@ -56,7 +56,7 @@ _public_ struct udev_queue* udev_queue_new(struct udev *udev) {
return udev_queue; return udev_queue;
} }
static struct udev_queue* udev_queue_free(struct udev_queue *udev_queue) { static struct udev_queue *udev_queue_free(struct udev_queue *udev_queue) {
assert(udev_queue); assert(udev_queue);
safe_close(udev_queue->fd); safe_close(udev_queue->fd);
@ -91,7 +91,7 @@ DEFINE_PUBLIC_TRIVIAL_REF_UNREF_FUNC(struct udev_queue, udev_queue, udev_queue_f
* *
* Returns: the udev library context. * Returns: the udev library context.
**/ **/
_public_ struct udev* udev_queue_get_udev(struct udev_queue *udev_queue) { _public_ struct udev *udev_queue_get_udev(struct udev_queue *udev_queue) {
assert_return_errno(udev_queue, NULL, EINVAL); assert_return_errno(udev_queue, NULL, EINVAL);
return udev_queue->udev; return udev_queue->udev;
@ -155,11 +155,8 @@ _public_ int udev_queue_get_queue_is_empty(struct udev_queue *udev_queue) {
* *
* Returns: a flag indicating if udev is currently handling events. * Returns: a flag indicating if udev is currently handling events.
**/ **/
_public_ int udev_queue_get_seqnum_sequence_is_finished( _public_ int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_queue,
struct udev_queue *udev_queue, unsigned long long int start, unsigned long long int end) {
unsigned long long int start,
unsigned long long int end) {
return udev_queue_is_empty() > 0; return udev_queue_is_empty() > 0;
} }
@ -184,7 +181,7 @@ _public_ int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, un
* *
* Returns: NULL. * Returns: NULL.
**/ **/
_public_ struct udev_list_entry* udev_queue_get_queued_list_entry(struct udev_queue *udev_queue) { _public_ struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev_queue) {
return_with_errno(NULL, ENODATA); return_with_errno(NULL, ENODATA);
} }

View File

@ -36,7 +36,7 @@ struct udev {
* *
* Returns: stored userdata * Returns: stored userdata
**/ **/
_public_ void* udev_get_userdata(struct udev *udev) { _public_ void *udev_get_userdata(struct udev *udev) {
assert_return(udev, NULL); assert_return(udev, NULL);
return udev->userdata; return udev->userdata;
@ -66,7 +66,7 @@ _public_ void udev_set_userdata(struct udev *udev, void *userdata) {
* *
* Returns: a new udev library context * Returns: a new udev library context
**/ **/
_public_ struct udev* udev_new(void) { _public_ struct udev *udev_new(void) {
struct udev *udev; struct udev *udev;
udev = new(struct udev, 1); udev = new(struct udev, 1);
@ -99,7 +99,7 @@ DEFINE_PUBLIC_TRIVIAL_REF_FUNC(struct udev, udev);
* *
* Returns: the passed udev library context if it has still an active reference, or #NULL otherwise. * Returns: the passed udev library context if it has still an active reference, or #NULL otherwise.
**/ **/
_public_ struct udev* udev_unref(struct udev *udev) { _public_ struct udev *udev_unref(struct udev *udev) {
if (!udev) if (!udev)
return NULL; return NULL;
@ -123,14 +123,10 @@ _public_ struct udev* udev_unref(struct udev *udev) {
* *
**/ **/
_public_ void udev_set_log_fn( _public_ void udev_set_log_fn(
struct udev *udev, struct udev *udev,
void (*log_fn)(struct udev *udev, void (*log_fn)(struct udev *udev,
int priority, int priority, const char *file, int line, const char *fn,
const char *file, const char *format, va_list args)) {
int line,
const char *fn,
const char *format,
va_list args)) {
return; return;
} }

View File

@ -18,21 +18,16 @@ extern "C" {
* allows custom logging * allows custom logging
*/ */
struct udev; struct udev;
struct udev* udev_ref(struct udev *udev); struct udev *udev_ref(struct udev *udev);
struct udev* udev_unref(struct udev *udev); struct udev *udev_unref(struct udev *udev);
struct udev* udev_new(void); struct udev *udev_new(void);
void udev_set_log_fn( void udev_set_log_fn(struct udev *udev,
struct udev *udev, void (*log_fn)(struct udev *udev,
void (*log_fn)(struct udev *udev, int priority, const char *file, int line, const char *fn,
int priority, const char *format, va_list args)) __attribute__((__deprecated__));
const char *file,
int line,
const char *fn,
const char *format,
va_list args)) __attribute__((__deprecated__));
int udev_get_log_priority(struct udev *udev) __attribute__((__deprecated__)); int udev_get_log_priority(struct udev *udev) __attribute__((__deprecated__));
void udev_set_log_priority(struct udev *udev, int priority) __attribute__((__deprecated__)); void udev_set_log_priority(struct udev *udev, int priority) __attribute__((__deprecated__));
void* udev_get_userdata(struct udev *udev); void *udev_get_userdata(struct udev *udev);
void udev_set_userdata(struct udev *udev, void *userdata); void udev_set_userdata(struct udev *udev, void *userdata);
/* /*
@ -41,8 +36,8 @@ void udev_set_userdata(struct udev *udev, void *userdata);
* access to libudev generated lists * access to libudev generated lists
*/ */
struct udev_list_entry; struct udev_list_entry;
struct udev_list_entry* udev_list_entry_get_next(struct udev_list_entry *list_entry); struct udev_list_entry *udev_list_entry_get_next(struct udev_list_entry *list_entry);
struct udev_list_entry* udev_list_entry_get_by_name(struct udev_list_entry *list_entry, const char *name); struct udev_list_entry *udev_list_entry_get_by_name(struct udev_list_entry *list_entry, const char *name);
const char* udev_list_entry_get_name(struct udev_list_entry *list_entry); const char* udev_list_entry_get_name(struct udev_list_entry *list_entry);
const char* udev_list_entry_get_value(struct udev_list_entry *list_entry); const char* udev_list_entry_get_value(struct udev_list_entry *list_entry);
/** /**
@ -63,20 +58,18 @@ const char* udev_list_entry_get_value(struct udev_list_entry *list_entry);
* access to sysfs/kernel devices * access to sysfs/kernel devices
*/ */
struct udev_device; struct udev_device;
struct udev_device* udev_device_ref(struct udev_device *udev_device); struct udev_device *udev_device_ref(struct udev_device *udev_device);
struct udev_device* udev_device_unref(struct udev_device *udev_device); struct udev_device *udev_device_unref(struct udev_device *udev_device);
struct udev* udev_device_get_udev(struct udev_device *udev_device); struct udev *udev_device_get_udev(struct udev_device *udev_device);
struct udev_device* udev_device_new_from_syspath(struct udev *udev, const char *syspath); struct udev_device *udev_device_new_from_syspath(struct udev *udev, const char *syspath);
struct udev_device* udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum); struct udev_device *udev_device_new_from_devnum(struct udev *udev, char type, dev_t devnum);
struct udev_device* udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname); struct udev_device *udev_device_new_from_subsystem_sysname(struct udev *udev, const char *subsystem, const char *sysname);
struct udev_device* udev_device_new_from_device_id(struct udev *udev, const char *id); struct udev_device *udev_device_new_from_device_id(struct udev *udev, const char *id);
struct udev_device* udev_device_new_from_environment(struct udev *udev); struct udev_device *udev_device_new_from_environment(struct udev *udev);
/* udev_device_get_parent_*() does not take a reference on the returned device, it is automatically unref'd with the parent */ /* udev_device_get_parent_*() does not take a reference on the returned device, it is automatically unref'd with the parent */
struct udev_device* udev_device_get_parent(struct udev_device *udev_device); struct udev_device *udev_device_get_parent(struct udev_device *udev_device);
struct udev_device* udev_device_get_parent_with_subsystem_devtype( struct udev_device *udev_device_get_parent_with_subsystem_devtype(struct udev_device *udev_device,
struct udev_device *udev_device, const char *subsystem, const char *devtype);
const char *subsystem,
const char *devtype);
/* retrieve device properties */ /* retrieve device properties */
const char* udev_device_get_devpath(struct udev_device *udev_device); const char* udev_device_get_devpath(struct udev_device *udev_device);
const char* udev_device_get_subsystem(struct udev_device *udev_device); const char* udev_device_get_subsystem(struct udev_device *udev_device);
@ -86,11 +79,11 @@ const char* udev_device_get_sysname(struct udev_device *udev_device);
const char* udev_device_get_sysnum(struct udev_device *udev_device); const char* udev_device_get_sysnum(struct udev_device *udev_device);
const char* udev_device_get_devnode(struct udev_device *udev_device); const char* udev_device_get_devnode(struct udev_device *udev_device);
int udev_device_get_is_initialized(struct udev_device *udev_device); int udev_device_get_is_initialized(struct udev_device *udev_device);
struct udev_list_entry* udev_device_get_devlinks_list_entry(struct udev_device *udev_device); struct udev_list_entry *udev_device_get_devlinks_list_entry(struct udev_device *udev_device);
struct udev_list_entry* udev_device_get_properties_list_entry(struct udev_device *udev_device); struct udev_list_entry *udev_device_get_properties_list_entry(struct udev_device *udev_device);
struct udev_list_entry* udev_device_get_tags_list_entry(struct udev_device *udev_device); struct udev_list_entry *udev_device_get_tags_list_entry(struct udev_device *udev_device);
struct udev_list_entry* udev_device_get_current_tags_list_entry(struct udev_device *udev_device); struct udev_list_entry *udev_device_get_current_tags_list_entry(struct udev_device *udev_device);
struct udev_list_entry* udev_device_get_sysattr_list_entry(struct udev_device *udev_device); struct udev_list_entry *udev_device_get_sysattr_list_entry(struct udev_device *udev_device);
const char* udev_device_get_property_value(struct udev_device *udev_device, const char *key); const char* udev_device_get_property_value(struct udev_device *udev_device, const char *key);
const char* udev_device_get_driver(struct udev_device *udev_device); const char* udev_device_get_driver(struct udev_device *udev_device);
dev_t udev_device_get_devnum(struct udev_device *udev_device); dev_t udev_device_get_devnum(struct udev_device *udev_device);
@ -108,21 +101,19 @@ int udev_device_has_current_tag(struct udev_device *udev_device, const char *tag
* access to kernel uevents and udev events * access to kernel uevents and udev events
*/ */
struct udev_monitor; struct udev_monitor;
struct udev_monitor* udev_monitor_ref(struct udev_monitor *udev_monitor); struct udev_monitor *udev_monitor_ref(struct udev_monitor *udev_monitor);
struct udev_monitor* udev_monitor_unref(struct udev_monitor *udev_monitor); struct udev_monitor *udev_monitor_unref(struct udev_monitor *udev_monitor);
struct udev* udev_monitor_get_udev(struct udev_monitor *udev_monitor); struct udev *udev_monitor_get_udev(struct udev_monitor *udev_monitor);
/* kernel and udev generated events over netlink */ /* kernel and udev generated events over netlink */
struct udev_monitor* udev_monitor_new_from_netlink(struct udev *udev, const char *name); struct udev_monitor *udev_monitor_new_from_netlink(struct udev *udev, const char *name);
/* bind socket */ /* bind socket */
int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor); int udev_monitor_enable_receiving(struct udev_monitor *udev_monitor);
int udev_monitor_set_receive_buffer_size(struct udev_monitor *udev_monitor, int size); int udev_monitor_set_receive_buffer_size(struct udev_monitor *udev_monitor, int size);
int udev_monitor_get_fd(struct udev_monitor *udev_monitor); int udev_monitor_get_fd(struct udev_monitor *udev_monitor);
struct udev_device* udev_monitor_receive_device(struct udev_monitor *udev_monitor); struct udev_device *udev_monitor_receive_device(struct udev_monitor *udev_monitor);
/* in-kernel socket filters to select messages that get delivered to a listener */ /* in-kernel socket filters to select messages that get delivered to a listener */
int udev_monitor_filter_add_match_subsystem_devtype( int udev_monitor_filter_add_match_subsystem_devtype(struct udev_monitor *udev_monitor,
struct udev_monitor *udev_monitor, const char *subsystem, const char *devtype);
const char *subsystem,
const char *devtype);
int udev_monitor_filter_add_match_tag(struct udev_monitor *udev_monitor, const char *tag); int udev_monitor_filter_add_match_tag(struct udev_monitor *udev_monitor, const char *tag);
int udev_monitor_filter_update(struct udev_monitor *udev_monitor); int udev_monitor_filter_update(struct udev_monitor *udev_monitor);
int udev_monitor_filter_remove(struct udev_monitor *udev_monitor); int udev_monitor_filter_remove(struct udev_monitor *udev_monitor);
@ -133,10 +124,10 @@ int udev_monitor_filter_remove(struct udev_monitor *udev_monitor);
* search sysfs for specific devices and provide a sorted list * search sysfs for specific devices and provide a sorted list
*/ */
struct udev_enumerate; struct udev_enumerate;
struct udev_enumerate* udev_enumerate_ref(struct udev_enumerate *udev_enumerate); struct udev_enumerate *udev_enumerate_ref(struct udev_enumerate *udev_enumerate);
struct udev_enumerate* udev_enumerate_unref(struct udev_enumerate *udev_enumerate); struct udev_enumerate *udev_enumerate_unref(struct udev_enumerate *udev_enumerate);
struct udev* udev_enumerate_get_udev(struct udev_enumerate *udev_enumerate); struct udev *udev_enumerate_get_udev(struct udev_enumerate *udev_enumerate);
struct udev_enumerate* udev_enumerate_new(struct udev *udev); struct udev_enumerate *udev_enumerate_new(struct udev *udev);
/* device properties filter */ /* device properties filter */
int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem); int udev_enumerate_add_match_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem);
int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem); int udev_enumerate_add_nomatch_subsystem(struct udev_enumerate *udev_enumerate, const char *subsystem);
@ -152,7 +143,7 @@ int udev_enumerate_add_syspath(struct udev_enumerate *udev_enumerate, const char
int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate); int udev_enumerate_scan_devices(struct udev_enumerate *udev_enumerate);
int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate); int udev_enumerate_scan_subsystems(struct udev_enumerate *udev_enumerate);
/* return device list */ /* return device list */
struct udev_list_entry* udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate); struct udev_list_entry *udev_enumerate_get_list_entry(struct udev_enumerate *udev_enumerate);
/* /*
* udev_queue * udev_queue
@ -160,22 +151,20 @@ struct udev_list_entry* udev_enumerate_get_list_entry(struct udev_enumerate *ude
* access to the currently running udev events * access to the currently running udev events
*/ */
struct udev_queue; struct udev_queue;
struct udev_queue* udev_queue_ref(struct udev_queue *udev_queue); struct udev_queue *udev_queue_ref(struct udev_queue *udev_queue);
struct udev_queue* udev_queue_unref(struct udev_queue *udev_queue); struct udev_queue *udev_queue_unref(struct udev_queue *udev_queue);
struct udev* udev_queue_get_udev(struct udev_queue *udev_queue); struct udev *udev_queue_get_udev(struct udev_queue *udev_queue);
struct udev_queue* udev_queue_new(struct udev *udev); struct udev_queue *udev_queue_new(struct udev *udev);
unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue *udev_queue) __attribute__((__deprecated__)); unsigned long long int udev_queue_get_kernel_seqnum(struct udev_queue *udev_queue) __attribute__((__deprecated__));
unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue *udev_queue) __attribute__((__deprecated__)); unsigned long long int udev_queue_get_udev_seqnum(struct udev_queue *udev_queue) __attribute__((__deprecated__));
int udev_queue_get_udev_is_active(struct udev_queue *udev_queue); int udev_queue_get_udev_is_active(struct udev_queue *udev_queue);
int udev_queue_get_queue_is_empty(struct udev_queue *udev_queue); int udev_queue_get_queue_is_empty(struct udev_queue *udev_queue);
int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, unsigned long long int seqnum) __attribute__((__deprecated__)); int udev_queue_get_seqnum_is_finished(struct udev_queue *udev_queue, unsigned long long int seqnum) __attribute__((__deprecated__));
int udev_queue_get_seqnum_sequence_is_finished( int udev_queue_get_seqnum_sequence_is_finished(struct udev_queue *udev_queue,
struct udev_queue *udev_queue, unsigned long long int start, unsigned long long int end) __attribute__((__deprecated__));
unsigned long long int start,
unsigned long long int end) __attribute__((__deprecated__));
int udev_queue_get_fd(struct udev_queue *udev_queue); int udev_queue_get_fd(struct udev_queue *udev_queue);
int udev_queue_flush(struct udev_queue *udev_queue); int udev_queue_flush(struct udev_queue *udev_queue);
struct udev_list_entry* udev_queue_get_queued_list_entry(struct udev_queue *udev_queue) __attribute__((__deprecated__)); struct udev_list_entry *udev_queue_get_queued_list_entry(struct udev_queue *udev_queue) __attribute__((__deprecated__));
/* /*
* udev_hwdb * udev_hwdb
@ -183,10 +172,10 @@ struct udev_list_entry* udev_queue_get_queued_list_entry(struct udev_queue *udev
* access to the static hardware properties database * access to the static hardware properties database
*/ */
struct udev_hwdb; struct udev_hwdb;
struct udev_hwdb* udev_hwdb_new(struct udev *udev); struct udev_hwdb *udev_hwdb_new(struct udev *udev);
struct udev_hwdb* udev_hwdb_ref(struct udev_hwdb *hwdb); struct udev_hwdb *udev_hwdb_ref(struct udev_hwdb *hwdb);
struct udev_hwdb* udev_hwdb_unref(struct udev_hwdb *hwdb); struct udev_hwdb *udev_hwdb_unref(struct udev_hwdb *hwdb);
struct udev_list_entry* udev_hwdb_get_properties_list_entry(struct udev_hwdb *hwdb, const char *modalias, unsigned flags); struct udev_list_entry *udev_hwdb_get_properties_list_entry(struct udev_hwdb *hwdb, const char *modalias, unsigned flags);
/* /*
* udev_util * udev_util

View File

@ -536,7 +536,7 @@ static int method_set_tty(sd_bus_message *message, void *userdata, sd_bus_error
flags = fcntl(fd, F_GETFL, 0); flags = fcntl(fd, F_GETFL, 0);
if (flags < 0) if (flags < 0)
return -errno; return -errno;
if ((flags & O_ACCMODE_STRICT) != O_RDWR) if ((flags & O_ACCMODE) != O_RDWR)
return -EACCES; return -EACCES;
if (FLAGS_SET(flags, O_PATH)) if (FLAGS_SET(flags, O_PATH))
return -ENOTTY; return -ENOTTY;

View File

@ -99,7 +99,7 @@ static int validate_image_fd(int fd, MountImageParameters *p) {
if (fl < 0) if (fl < 0)
return log_debug_errno(fl, "Image file descriptor has unsafe flags set: %m"); return log_debug_errno(fl, "Image file descriptor has unsafe flags set: %m");
switch (fl & O_ACCMODE_STRICT) { switch (fl & O_ACCMODE) {
case O_RDONLY: case O_RDONLY:
p->read_only = true; p->read_only = true;

View File

@ -22,7 +22,8 @@
#define STATIC_BRIDGE_FDB_ENTRIES_PER_NETWORK_MAX 1024U #define STATIC_BRIDGE_FDB_ENTRIES_PER_NETWORK_MAX 1024U
static BridgeFDB* bridge_fdb_free(BridgeFDB *fdb) { /* remove and FDB entry. */
BridgeFDB *bridge_fdb_free(BridgeFDB *fdb) {
if (!fdb) if (!fdb)
return NULL; return NULL;
@ -39,11 +40,7 @@ static BridgeFDB* bridge_fdb_free(BridgeFDB *fdb) {
DEFINE_SECTION_CLEANUP_FUNCTIONS(BridgeFDB, bridge_fdb_free); DEFINE_SECTION_CLEANUP_FUNCTIONS(BridgeFDB, bridge_fdb_free);
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR( /* create a new FDB entry or get an existing one. */
bridge_fdb_hash_ops_by_section,
ConfigSection, config_section_hash_func, config_section_compare_func,
BridgeFDB, bridge_fdb_free);
static int bridge_fdb_new_static( static int bridge_fdb_new_static(
Network *network, Network *network,
const char *filename, const char *filename,
@ -86,12 +83,13 @@ static int bridge_fdb_new_static(
.ntf_flags = NEIGHBOR_CACHE_ENTRY_FLAGS_SELF, .ntf_flags = NEIGHBOR_CACHE_ENTRY_FLAGS_SELF,
}; };
r = hashmap_ensure_put(&network->bridge_fdb_entries_by_section, &bridge_fdb_hash_ops_by_section, fdb->section, fdb); r = hashmap_ensure_put(&network->bridge_fdb_entries_by_section, &config_section_hash_ops, fdb->section, fdb);
if (r < 0) if (r < 0)
return r; return r;
/* return allocated FDB structure. */ /* return allocated FDB structure. */
*ret = TAKE_PTR(fdb); *ret = TAKE_PTR(fdb);
return 0; return 0;
} }

View File

@ -40,6 +40,8 @@ typedef struct BridgeFDB {
int outgoing_ifindex; int outgoing_ifindex;
} BridgeFDB; } BridgeFDB;
BridgeFDB *bridge_fdb_free(BridgeFDB *fdb);
void network_drop_invalid_bridge_fdb_entries(Network *network); void network_drop_invalid_bridge_fdb_entries(Network *network);
int link_request_static_bridge_fdb(Link *link); int link_request_static_bridge_fdb(Link *link);

View File

@ -10,13 +10,13 @@
#include "networkd-manager.h" #include "networkd-manager.h"
#include "networkd-network.h" #include "networkd-network.h"
#include "networkd-queue.h" #include "networkd-queue.h"
#include "networkd-util.h"
#include "string-util.h" #include "string-util.h"
#include "vlan-util.h" #include "vlan-util.h"
#define STATIC_BRIDGE_MDB_ENTRIES_PER_NETWORK_MAX 1024U #define STATIC_BRIDGE_MDB_ENTRIES_PER_NETWORK_MAX 1024U
static BridgeMDB* bridge_mdb_free(BridgeMDB *mdb) { /* remove MDB entry. */
BridgeMDB *bridge_mdb_free(BridgeMDB *mdb) {
if (!mdb) if (!mdb)
return NULL; return NULL;
@ -32,11 +32,7 @@ static BridgeMDB* bridge_mdb_free(BridgeMDB *mdb) {
DEFINE_SECTION_CLEANUP_FUNCTIONS(BridgeMDB, bridge_mdb_free); DEFINE_SECTION_CLEANUP_FUNCTIONS(BridgeMDB, bridge_mdb_free);
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR( /* create a new MDB entry or get an existing one. */
bridge_mdb_hash_ops_by_section,
ConfigSection, config_section_hash_func, config_section_compare_func,
BridgeMDB, bridge_mdb_free);
static int bridge_mdb_new_static( static int bridge_mdb_new_static(
Network *network, Network *network,
const char *filename, const char *filename,
@ -78,7 +74,7 @@ static int bridge_mdb_new_static(
.type = _BRIDGE_MDB_ENTRY_TYPE_INVALID, .type = _BRIDGE_MDB_ENTRY_TYPE_INVALID,
}; };
r = hashmap_ensure_put(&network->bridge_mdb_entries_by_section, &bridge_mdb_hash_ops_by_section, mdb->section, mdb); r = hashmap_ensure_put(&network->bridge_mdb_entries_by_section, &config_section_hash_ops, mdb->section, mdb);
if (r < 0) if (r < 0)
return r; return r;

View File

@ -5,6 +5,7 @@
#include "conf-parser.h" #include "conf-parser.h"
#include "in-addr-util.h" #include "in-addr-util.h"
#include "networkd-util.h"
typedef struct Link Link; typedef struct Link Link;
typedef struct Network Network; typedef struct Network Network;
@ -29,6 +30,8 @@ typedef struct BridgeMDB {
uint16_t vlan_id; uint16_t vlan_id;
} BridgeMDB; } BridgeMDB;
BridgeMDB *bridge_mdb_free(BridgeMDB *mdb);
void network_drop_invalid_bridge_mdb_entries(Network *network); void network_drop_invalid_bridge_mdb_entries(Network *network);
int link_request_static_bridge_mdb(Link *link); int link_request_static_bridge_mdb(Link *link);

View File

@ -7,7 +7,9 @@
#include "networkd-network.h" #include "networkd-network.h"
#include "networkd-util.h" #include "networkd-util.h"
static DHCPStaticLease* dhcp_static_lease_free(DHCPStaticLease *static_lease) { DEFINE_SECTION_CLEANUP_FUNCTIONS(DHCPStaticLease, dhcp_static_lease_free);
DHCPStaticLease *dhcp_static_lease_free(DHCPStaticLease *static_lease) {
if (!static_lease) if (!static_lease)
return NULL; return NULL;
@ -19,13 +21,6 @@ static DHCPStaticLease* dhcp_static_lease_free(DHCPStaticLease *static_lease) {
return mfree(static_lease); return mfree(static_lease);
} }
DEFINE_SECTION_CLEANUP_FUNCTIONS(DHCPStaticLease, dhcp_static_lease_free);
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
static_lease_hash_ops_by_section,
ConfigSection, config_section_hash_func, config_section_compare_func,
DHCPStaticLease, dhcp_static_lease_free);
static int dhcp_static_lease_new(DHCPStaticLease **ret) { static int dhcp_static_lease_new(DHCPStaticLease **ret) {
DHCPStaticLease *p; DHCPStaticLease *p;
@ -65,8 +60,7 @@ static int lease_new_static(Network *network, const char *filename, unsigned sec
static_lease->network = network; static_lease->network = network;
static_lease->section = TAKE_PTR(n); static_lease->section = TAKE_PTR(n);
r = hashmap_ensure_put(&network->dhcp_static_leases_by_section, &config_section_hash_ops, static_lease->section, static_lease);
r = hashmap_ensure_put(&network->dhcp_static_leases_by_section, &static_lease_hash_ops_by_section, static_lease->section, static_lease);
if (r < 0) if (r < 0)
return r; return r;

View File

@ -19,6 +19,7 @@ typedef struct DHCPStaticLease {
size_t client_id_size; size_t client_id_size;
} DHCPStaticLease; } DHCPStaticLease;
DHCPStaticLease *dhcp_static_lease_free(DHCPStaticLease *lease);
void network_drop_invalid_static_leases(Network *network); void network_drop_invalid_static_leases(Network *network);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_static_lease_address); CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_static_lease_address);

View File

@ -281,7 +281,7 @@ int config_parse_dnssec_negative_trust_anchors(
assert(rvalue); assert(rvalue);
if (isempty(rvalue)) { if (isempty(rvalue)) {
*nta = set_free(*nta); *nta = set_free_free(*nta);
return 0; return 0;
} }
@ -306,7 +306,7 @@ int config_parse_dnssec_negative_trust_anchors(
continue; continue;
} }
r = set_ensure_consume(nta, &dns_name_hash_ops_free, TAKE_PTR(w)); r = set_ensure_consume(nta, &dns_name_hash_ops, TAKE_PTR(w));
if (r < 0) if (r < 0)
return log_oom(); return log_oom();
} }

View File

@ -22,13 +22,7 @@ void network_adjust_ipv6_proxy_ndp(Network *network) {
log_once(LOG_WARNING, log_once(LOG_WARNING,
"%s: IPv6 proxy NDP addresses are set, but IPv6 is not supported by kernel, " "%s: IPv6 proxy NDP addresses are set, but IPv6 is not supported by kernel, "
"Ignoring IPv6 proxy NDP addresses.", network->filename); "Ignoring IPv6 proxy NDP addresses.", network->filename);
network->ipv6_proxy_ndp_addresses = set_free(network->ipv6_proxy_ndp_addresses); network->ipv6_proxy_ndp_addresses = set_free_free(network->ipv6_proxy_ndp_addresses);
return;
}
if (network->ipv6_proxy_ndp == 0) {
log_warning("%s: IPv6ProxyNDP= is disabled. Ignoring IPv6ProxyNDPAddress=.", network->filename);
network->ipv6_proxy_ndp_addresses = set_free(network->ipv6_proxy_ndp_addresses);
} }
} }
@ -155,7 +149,7 @@ int config_parse_ipv6_proxy_ndp_address(
assert(rvalue); assert(rvalue);
if (isempty(rvalue)) { if (isempty(rvalue)) {
network->ipv6_proxy_ndp_addresses = set_free(network->ipv6_proxy_ndp_addresses); network->ipv6_proxy_ndp_addresses = set_free_free(network->ipv6_proxy_ndp_addresses);
return 0; return 0;
} }
@ -176,9 +170,11 @@ int config_parse_ipv6_proxy_ndp_address(
if (!address) if (!address)
return log_oom(); return log_oom();
r = set_ensure_consume(&network->ipv6_proxy_ndp_addresses, &in6_addr_hash_ops_free, TAKE_PTR(address)); r = set_ensure_put(&network->ipv6_proxy_ndp_addresses, &in6_addr_hash_ops, address);
if (r < 0) if (r < 0)
return log_oom(); return log_oom();
if (r > 0)
TAKE_PTR(address);
return 0; return 0;
} }

View File

@ -479,7 +479,7 @@ int bus_link_method_set_dnssec(sd_bus_message *message, void *userdata, sd_bus_e
} }
int bus_link_method_set_dnssec_negative_trust_anchors(sd_bus_message *message, void *userdata, sd_bus_error *error) { int bus_link_method_set_dnssec_negative_trust_anchors(sd_bus_message *message, void *userdata, sd_bus_error *error) {
_cleanup_set_free_ Set *ns = NULL; _cleanup_set_free_free_ Set *ns = NULL;
_cleanup_strv_free_ char **ntas = NULL; _cleanup_strv_free_ char **ntas = NULL;
Link *l = ASSERT_PTR(userdata); Link *l = ASSERT_PTR(userdata);
int r; int r;
@ -502,7 +502,7 @@ int bus_link_method_set_dnssec_negative_trust_anchors(sd_bus_message *message, v
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid negative trust anchor domain: %s", *i); return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid negative trust anchor domain: %s", *i);
} }
ns = set_new(&dns_name_hash_ops_free); ns = set_new(&dns_name_hash_ops);
if (!ns) if (!ns)
return -ENOMEM; return -ENOMEM;
@ -523,7 +523,8 @@ int bus_link_method_set_dnssec_negative_trust_anchors(sd_bus_message *message, v
if (r == 0) if (r == 0)
return 1; /* Polkit will call us back */ return 1; /* Polkit will call us back */
set_free_and_replace(l->dnssec_negative_trust_anchors, ns); set_free_free(l->dnssec_negative_trust_anchors);
l->dnssec_negative_trust_anchors = TAKE_PTR(ns);
r = link_save_and_clean_full(l, /* also_save_manager = */ true); r = link_save_and_clean_full(l, /* also_save_manager = */ true);
if (r < 0) if (r < 0)

View File

@ -231,7 +231,7 @@ void link_dns_settings_clear(Link *link) {
link->dnssec_mode = _DNSSEC_MODE_INVALID; link->dnssec_mode = _DNSSEC_MODE_INVALID;
link->dns_over_tls_mode = _DNS_OVER_TLS_MODE_INVALID; link->dns_over_tls_mode = _DNS_OVER_TLS_MODE_INVALID;
link->dnssec_negative_trust_anchors = set_free(link->dnssec_negative_trust_anchors); link->dnssec_negative_trust_anchors = set_free_free(link->dnssec_negative_trust_anchors);
} }
static void link_free_engines(Link *link) { static void link_free_engines(Link *link) {
@ -261,7 +261,7 @@ static void link_free_engines(Link *link) {
link->radv = sd_radv_unref(link->radv); link->radv = sd_radv_unref(link->radv);
} }
static Link* link_free(Link *link) { static Link *link_free(Link *link) {
assert(link); assert(link);
(void) link_clear_sysctl_shadows(link); (void) link_clear_sysctl_shadows(link);
@ -295,7 +295,7 @@ static Link* link_free(Link *link) {
hashmap_free(link->bound_to_links); hashmap_free(link->bound_to_links);
hashmap_free(link->bound_by_links); hashmap_free(link->bound_by_links);
set_free(link->slaves); set_free_with_destructor(link->slaves, link_unref);
network_unref(link->network); network_unref(link->network);
@ -307,11 +307,6 @@ static Link* link_free(Link *link) {
DEFINE_TRIVIAL_REF_UNREF_FUNC(Link, link, link_free); DEFINE_TRIVIAL_REF_UNREF_FUNC(Link, link, link_free);
DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
link_hash_ops,
void, trivial_hash_func, trivial_compare_func,
Link, link_unref);
int link_get_by_index(Manager *m, int ifindex, Link **ret) { int link_get_by_index(Manager *m, int ifindex, Link **ret) {
Link *link; Link *link;
@ -990,7 +985,7 @@ static int link_append_to_master(Link *link) {
if (link_get_master(link, &master) < 0) if (link_get_master(link, &master) < 0)
return 0; return 0;
r = set_ensure_put(&master->slaves, &link_hash_ops, link); r = set_ensure_put(&master->slaves, NULL, link);
if (r <= 0) if (r <= 0)
return r; return r;
@ -2751,7 +2746,7 @@ static int link_new(Manager *manager, sd_netlink_message *message, Link **ret) {
.dns_over_tls_mode = _DNS_OVER_TLS_MODE_INVALID, .dns_over_tls_mode = _DNS_OVER_TLS_MODE_INVALID,
}; };
r = hashmap_ensure_put(&manager->links_by_index, &link_hash_ops, INT_TO_PTR(link->ifindex), link); r = hashmap_ensure_put(&manager->links_by_index, NULL, INT_TO_PTR(link->ifindex), link);
if (r < 0) if (r < 0)
return log_link_debug_errno(link, r, "Failed to store link into manager: %m"); return log_link_debug_errno(link, r, "Failed to store link into manager: %m");

View File

@ -222,8 +222,6 @@ typedef struct Link {
char **ntp; char **ntp;
} Link; } Link;
extern const struct hash_ops link_hash_ops;
typedef int (*link_netlink_message_handler_t)(sd_netlink*, sd_netlink_message*, Link*); typedef int (*link_netlink_message_handler_t)(sd_netlink*, sd_netlink_message*, Link*);
bool link_is_ready_to_configure(Link *link, bool allow_unmanaged); bool link_is_ready_to_configure(Link *link, bool allow_unmanaged);

View File

@ -672,16 +672,15 @@ Manager* manager_free(Manager *m) {
m->request_queue = ordered_set_free(m->request_queue); m->request_queue = ordered_set_free(m->request_queue);
m->remove_request_queue = ordered_set_free(m->remove_request_queue); m->remove_request_queue = ordered_set_free(m->remove_request_queue);
m->dirty_links = set_free_with_destructor(m->dirty_links, link_unref);
m->new_wlan_ifindices = set_free(m->new_wlan_ifindices); m->new_wlan_ifindices = set_free(m->new_wlan_ifindices);
m->dirty_links = set_free(m->dirty_links);
m->links_by_name = hashmap_free(m->links_by_name); m->links_by_name = hashmap_free(m->links_by_name);
m->links_by_hw_addr = hashmap_free(m->links_by_hw_addr); m->links_by_hw_addr = hashmap_free(m->links_by_hw_addr);
m->links_by_dhcp_pd_subnet_prefix = hashmap_free(m->links_by_dhcp_pd_subnet_prefix); m->links_by_dhcp_pd_subnet_prefix = hashmap_free(m->links_by_dhcp_pd_subnet_prefix);
m->links_by_index = hashmap_free(m->links_by_index); m->links_by_index = hashmap_free_with_destructor(m->links_by_index, link_unref);
m->dhcp_pd_subnet_ids = set_free(m->dhcp_pd_subnet_ids); m->dhcp_pd_subnet_ids = set_free(m->dhcp_pd_subnet_ids);
m->networks = ordered_hashmap_free(m->networks); m->networks = ordered_hashmap_free_with_destructor(m->networks, network_unref);
/* The same object may be registered with multiple names, and netdev_detach() may drop multiple /* The same object may be registered with multiple names, and netdev_detach() may drop multiple
* entries. Hence, hashmap_free_with_destructor() cannot be used. */ * entries. Hence, hashmap_free_with_destructor() cannot be used. */
@ -692,7 +691,7 @@ Manager* manager_free(Manager *m) {
m->tuntap_fds_by_name = hashmap_free(m->tuntap_fds_by_name); m->tuntap_fds_by_name = hashmap_free(m->tuntap_fds_by_name);
m->wiphy_by_name = hashmap_free(m->wiphy_by_name); m->wiphy_by_name = hashmap_free(m->wiphy_by_name);
m->wiphy_by_index = hashmap_free(m->wiphy_by_index); m->wiphy_by_index = hashmap_free_with_destructor(m->wiphy_by_index, wiphy_free);
ordered_set_free(m->address_pools); ordered_set_free(m->address_pools);

View File

@ -89,11 +89,11 @@ void network_adjust_ndisc(Network *network) {
/* When RouterAllowList=, PrefixAllowList= or RouteAllowList= are specified, then /* When RouterAllowList=, PrefixAllowList= or RouteAllowList= are specified, then
* RouterDenyList=, PrefixDenyList= or RouteDenyList= are ignored, respectively. */ * RouterDenyList=, PrefixDenyList= or RouteDenyList= are ignored, respectively. */
if (!set_isempty(network->ndisc_allow_listed_router)) if (!set_isempty(network->ndisc_allow_listed_router))
network->ndisc_deny_listed_router = set_free(network->ndisc_deny_listed_router); network->ndisc_deny_listed_router = set_free_free(network->ndisc_deny_listed_router);
if (!set_isempty(network->ndisc_allow_listed_prefix)) if (!set_isempty(network->ndisc_allow_listed_prefix))
network->ndisc_deny_listed_prefix = set_free(network->ndisc_deny_listed_prefix); network->ndisc_deny_listed_prefix = set_free_free(network->ndisc_deny_listed_prefix);
if (!set_isempty(network->ndisc_allow_listed_route_prefix)) if (!set_isempty(network->ndisc_allow_listed_route_prefix))
network->ndisc_deny_listed_route_prefix = set_free(network->ndisc_deny_listed_route_prefix); network->ndisc_deny_listed_route_prefix = set_free_free(network->ndisc_deny_listed_route_prefix);
} }
static int ndisc_check_ready(Link *link); static int ndisc_check_ready(Link *link);

View File

@ -44,16 +44,6 @@
#include "strv.h" #include "strv.h"
#include "tclass.h" #include "tclass.h"
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
network_hash_ops,
char, string_hash_func, string_compare_func,
Network, network_unref);
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
stacked_netdevs_hash_ops,
char, string_hash_func, string_compare_func,
NetDev, netdev_unref);
static int network_resolve_netdev_one(Network *network, const char *name, NetDevKind kind, NetDev **ret) { static int network_resolve_netdev_one(Network *network, const char *name, NetDevKind kind, NetDev **ret) {
const char *kind_string; const char *kind_string;
NetDev *netdev; NetDev *netdev;
@ -115,14 +105,14 @@ static int network_resolve_stacked_netdevs(Network *network) {
if (network_resolve_netdev_one(network, name, PTR_TO_INT(kind), &netdev) <= 0) if (network_resolve_netdev_one(network, name, PTR_TO_INT(kind), &netdev) <= 0)
continue; continue;
r = hashmap_ensure_put(&network->stacked_netdevs, &stacked_netdevs_hash_ops, netdev->ifname, netdev); r = hashmap_ensure_put(&network->stacked_netdevs, &string_hash_ops, netdev->ifname, netdev);
if (r == -ENOMEM) if (r == -ENOMEM)
return log_oom(); return log_oom();
if (r < 0) if (r < 0)
log_warning_errno(r, "%s: Failed to add NetDev '%s' to network, ignoring: %m", log_warning_errno(r, "%s: Failed to add NetDev '%s' to network, ignoring: %m",
network->filename, (const char *) name); network->filename, (const char *) name);
TAKE_PTR(netdev); netdev = NULL;
} }
return 0; return 0;
@ -301,6 +291,11 @@ int network_verify(Network *network) {
if (network->keep_configuration < 0) if (network->keep_configuration < 0)
network->keep_configuration = KEEP_CONFIGURATION_NO; network->keep_configuration = KEEP_CONFIGURATION_NO;
if (network->ipv6_proxy_ndp == 0 && !set_isempty(network->ipv6_proxy_ndp_addresses)) {
log_warning("%s: IPv6ProxyNDP= is disabled. Ignoring IPv6ProxyNDPAddress=.", network->filename);
network->ipv6_proxy_ndp_addresses = set_free_free(network->ipv6_proxy_ndp_addresses);
}
r = network_drop_invalid_addresses(network); r = network_drop_invalid_addresses(network);
if (r < 0) if (r < 0)
return r; /* network_drop_invalid_addresses() logs internally. */ return r; /* network_drop_invalid_addresses() logs internally. */
@ -599,7 +594,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
if (r < 0) if (r < 0)
return r; /* network_verify() logs internally. */ return r; /* network_verify() logs internally. */
r = ordered_hashmap_ensure_put(networks, &network_hash_ops, network->name, network); r = ordered_hashmap_ensure_put(networks, &string_hash_ops, network->name, network);
if (r < 0) if (r < 0)
return log_warning_errno(r, "%s: Failed to store configuration into hashmap: %m", filename); return log_warning_errno(r, "%s: Failed to store configuration into hashmap: %m", filename);
@ -650,7 +645,7 @@ static bool network_netdev_equal(Network *a, Network *b) {
} }
int network_reload(Manager *manager) { int network_reload(Manager *manager) {
_cleanup_ordered_hashmap_free_ OrderedHashmap *new_networks = NULL; OrderedHashmap *new_networks = NULL;
Network *n, *old; Network *n, *old;
int r; int r;
@ -658,7 +653,7 @@ int network_reload(Manager *manager) {
r = network_load(manager, &new_networks); r = network_load(manager, &new_networks);
if (r < 0) if (r < 0)
return r; goto failure;
ORDERED_HASHMAP_FOREACH(n, new_networks) { ORDERED_HASHMAP_FOREACH(n, new_networks) {
r = network_get_by_name(manager, n->name, &old); r = network_get_by_name(manager, n->name, &old);
@ -680,13 +675,14 @@ int network_reload(Manager *manager) {
/* Nothing updated, use the existing Network object, and drop the new one. */ /* Nothing updated, use the existing Network object, and drop the new one. */
r = ordered_hashmap_replace(new_networks, old->name, old); r = ordered_hashmap_replace(new_networks, old->name, old);
if (r < 0) if (r < 0)
return r; goto failure;
network_ref(old); network_ref(old);
network_unref(n); network_unref(n);
} }
ordered_hashmap_free_and_replace(manager->networks, new_networks); ordered_hashmap_free_with_destructor(manager->networks, network_unref);
manager->networks = new_networks;
r = manager_build_dhcp_pd_subnet_ids(manager); r = manager_build_dhcp_pd_subnet_ids(manager);
if (r < 0) if (r < 0)
@ -697,6 +693,11 @@ int network_reload(Manager *manager) {
return r; return r;
return 0; return 0;
failure:
ordered_hashmap_free_with_destructor(new_networks, network_unref);
return r;
} }
int manager_build_dhcp_pd_subnet_ids(Manager *manager) { int manager_build_dhcp_pd_subnet_ids(Manager *manager) {
@ -751,7 +752,7 @@ static Network *network_free(Network *network) {
free(network->dns); free(network->dns);
ordered_set_free(network->search_domains); ordered_set_free(network->search_domains);
ordered_set_free(network->route_domains); ordered_set_free(network->route_domains);
set_free(network->dnssec_negative_trust_anchors); set_free_free(network->dnssec_negative_trust_anchors);
/* DHCP server */ /* DHCP server */
free(network->dhcp_server_relay_agent_circuit_id); free(network->dhcp_server_relay_agent_circuit_id);
@ -824,23 +825,23 @@ static Network *network_free(Network *network) {
netdev_unref(network->bridge); netdev_unref(network->bridge);
netdev_unref(network->bond); netdev_unref(network->bond);
netdev_unref(network->vrf); netdev_unref(network->vrf);
hashmap_free(network->stacked_netdevs); hashmap_free_with_destructor(network->stacked_netdevs, netdev_unref);
/* static configs */ /* static configs */
set_free(network->ipv6_proxy_ndp_addresses); set_free_free(network->ipv6_proxy_ndp_addresses);
ordered_hashmap_free(network->addresses_by_section); ordered_hashmap_free(network->addresses_by_section);
hashmap_free(network->routes_by_section); hashmap_free(network->routes_by_section);
ordered_hashmap_free(network->nexthops_by_section); ordered_hashmap_free(network->nexthops_by_section);
hashmap_free(network->bridge_fdb_entries_by_section); hashmap_free_with_destructor(network->bridge_fdb_entries_by_section, bridge_fdb_free);
hashmap_free(network->bridge_mdb_entries_by_section); hashmap_free_with_destructor(network->bridge_mdb_entries_by_section, bridge_mdb_free);
ordered_hashmap_free(network->neighbors_by_section); ordered_hashmap_free(network->neighbors_by_section);
hashmap_free(network->address_labels_by_section); hashmap_free(network->address_labels_by_section);
hashmap_free(network->prefixes_by_section); hashmap_free_with_destructor(network->prefixes_by_section, prefix_free);
hashmap_free(network->route_prefixes_by_section); hashmap_free_with_destructor(network->route_prefixes_by_section, route_prefix_free);
hashmap_free(network->pref64_prefixes_by_section); hashmap_free_with_destructor(network->pref64_prefixes_by_section, prefix64_free);
hashmap_free(network->rules_by_section); hashmap_free(network->rules_by_section);
hashmap_free(network->dhcp_static_leases_by_section); hashmap_free_with_destructor(network->dhcp_static_leases_by_section, dhcp_static_lease_free);
ordered_hashmap_free(network->sr_iov_by_section); ordered_hashmap_free_with_destructor(network->sr_iov_by_section, sr_iov_free);
hashmap_free(network->qdiscs_by_section); hashmap_free(network->qdiscs_by_section);
hashmap_free(network->tclasses_by_section); hashmap_free(network->tclasses_by_section);

View File

@ -35,7 +35,7 @@ bool link_radv_enabled(Link *link) {
return link->network->router_prefix_delegation; return link->network->router_prefix_delegation;
} }
static Prefix* prefix_free(Prefix *prefix) { Prefix* prefix_free(Prefix *prefix) {
if (!prefix) if (!prefix)
return NULL; return NULL;
@ -52,11 +52,6 @@ static Prefix* prefix_free(Prefix *prefix) {
DEFINE_SECTION_CLEANUP_FUNCTIONS(Prefix, prefix_free); DEFINE_SECTION_CLEANUP_FUNCTIONS(Prefix, prefix_free);
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
prefix_hash_ops_by_section,
ConfigSection, config_section_hash_func, config_section_compare_func,
Prefix, prefix_free);
static int prefix_new_static(Network *network, const char *filename, unsigned section_line, Prefix **ret) { static int prefix_new_static(Network *network, const char *filename, unsigned section_line, Prefix **ret) {
_cleanup_(config_section_freep) ConfigSection *n = NULL; _cleanup_(config_section_freep) ConfigSection *n = NULL;
_cleanup_(prefix_freep) Prefix *prefix = NULL; _cleanup_(prefix_freep) Prefix *prefix = NULL;
@ -92,7 +87,7 @@ static int prefix_new_static(Network *network, const char *filename, unsigned se
.prefix.preferred_until = USEC_INFINITY, .prefix.preferred_until = USEC_INFINITY,
}; };
r = hashmap_ensure_put(&network->prefixes_by_section, &prefix_hash_ops_by_section, prefix->section, prefix); r = hashmap_ensure_put(&network->prefixes_by_section, &config_section_hash_ops, prefix->section, prefix);
if (r < 0) if (r < 0)
return r; return r;
@ -100,7 +95,7 @@ static int prefix_new_static(Network *network, const char *filename, unsigned se
return 0; return 0;
} }
static RoutePrefix* route_prefix_free(RoutePrefix *prefix) { RoutePrefix* route_prefix_free(RoutePrefix *prefix) {
if (!prefix) if (!prefix)
return NULL; return NULL;
@ -116,11 +111,6 @@ static RoutePrefix* route_prefix_free(RoutePrefix *prefix) {
DEFINE_SECTION_CLEANUP_FUNCTIONS(RoutePrefix, route_prefix_free); DEFINE_SECTION_CLEANUP_FUNCTIONS(RoutePrefix, route_prefix_free);
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
route_prefix_hash_ops_by_section,
ConfigSection, config_section_hash_func, config_section_compare_func,
RoutePrefix, route_prefix_free);
static int route_prefix_new_static(Network *network, const char *filename, unsigned section_line, RoutePrefix **ret) { static int route_prefix_new_static(Network *network, const char *filename, unsigned section_line, RoutePrefix **ret) {
_cleanup_(config_section_freep) ConfigSection *n = NULL; _cleanup_(config_section_freep) ConfigSection *n = NULL;
_cleanup_(route_prefix_freep) RoutePrefix *prefix = NULL; _cleanup_(route_prefix_freep) RoutePrefix *prefix = NULL;
@ -153,7 +143,7 @@ static int route_prefix_new_static(Network *network, const char *filename, unsig
.route.valid_until = USEC_INFINITY, .route.valid_until = USEC_INFINITY,
}; };
r = hashmap_ensure_put(&network->route_prefixes_by_section, &route_prefix_hash_ops_by_section, prefix->section, prefix); r = hashmap_ensure_put(&network->route_prefixes_by_section, &config_section_hash_ops, prefix->section, prefix);
if (r < 0) if (r < 0)
return r; return r;
@ -161,7 +151,7 @@ static int route_prefix_new_static(Network *network, const char *filename, unsig
return 0; return 0;
} }
static Prefix64* prefix64_free(Prefix64 *prefix) { Prefix64* prefix64_free(Prefix64 *prefix) {
if (!prefix) if (!prefix)
return NULL; return NULL;
@ -177,11 +167,6 @@ static Prefix64* prefix64_free(Prefix64 *prefix) {
DEFINE_SECTION_CLEANUP_FUNCTIONS(Prefix64, prefix64_free); DEFINE_SECTION_CLEANUP_FUNCTIONS(Prefix64, prefix64_free);
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
prefix64_hash_ops_by_section,
ConfigSection, config_section_hash_func, config_section_compare_func,
Prefix64, prefix64_free);
static int prefix64_new_static(Network *network, const char *filename, unsigned section_line, Prefix64 **ret) { static int prefix64_new_static(Network *network, const char *filename, unsigned section_line, Prefix64 **ret) {
_cleanup_(config_section_freep) ConfigSection *n = NULL; _cleanup_(config_section_freep) ConfigSection *n = NULL;
_cleanup_(prefix64_freep) Prefix64 *prefix = NULL; _cleanup_(prefix64_freep) Prefix64 *prefix = NULL;
@ -214,7 +199,7 @@ static int prefix64_new_static(Network *network, const char *filename, unsigned
.prefix64.valid_until = USEC_INFINITY, .prefix64.valid_until = USEC_INFINITY,
}; };
r = hashmap_ensure_put(&network->pref64_prefixes_by_section, &prefix64_hash_ops_by_section, prefix->section, prefix); r = hashmap_ensure_put(&network->pref64_prefixes_by_section, &config_section_hash_ops, prefix->section, prefix);
if (r < 0) if (r < 0)
return r; return r;
@ -824,9 +809,9 @@ void network_adjust_radv(Network *network) {
} }
if (!FLAGS_SET(network->router_prefix_delegation, RADV_PREFIX_DELEGATION_STATIC)) { if (!FLAGS_SET(network->router_prefix_delegation, RADV_PREFIX_DELEGATION_STATIC)) {
network->prefixes_by_section = hashmap_free(network->prefixes_by_section); network->prefixes_by_section = hashmap_free_with_destructor(network->prefixes_by_section, prefix_free);
network->route_prefixes_by_section = hashmap_free(network->route_prefixes_by_section); network->route_prefixes_by_section = hashmap_free_with_destructor(network->route_prefixes_by_section, route_prefix_free);
network->pref64_prefixes_by_section = hashmap_free(network->pref64_prefixes_by_section); network->pref64_prefixes_by_section = hashmap_free_with_destructor(network->pref64_prefixes_by_section, prefix64_free);
} }
if (!network->router_prefix_delegation) if (!network->router_prefix_delegation)

View File

@ -52,6 +52,10 @@ typedef struct Prefix64 {
sd_ndisc_prefix64 prefix64; sd_ndisc_prefix64 prefix64;
} Prefix64; } Prefix64;
Prefix* prefix_free(Prefix *prefix);
RoutePrefix* route_prefix_free(RoutePrefix *prefix);
Prefix64* prefix64_free(Prefix64 *prefix);
void network_adjust_radv(Network *network); void network_adjust_radv(Network *network);
int link_request_radv_addresses(Link *link); int link_request_radv_addresses(Link *link);

View File

@ -947,6 +947,8 @@ static int link_save(Link *link) {
} }
void link_dirty(Link *link) { void link_dirty(Link *link) {
int r;
assert(link); assert(link);
assert(link->manager); assert(link->manager);
@ -960,9 +962,10 @@ void link_dirty(Link *link) {
/* Also mark manager dirty as link is dirty */ /* Also mark manager dirty as link is dirty */
link->manager->dirty = true; link->manager->dirty = true;
if (set_ensure_put(&link->manager->dirty_links, &link_hash_ops, link) <= 0) r = set_ensure_put(&link->manager->dirty_links, NULL, link);
return; /* Ignore allocation errors and don't take another ref if the link was already dirty */ if (r <= 0)
/* Ignore allocation errors and don't take another ref if the link was already dirty */
return;
link_ref(link); link_ref(link);
} }

View File

@ -12,7 +12,7 @@
#include "udev-util.h" #include "udev-util.h"
#include "wifi-util.h" #include "wifi-util.h"
static Wiphy* wiphy_free(Wiphy *w) { Wiphy *wiphy_free(Wiphy *w) {
if (!w) if (!w)
return NULL; return NULL;
@ -29,13 +29,6 @@ static Wiphy* wiphy_free(Wiphy *w) {
return mfree(w); return mfree(w);
} }
DEFINE_TRIVIAL_CLEANUP_FUNC(Wiphy*, wiphy_free);
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
wiphy_hash_ops,
void, trivial_hash_func, trivial_compare_func,
Wiphy, wiphy_free);
static int wiphy_new(Manager *manager, sd_netlink_message *message, Wiphy **ret) { static int wiphy_new(Manager *manager, sd_netlink_message *message, Wiphy **ret) {
_cleanup_(wiphy_freep) Wiphy *w = NULL; _cleanup_(wiphy_freep) Wiphy *w = NULL;
_cleanup_free_ char *name = NULL; _cleanup_free_ char *name = NULL;
@ -63,7 +56,7 @@ static int wiphy_new(Manager *manager, sd_netlink_message *message, Wiphy **ret)
.name = TAKE_PTR(name), .name = TAKE_PTR(name),
}; };
r = hashmap_ensure_put(&manager->wiphy_by_index, &wiphy_hash_ops, UINT32_TO_PTR(w->index), w); r = hashmap_ensure_put(&manager->wiphy_by_index, NULL, UINT32_TO_PTR(w->index), w);
if (r < 0) if (r < 0)
return r; return r;

View File

@ -31,6 +31,9 @@ typedef struct Wiphy {
RFKillState rfkill_state; RFKillState rfkill_state;
} Wiphy; } Wiphy;
Wiphy *wiphy_free(Wiphy *w);
DEFINE_TRIVIAL_CLEANUP_FUNC(Wiphy*, wiphy_free);
int wiphy_get_by_index(Manager *manager, uint32_t index, Wiphy **ret); int wiphy_get_by_index(Manager *manager, uint32_t index, Wiphy **ret);
int wiphy_get_by_name(Manager *manager, const char *name, Wiphy **ret); int wiphy_get_by_name(Manager *manager, const char *name, Wiphy **ret);

View File

@ -146,13 +146,13 @@ int memfd_clone_fd(int fd, const char *name, int mode) {
assert(fd >= 0); assert(fd >= 0);
assert(name); assert(name);
assert(IN_SET(mode & O_ACCMODE_STRICT, O_RDONLY, O_RDWR)); assert(IN_SET(mode & O_ACCMODE, O_RDONLY, O_RDWR));
assert((mode & ~(O_RDONLY|O_RDWR|O_CLOEXEC)) == 0); assert((mode & ~(O_RDONLY|O_RDWR|O_CLOEXEC)) == 0);
if (fstat(fd, &st) < 0) if (fstat(fd, &st) < 0)
return -errno; return -errno;
ro = (mode & O_ACCMODE_STRICT) == O_RDONLY; ro = (mode & O_ACCMODE) == O_RDONLY;
exec = st.st_mode & 0111; exec = st.st_mode & 0111;
mfd = memfd_create_wrapper(name, mfd = memfd_create_wrapper(name,

View File

@ -504,7 +504,7 @@ int journal_file_open_reliably(
-EIDRM)) /* File has been deleted */ -EIDRM)) /* File has been deleted */
return r; return r;
if ((open_flags & O_ACCMODE_STRICT) == O_RDONLY) if ((open_flags & O_ACCMODE) == O_RDONLY)
return r; return r;
if (!(open_flags & O_CREAT)) if (!(open_flags & O_CREAT))
@ -519,7 +519,7 @@ int journal_file_open_reliably(
/* The file is corrupted. Try opening it read-only as the template before rotating to inherit its /* The file is corrupted. Try opening it read-only as the template before rotating to inherit its
* sequence number and ID. */ * sequence number and ID. */
r = journal_file_open(-EBADF, fname, r = journal_file_open(-EBADF, fname,
(open_flags & ~(O_ACCMODE_STRICT|O_CREAT|O_EXCL)) | O_RDONLY, (open_flags & ~(O_ACCMODE|O_CREAT|O_EXCL)) | O_RDONLY,
file_flags, 0, compress_threshold_bytes, NULL, file_flags, 0, compress_threshold_bytes, NULL,
mmap_cache, /* template = */ NULL, &old_file); mmap_cache, /* template = */ NULL, &old_file);
if (r < 0) if (r < 0)

View File

@ -500,7 +500,7 @@ static int loop_device_make_internal(
.block_size = sector_size, .block_size = sector_size,
.info = { .info = {
/* Use the specified flags, but configure the read-only flag from the open flags, and force autoclear */ /* Use the specified flags, but configure the read-only flag from the open flags, and force autoclear */
.lo_flags = (loop_flags & ~LO_FLAGS_READ_ONLY) | ((open_flags & O_ACCMODE_STRICT) == O_RDONLY ? LO_FLAGS_READ_ONLY : 0) | LO_FLAGS_AUTOCLEAR, .lo_flags = (loop_flags & ~LO_FLAGS_READ_ONLY) | ((open_flags & O_ACCMODE) == O_RDONLY ? LO_FLAGS_READ_ONLY : 0) | LO_FLAGS_AUTOCLEAR,
.lo_offset = offset, .lo_offset = offset,
.lo_sizelimit = size == UINT64_MAX ? 0 : size, .lo_sizelimit = size == UINT64_MAX ? 0 : size,
}, },

View File

@ -9,25 +9,6 @@
#include "stdio-util.h" #include "stdio-util.h"
#include "string-util.h" #include "string-util.h"
static SRIOV* sr_iov_free(SRIOV *sr_iov) {
if (!sr_iov)
return NULL;
if (sr_iov->sr_iov_by_section && sr_iov->section)
ordered_hashmap_remove(sr_iov->sr_iov_by_section, sr_iov->section);
config_section_free(sr_iov->section);
return mfree(sr_iov);
}
DEFINE_SECTION_CLEANUP_FUNCTIONS(SRIOV, sr_iov_free);
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
sr_iov_hash_ops_by_section,
ConfigSection, config_section_hash_func, config_section_compare_func,
SRIOV, sr_iov_free);
static int sr_iov_new(SRIOV **ret) { static int sr_iov_new(SRIOV **ret) {
SRIOV *sr_iov; SRIOV *sr_iov;
@ -76,7 +57,7 @@ static int sr_iov_new_static(OrderedHashmap **sr_iov_by_section, const char *fil
if (r < 0) if (r < 0)
return r; return r;
r = ordered_hashmap_ensure_put(sr_iov_by_section, &sr_iov_hash_ops_by_section, n, sr_iov); r = ordered_hashmap_ensure_put(sr_iov_by_section, &config_section_hash_ops, n, sr_iov);
if (r < 0) if (r < 0)
return r; return r;
@ -87,6 +68,18 @@ static int sr_iov_new_static(OrderedHashmap **sr_iov_by_section, const char *fil
return 0; return 0;
} }
SRIOV *sr_iov_free(SRIOV *sr_iov) {
if (!sr_iov)
return NULL;
if (sr_iov->sr_iov_by_section && sr_iov->section)
ordered_hashmap_remove(sr_iov->sr_iov_by_section, sr_iov->section);
config_section_free(sr_iov->section);
return mfree(sr_iov);
}
void sr_iov_hash_func(const SRIOV *sr_iov, struct siphash *state) { void sr_iov_hash_func(const SRIOV *sr_iov, struct siphash *state) {
assert(sr_iov); assert(sr_iov);
assert(state); assert(state);

View File

@ -32,6 +32,7 @@ typedef struct SRIOV {
struct ether_addr mac; struct ether_addr mac;
} SRIOV; } SRIOV;
SRIOV *sr_iov_free(SRIOV *sr_iov);
void sr_iov_hash_func(const SRIOV *sr_iov, struct siphash *state); void sr_iov_hash_func(const SRIOV *sr_iov, struct siphash *state);
int sr_iov_compare_func(const SRIOV *s1, const SRIOV *s2); int sr_iov_compare_func(const SRIOV *s1, const SRIOV *s2);
int sr_iov_set_netlink_message(SRIOV *sr_iov, sd_netlink_message *req); int sr_iov_set_netlink_message(SRIOV *sr_iov, sd_netlink_message *req);
@ -39,6 +40,8 @@ int sr_iov_get_num_vfs(sd_device *device, uint32_t *ret);
int sr_iov_set_num_vfs(sd_device *device, uint32_t num_vfs, OrderedHashmap *sr_iov_by_section); int sr_iov_set_num_vfs(sd_device *device, uint32_t num_vfs, OrderedHashmap *sr_iov_by_section);
int sr_iov_drop_invalid_sections(uint32_t num_vfs, OrderedHashmap *sr_iov_by_section); int sr_iov_drop_invalid_sections(uint32_t num_vfs, OrderedHashmap *sr_iov_by_section);
DEFINE_SECTION_CLEANUP_FUNCTIONS(SRIOV, sr_iov_free);
CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_uint32); CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_uint32);
CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_boolean); CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_boolean);
CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_link_state); CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_link_state);

View File

@ -17,7 +17,6 @@
#include "blockdev-util.h" #include "blockdev-util.h"
#include "detach-loopback.h" #include "detach-loopback.h"
#include "device-util.h" #include "device-util.h"
#include "errno-util.h"
#include "fd-util.h" #include "fd-util.h"
#include "shutdown.h" #include "shutdown.h"
@ -107,12 +106,8 @@ static int delete_loopback(const char *device) {
fd = open(device, O_RDONLY|O_CLOEXEC); fd = open(device, O_RDONLY|O_CLOEXEC);
if (fd < 0) { if (fd < 0) {
if (ERRNO_IS_DEVICE_ABSENT(errno)) { log_debug_errno(errno, "Failed to open loopback device %s: %m", device);
log_debug_errno(errno, "Tried to open loopback device '%s', but device disappeared by now, ignoring: %m", device); return errno == ENOENT ? 0 : -errno;
return 0;
}
return log_debug_errno(errno, "Failed to open loopback device '%s': %m", device);
} }
/* Loopback block devices don't sync in-flight blocks when we clear the fd, hence sync explicitly /* Loopback block devices don't sync in-flight blocks when we clear the fd, hence sync explicitly

View File

@ -131,21 +131,12 @@ static int delete_md(RaidDevice *m) {
assert(m->path); assert(m->path);
fd = open(m->path, O_RDONLY|O_CLOEXEC|O_EXCL); fd = open(m->path, O_RDONLY|O_CLOEXEC|O_EXCL);
if (fd < 0) { if (fd < 0)
if (ERRNO_IS_DEVICE_ABSENT(errno)) { return -errno;
log_debug_errno(errno, "Tried to open MD device '%s', but device disappeared by now, ignoring: %m", m->path);
return 0;
}
return log_debug_errno(errno, "Failed to open MD device '%s': %m", m->path);
}
(void) sync_with_progress(fd); (void) sync_with_progress(fd);
if (ioctl(fd, STOP_ARRAY, NULL) < 0) return RET_NERRNO(ioctl(fd, STOP_ARRAY, NULL));
return log_debug_errno(errno, "Failed to issue STOP_ARRAY on MD device '%s': %m", m->path);
return 1;
} }
static int md_points_list_detach(RaidDevice **head, bool *changed, bool last_try) { static int md_points_list_detach(RaidDevice **head, bool *changed, bool last_try) {
@ -173,9 +164,8 @@ static int md_points_list_detach(RaidDevice **head, bool *changed, bool last_try
n_failed++; n_failed++;
continue; continue;
} }
if (r > 0)
*changed = true;
*changed = true;
raid_device_free(head, m); raid_device_free(head, m);
} }

View File

@ -7,7 +7,6 @@
#include "alloc-util.h" #include "alloc-util.h"
#include "detach-swap.h" #include "detach-swap.h"
#include "errno-util.h"
#include "libmount-util.h" #include "libmount-util.h"
static void swap_device_free(SwapDevice **head, SwapDevice *m) { static void swap_device_free(SwapDevice **head, SwapDevice *m) {
@ -75,23 +74,20 @@ int swap_list_get(const char *swaps, SwapDevice **head) {
} }
static int swap_points_list_off(SwapDevice **head, bool *changed) { static int swap_points_list_off(SwapDevice **head, bool *changed) {
int n_failed = 0, r; int n_failed = 0;
assert(head); assert(head);
assert(changed); assert(changed);
LIST_FOREACH(swap_device, m, *head) { LIST_FOREACH(swap_device, m, *head) {
log_info("Deactivating swap %s.", m->path); log_info("Deactivating swap %s.", m->path);
r = RET_NERRNO(swapoff(m->path)); if (swapoff(m->path) < 0) {
if (ERRNO_IS_NEG_DEVICE_ABSENT(r)) log_warning_errno(errno, "Could not deactivate swap %s: %m", m->path);
log_debug_errno(r, "Tried to deactivate swap '%s', but swap disappeared by now, ignoring: %m", m->path);
else if (r < 0) {
log_warning_errno(r, "Could not deactivate swap %s: %m", m->path);
n_failed++; n_failed++;
continue; continue;
} else }
*changed = true;
*changed = true;
swap_device_free(head, m); swap_device_free(head, m);
} }

View File

@ -143,7 +143,7 @@ static void context_done(Context *c) {
hashmap_free(c->database_by_gid); hashmap_free(c->database_by_gid);
hashmap_free(c->database_by_groupname); hashmap_free(c->database_by_groupname);
set_free(c->names); set_free_free(c->names);
uid_range_free(c->uid_range); uid_range_free(c->uid_range);
} }
@ -231,8 +231,9 @@ static int load_user_database(Context *c) {
if (!n) if (!n)
return -ENOMEM; return -ENOMEM;
/* Note that we use trivial_hash_ops_free here, so identical strings can exist in the set. */ /* Note that we use NULL hash_ops (i.e. trivial_hash_ops) here, so identical strings can
r = set_ensure_consume(&c->names, &trivial_hash_ops_free, n); * exist in the set. */
r = set_ensure_consume(&c->names, /* hash_ops= */ NULL, n);
if (r < 0) if (r < 0)
return r; return r;
assert(r > 0); /* The set uses pointer comparisons, so n must not be in the set. */ assert(r > 0); /* The set uses pointer comparisons, so n must not be in the set. */
@ -273,8 +274,9 @@ static int load_group_database(Context *c) {
if (!n) if (!n)
return -ENOMEM; return -ENOMEM;
/* Note that we use trivial_hash_ops_free here, so identical strings can exist in the set. */ /* Note that we use NULL hash_ops (i.e. trivial_hash_ops) here, so identical strings can
r = set_ensure_consume(&c->names, &trivial_hash_ops_free, n); * exist in the set. */
r = set_ensure_consume(&c->names, /* hash_ops= */ NULL, n);
if (r < 0) if (r < 0)
return r; return r;
assert(r > 0); /* The set uses pointer comparisons, so n must not be in the set. */ assert(r > 0); /* The set uses pointer comparisons, so n must not be in the set. */

View File

@ -64,7 +64,7 @@ typedef struct SysvStub {
bool loaded; bool loaded;
} SysvStub; } SysvStub;
static SysvStub* sysvstub_free(SysvStub *s) { static SysvStub* free_sysvstub(SysvStub *s) {
if (!s) if (!s)
return NULL; return NULL;
@ -78,12 +78,11 @@ static SysvStub* sysvstub_free(SysvStub *s) {
strv_free(s->wanted_by); strv_free(s->wanted_by);
return mfree(s); return mfree(s);
} }
DEFINE_TRIVIAL_CLEANUP_FUNC(SysvStub*, sysvstub_free); DEFINE_TRIVIAL_CLEANUP_FUNC(SysvStub*, free_sysvstub);
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR( static void free_sysvstub_hashmapp(Hashmap **h) {
sysvstub_hash_ops, hashmap_free_with_destructor(*h, free_sysvstub);
char, string_hash_func, string_compare_func, }
SysvStub, sysvstub_free);
static int add_alias(const char *service, const char *alias) { static int add_alias(const char *service, const char *alias) {
_cleanup_free_ char *link = NULL; _cleanup_free_ char *link = NULL;
@ -729,7 +728,7 @@ static int enumerate_sysv(const LookupPaths *lp, Hashmap *all_services) {
FOREACH_DIRENT(de, d, log_error_errno(errno, "Failed to enumerate directory %s, ignoring: %m", *path)) { FOREACH_DIRENT(de, d, log_error_errno(errno, "Failed to enumerate directory %s, ignoring: %m", *path)) {
_cleanup_free_ char *fpath = NULL, *name = NULL; _cleanup_free_ char *fpath = NULL, *name = NULL;
_cleanup_(sysvstub_freep) SysvStub *service = NULL; _cleanup_(free_sysvstubp) SysvStub *service = NULL;
struct stat st; struct stat st;
if (fstatat(dirfd(d), de->d_name, &st, 0) < 0) { if (fstatat(dirfd(d), de->d_name, &st, 0) < 0) {
@ -895,7 +894,7 @@ finish:
} }
static int run(const char *dest, const char *dest_early, const char *dest_late) { static int run(const char *dest, const char *dest_early, const char *dest_late) {
_cleanup_hashmap_free_ Hashmap *all_services = NULL; _cleanup_(free_sysvstub_hashmapp) Hashmap *all_services = NULL;
_cleanup_(lookup_paths_done) LookupPaths lp = {}; _cleanup_(lookup_paths_done) LookupPaths lp = {};
SysvStub *service; SysvStub *service;
int r; int r;
@ -911,7 +910,7 @@ static int run(const char *dest, const char *dest_early, const char *dest_late)
if (r < 0) if (r < 0)
return r; return r;
all_services = hashmap_new(&sysvstub_hash_ops); all_services = hashmap_new(&string_hash_ops);
if (!all_services) if (!all_services)
return log_oom(); return log_oom();

View File

@ -1104,7 +1104,7 @@ TEST(fdopen_independent) {
zero(buf); zero(buf);
assert_se(fread(buf, 1, sizeof(buf), f) == strlen(TEST_TEXT)); assert_se(fread(buf, 1, sizeof(buf), f) == strlen(TEST_TEXT));
ASSERT_STREQ(buf, TEST_TEXT); ASSERT_STREQ(buf, TEST_TEXT);
assert_se((fcntl(fileno(f), F_GETFL) & O_ACCMODE_STRICT) == O_RDONLY); assert_se((fcntl(fileno(f), F_GETFL) & O_ACCMODE) == O_RDONLY);
assert_se(FLAGS_SET(fcntl(fileno(f), F_GETFD), FD_CLOEXEC)); assert_se(FLAGS_SET(fcntl(fileno(f), F_GETFD), FD_CLOEXEC));
f = safe_fclose(f); f = safe_fclose(f);
@ -1112,7 +1112,7 @@ TEST(fdopen_independent) {
zero(buf); zero(buf);
assert_se(fread(buf, 1, sizeof(buf), f) == strlen(TEST_TEXT)); assert_se(fread(buf, 1, sizeof(buf), f) == strlen(TEST_TEXT));
ASSERT_STREQ(buf, TEST_TEXT); ASSERT_STREQ(buf, TEST_TEXT);
assert_se((fcntl(fileno(f), F_GETFL) & O_ACCMODE_STRICT) == O_RDONLY); assert_se((fcntl(fileno(f), F_GETFL) & O_ACCMODE) == O_RDONLY);
assert_se(!FLAGS_SET(fcntl(fileno(f), F_GETFD), FD_CLOEXEC)); assert_se(!FLAGS_SET(fcntl(fileno(f), F_GETFD), FD_CLOEXEC));
f = safe_fclose(f); f = safe_fclose(f);
@ -1120,7 +1120,7 @@ TEST(fdopen_independent) {
zero(buf); zero(buf);
assert_se(fread(buf, 1, sizeof(buf), f) == strlen(TEST_TEXT)); assert_se(fread(buf, 1, sizeof(buf), f) == strlen(TEST_TEXT));
ASSERT_STREQ(buf, TEST_TEXT); ASSERT_STREQ(buf, TEST_TEXT);
assert_se((fcntl(fileno(f), F_GETFL) & O_ACCMODE_STRICT) == O_RDWR); assert_se((fcntl(fileno(f), F_GETFL) & O_ACCMODE) == O_RDWR);
assert_se(FLAGS_SET(fcntl(fileno(f), F_GETFD), FD_CLOEXEC)); assert_se(FLAGS_SET(fcntl(fileno(f), F_GETFD), FD_CLOEXEC));
f = safe_fclose(f); f = safe_fclose(f);
} }

View File

@ -75,7 +75,7 @@ static LinkConfig* link_config_free(LinkConfig *config) {
erase_and_free(config->wol_password); erase_and_free(config->wol_password);
cpu_set_free(config->rps_cpu_mask); cpu_set_free(config->rps_cpu_mask);
ordered_hashmap_free(config->sr_iov_by_section); ordered_hashmap_free_with_destructor(config->sr_iov_by_section, sr_iov_free);
return mfree(config); return mfree(config);
} }