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