chiark / gitweb /
sd-bus: get rid of kdbus flags cruft
[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   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
21 #if HAVE_VALGRIND_MEMCHECK_H
22 #include <valgrind/memcheck.h>
23 #endif
24
25 #include <fcntl.h>
26 #include <malloc.h>
27 #include <sys/mman.h>
28 #include <sys/prctl.h>
29
30 /* When we include libgen.h because we need dirname() we immediately
31  * undefine basename() since libgen.h defines it as a macro to the POSIX
32  * version which is really broken. We prefer GNU basename(). */
33 #include <libgen.h>
34 #undef basename
35
36 #include "alloc-util.h"
37 #include "bus-internal.h"
38 #include "bus-kernel.h"
39 #include "bus-label.h"
40 #include "bus-message.h"
41 #include "bus-util.h"
42 #include "capability-util.h"
43 #include "fd-util.h"
44 #include "fileio.h"
45 #include "format-util.h"
46 #include "memfd-util.h"
47 #include "parse-util.h"
48 #include "stdio-util.h"
49 #include "string-util.h"
50 #include "strv.h"
51 #include "user-util.h"
52 #include "util.h"
53
54 void close_and_munmap(int fd, void *address, size_t size) {
55         if (size > 0)
56                 assert_se(munmap(address, PAGE_ALIGN(size)) >= 0);
57
58         safe_close(fd);
59 }
60
61 void bus_flush_memfd(sd_bus *b) {
62         unsigned i;
63
64         assert(b);
65
66         for (i = 0; i < b->n_memfd_cache; i++)
67                 close_and_munmap(b->memfd_cache[i].fd, b->memfd_cache[i].address, b->memfd_cache[i].mapped);
68 }
69 #if 0 /// UNNEEDED by elogind
70 #endif // 0