2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2013-04-11 23:09:29 +02:00
|
|
|
|
2017-10-03 10:41:51 +02:00
|
|
|
#if HAVE_VALGRIND_MEMCHECK_H
|
2013-04-12 02:19:26 +02:00
|
|
|
#include <valgrind/memcheck.h>
|
|
|
|
#endif
|
|
|
|
|
2013-04-11 23:09:29 +02:00
|
|
|
#include <fcntl.h>
|
2013-04-17 18:45:45 +02:00
|
|
|
#include <malloc.h>
|
2013-05-10 03:36:55 +02:00
|
|
|
#include <sys/mman.h>
|
2014-01-22 16:09:59 +01:00
|
|
|
#include <sys/prctl.h>
|
2013-04-11 23:09:29 +02:00
|
|
|
|
2015-02-11 18:50:38 +01:00
|
|
|
/* When we include libgen.h because we need dirname() we immediately
|
2015-06-17 12:23:46 +02:00
|
|
|
* undefine basename() since libgen.h defines it as a macro to the POSIX
|
|
|
|
* version which is really broken. We prefer GNU basename(). */
|
2015-02-11 18:50:38 +01:00
|
|
|
#include <libgen.h>
|
|
|
|
#undef basename
|
|
|
|
|
2015-10-27 03:01:06 +01:00
|
|
|
#include "alloc-util.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "bus-internal.h"
|
2015-10-25 13:14:12 +01:00
|
|
|
#include "bus-kernel.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "bus-label.h"
|
|
|
|
#include "bus-message.h"
|
|
|
|
#include "bus-util.h"
|
2015-10-26 23:32:16 +01:00
|
|
|
#include "capability-util.h"
|
2015-10-25 13:14:12 +01:00
|
|
|
#include "fd-util.h"
|
2014-11-27 21:28:13 +01:00
|
|
|
#include "fileio.h"
|
2016-11-07 16:14:59 +01:00
|
|
|
#include "format-util.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "memfd-util.h"
|
2015-10-26 16:18:16 +01:00
|
|
|
#include "parse-util.h"
|
2016-01-12 15:34:20 +01:00
|
|
|
#include "stdio-util.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "string-util.h"
|
|
|
|
#include "strv.h"
|
2015-10-27 00:42:07 +01:00
|
|
|
#include "user-util.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "util.h"
|
2013-11-29 20:07:56 +01:00
|
|
|
|
2017-07-23 17:45:57 +02:00
|
|
|
void close_and_munmap(int fd, void *address, size_t size) {
|
2013-05-17 03:13:58 +02:00
|
|
|
if (size > 0)
|
2013-05-29 09:58:31 +02:00
|
|
|
assert_se(munmap(address, PAGE_ALIGN(size)) >= 0);
|
2013-05-17 03:13:58 +02:00
|
|
|
|
2014-03-18 19:22:43 +01:00
|
|
|
safe_close(fd);
|
2013-05-14 22:24:26 +02:00
|
|
|
}
|
|
|
|
|
2017-07-23 17:45:57 +02:00
|
|
|
void bus_flush_memfd(sd_bus *b) {
|
2013-05-14 22:24:26 +02:00
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
assert(b);
|
|
|
|
|
2013-05-29 09:58:31 +02:00
|
|
|
for (i = 0; i < b->n_memfd_cache; i++)
|
2013-12-18 18:46:23 +01:00
|
|
|
close_and_munmap(b->memfd_cache[i].fd, b->memfd_cache[i].address, b->memfd_cache[i].mapped);
|
2013-05-14 22:24:26 +02:00
|
|
|
}
|