]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd/sd-bus/bus-kernel.c
license: LGPL-2.1+ -> LGPL-2.1-or-later
[thirdparty/systemd.git] / src / libsystemd / sd-bus / bus-kernel.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #if HAVE_VALGRIND_MEMCHECK_H
4 #include <valgrind/memcheck.h>
5 #endif
6
7 #include <fcntl.h>
8 #include <malloc.h>
9 #include <sys/mman.h>
10 #include <sys/prctl.h>
11
12 /* When we include libgen.h because we need dirname() we immediately
13 * undefine basename() since libgen.h defines it as a macro to the POSIX
14 * version which is really broken. We prefer GNU basename(). */
15 #include <libgen.h>
16 #undef basename
17
18 #include "alloc-util.h"
19 #include "bus-internal.h"
20 #include "bus-kernel.h"
21 #include "bus-label.h"
22 #include "bus-message.h"
23 #include "bus-util.h"
24 #include "capability-util.h"
25 #include "fd-util.h"
26 #include "fileio.h"
27 #include "format-util.h"
28 #include "memfd-util.h"
29 #include "parse-util.h"
30 #include "stdio-util.h"
31 #include "string-util.h"
32 #include "strv.h"
33 #include "user-util.h"
34 #include "memory-util.h"
35
36 void close_and_munmap(int fd, void *address, size_t size) {
37 if (size > 0)
38 assert_se(munmap(address, PAGE_ALIGN(size)) >= 0);
39
40 safe_close(fd);
41 }
42
43 void bus_flush_memfd(sd_bus *b) {
44 unsigned i;
45
46 assert(b);
47
48 for (i = 0; i < b->n_memfd_cache; i++)
49 close_and_munmap(b->memfd_cache[i].fd, b->memfd_cache[i].address, b->memfd_cache[i].mapped);
50 }