From fb36b1339be0211d5d4cd6d035df704bdd589597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 4 Apr 2019 12:54:19 +0200 Subject: [PATCH] shared: add a single definition of libmount cleanup functions Use a trivial header file to share mnt_free_tablep and mnt_free_iterp. It would be nicer put this in mount-util.h, but libmount.h is not in the default include path, and the build system would have to be adjusted to pass pkg-config include path in various places, and it's just not worth the trouble. A separate header file works nicely. --- src/core/mount.c | 6 +----- src/shared/libmount-util.h | 10 ++++++++++ src/shared/meson.build | 1 + src/shutdown/umount.c | 7 +------ 4 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 src/shared/libmount-util.h diff --git a/src/core/mount.c b/src/core/mount.c index 965dc51db5..c1b0c29d80 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -5,8 +5,6 @@ #include #include -#include - #include "sd-messages.h" #include "alloc-util.h" @@ -17,6 +15,7 @@ #include "exit-status.h" #include "format-util.h" #include "fstab-util.h" +#include "libmount-util.h" #include "log.h" #include "manager.h" #include "mkdir.h" @@ -36,9 +35,6 @@ #define RETRY_UMOUNT_MAX 32 -DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_table*, mnt_free_table); -DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_iter*, mnt_free_iter); - static const UnitActiveState state_translation_table[_MOUNT_STATE_MAX] = { [MOUNT_DEAD] = UNIT_INACTIVE, [MOUNT_MOUNTING] = UNIT_ACTIVATING, diff --git a/src/shared/libmount-util.h b/src/shared/libmount-util.h new file mode 100644 index 0000000000..7d94468e52 --- /dev/null +++ b/src/shared/libmount-util.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: LGPL-2.1+ */ +#pragma once + +/* This needs to be after sys/mount.h */ +#include + +#include "macro.h" + +DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_table*, mnt_free_table); +DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_iter*, mnt_free_iter); diff --git a/src/shared/meson.build b/src/shared/meson.build index 47cbc9932c..bb28bcac2b 100644 --- a/src/shared/meson.build +++ b/src/shared/meson.build @@ -95,6 +95,7 @@ shared_sources = files(''' json-internal.h json.c json.h + libmount-util.h lockfile-util.c lockfile-util.h log-link.h diff --git a/src/shutdown/umount.c b/src/shutdown/umount.c index 0ed358bb32..3d6cfa08f2 100644 --- a/src/shutdown/umount.c +++ b/src/shutdown/umount.c @@ -13,9 +13,6 @@ #include #include -/* This needs to be after sys/mount.h :( */ -#include - #include "sd-device.h" #include "alloc-util.h" @@ -25,6 +22,7 @@ #include "escape.h" #include "fd-util.h" #include "fstab-util.h" +#include "libmount-util.h" #include "linux-3.13/dm-ioctl.h" #include "mount-setup.h" #include "mount-util.h" @@ -38,9 +36,6 @@ #include "util.h" #include "virt.h" -DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_table*, mnt_free_table); -DEFINE_TRIVIAL_CLEANUP_FUNC(struct libmnt_iter*, mnt_free_iter); - static void mount_point_free(MountPoint **head, MountPoint *m) { assert(head); assert(m);