]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd/sd-bus/bus-kernel.c
Merge pull request #7855 from poettering/log-h-includes
[thirdparty/systemd.git] / src / libsystemd / sd-bus / bus-kernel.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
6629161f
LP
2/***
3 This file is part of systemd.
4
5 Copyright 2013 Lennart Poettering
6
7 systemd is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 systemd is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with systemd; If not, see <http://www.gnu.org/licenses/>.
19***/
20
349cc4a5 21#if HAVE_VALGRIND_MEMCHECK_H
7211f918
LP
22#include <valgrind/memcheck.h>
23#endif
24
6629161f 25#include <fcntl.h>
c556fe79 26#include <malloc.h>
fd8d62d9 27#include <sys/mman.h>
5972fe95 28#include <sys/prctl.h>
6629161f 29
eef46c37 30/* When we include libgen.h because we need dirname() we immediately
11c9f1e4
SM
31 * undefine basename() since libgen.h defines it as a macro to the POSIX
32 * version which is really broken. We prefer GNU basename(). */
eef46c37
LP
33#include <libgen.h>
34#undef basename
35
b5efdb8a 36#include "alloc-util.h"
07630cea 37#include "bus-internal.h"
3ffd4af2 38#include "bus-kernel.h"
07630cea
LP
39#include "bus-label.h"
40#include "bus-message.h"
41#include "bus-util.h"
430f0182 42#include "capability-util.h"
3ffd4af2 43#include "fd-util.h"
1a299299 44#include "fileio.h"
f97b34a6 45#include "format-util.h"
07630cea 46#include "memfd-util.h"
6bedfcbb 47#include "parse-util.h"
d054f0a4 48#include "stdio-util.h"
07630cea
LP
49#include "string-util.h"
50#include "strv.h"
ee104e11 51#include "user-util.h"
07630cea 52#include "util.h"
777d7a61 53
a132bef0 54void close_and_munmap(int fd, void *address, size_t size) {
45fbe937 55 if (size > 0)
76b7742c 56 assert_se(munmap(address, PAGE_ALIGN(size)) >= 0);
45fbe937 57
03e334a1 58 safe_close(fd);
bc7fd8cd
LP
59}
60
a132bef0 61void bus_flush_memfd(sd_bus *b) {
bc7fd8cd
LP
62 unsigned i;
63
64 assert(b);
65
76b7742c 66 for (i = 0; i < b->n_memfd_cache; i++)
8e959fbf 67 close_and_munmap(b->memfd_cache[i].fd, b->memfd_cache[i].address, b->memfd_cache[i].mapped);
bc7fd8cd 68}