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