]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd/sd-bus/bus-kernel.c
Merge pull request #29687 from yuwata/network-state-file-sync
[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 #include "alloc-util.h"
13 #include "bus-internal.h"
14 #include "bus-kernel.h"
15 #include "bus-label.h"
16 #include "bus-message.h"
17 #include "capability-util.h"
18 #include "fd-util.h"
19 #include "fileio.h"
20 #include "format-util.h"
21 #include "memfd-util.h"
22 #include "parse-util.h"
23 #include "stdio-util.h"
24 #include "string-util.h"
25 #include "strv.h"
26 #include "user-util.h"
27 #include "memory-util.h"
28
29 void close_and_munmap(int fd, void *address, size_t size) {
30 if (size > 0) {
31 size = PAGE_ALIGN(size);
32 assert(size < SIZE_MAX);
33 assert_se(munmap(address, size) >= 0);
34 }
35
36 safe_close(fd);
37 }
38
39 void bus_flush_memfd(sd_bus *b) {
40 assert(b);
41
42 for (unsigned i = 0; i < b->n_memfd_cache; i++)
43 close_and_munmap(b->memfd_cache[i].fd, b->memfd_cache[i].address, b->memfd_cache[i].mapped);
44 }