summaryrefslogtreecommitdiff
path: root/src/libelogind/sd-bus/bus-message.c
diff options
context:
space:
mode:
authorSven Eden <yamakuzure@gmx.net>2017-08-14 07:49:46 +0200
committerSven Eden <yamakuzure@gmx.net>2017-08-14 09:20:57 +0200
commit702f867ba334c116569501d9a5c84283ad7d48aa (patch)
tree2f9a884766eb5a4b17d3c52fda052b7db4470bce /src/libelogind/sd-bus/bus-message.c
parentc9fd3731e96287a20a2a7c746a35cb9aff9f1543 (diff)
Prep v235: Apply upstream fixes (5/10) [src/libelogind]
Diffstat (limited to 'src/libelogind/sd-bus/bus-message.c')
-rw-r--r--src/libelogind/sd-bus/bus-message.c90
1 files changed, 14 insertions, 76 deletions
diff --git a/src/libelogind/sd-bus/bus-message.c b/src/libelogind/sd-bus/bus-message.c
index cbe9c6259..31711c2c8 100644
--- a/src/libelogind/sd-bus/bus-message.c
+++ b/src/libelogind/sd-bus/bus-message.c
@@ -62,22 +62,9 @@ static void message_free_part(sd_bus_message *m, struct bus_body_part *part) {
assert(m);
assert(part);
- if (part->memfd >= 0) {
- /* If we can reuse the memfd, try that. For that it
- * can't be sealed yet. */
-
- if (!part->sealed) {
- assert(part->memfd_offset == 0);
- assert(part->data == part->mmap_begin);
- bus_kernel_push_memfd(m->bus, part->memfd, part->data, part->mapped, part->allocated);
- } else {
- if (part->mapped > 0)
- assert_se(munmap(part->mmap_begin, part->mapped) == 0);
-
- safe_close(part->memfd);
- }
-
- } else if (part->munmap_this)
+ if (part->memfd >= 0)
+ close_and_munmap(part->memfd, part->mmap_begin, part->mapped);
+ else if (part->munmap_this)
munmap(part->mmap_begin, part->mapped);
else if (part->free_this)
free(part->data);
@@ -129,12 +116,6 @@ static void message_free(sd_bus_message *m) {
message_reset_parts(m);
- if (m->release_kdbus)
- bus_kernel_cmd_free(m->bus, (uint8_t *) m->kdbus - (uint8_t *) m->bus->kdbus_buffer);
-
- if (m->free_kdbus)
- free(m->kdbus);
-
sd_bus_unref(m->bus);
if (m->free_fds) {
@@ -1223,7 +1204,6 @@ static int part_make_space(
void **q) {
void *n;
- int r;
assert(m);
assert(part);
@@ -1232,61 +1212,19 @@ static int part_make_space(
if (m->poisoned)
return -ENOMEM;
- if (!part->data && part->memfd < 0) {
- part->memfd = bus_kernel_pop_memfd(m->bus, &part->data, &part->mapped, &part->allocated);
- part->mmap_begin = part->data;
- }
-
- if (part->memfd >= 0) {
+ if (part->allocated == 0 || sz > part->allocated) {
+ size_t new_allocated;
- if (part->allocated == 0 || sz > part->allocated) {
- uint64_t new_allocated;
-
- new_allocated = PAGE_ALIGN(sz > 0 ? 2 * sz : 1);
- r = memfd_set_size(part->memfd, new_allocated);
- if (r < 0) {
- m->poisoned = true;
- return r;
- }
-
- part->allocated = new_allocated;
- }
-
- if (!part->data || sz > part->mapped) {
- size_t psz;
-
- psz = PAGE_ALIGN(sz > 0 ? sz : 1);
- if (part->mapped <= 0)
- n = mmap(NULL, psz, PROT_READ|PROT_WRITE, MAP_SHARED, part->memfd, 0);
- else
- n = mremap(part->mmap_begin, part->mapped, psz, MREMAP_MAYMOVE);
-
- if (n == MAP_FAILED) {
- m->poisoned = true;
- return -errno;
- }
-
- part->mmap_begin = part->data = n;
- part->mapped = psz;
- part->memfd_offset = 0;
+ new_allocated = sz > 0 ? 2 * sz : 64;
+ n = realloc(part->data, new_allocated);
+ if (!n) {
+ m->poisoned = true;
+ return -ENOMEM;
}
- part->munmap_this = true;
- } else {
- if (part->allocated == 0 || sz > part->allocated) {
- size_t new_allocated;
-
- new_allocated = sz > 0 ? 2 * sz : 64;
- n = realloc(part->data, new_allocated);
- if (!n) {
- m->poisoned = true;
- return -ENOMEM;
- }
-
- part->data = n;
- part->allocated = new_allocated;
- part->free_this = true;
- }
+ part->data = n;
+ part->allocated = new_allocated;
+ part->free_this = true;
}
if (q)
@@ -5382,7 +5320,7 @@ int bus_message_parse_fields(sd_bus_message *m) {
r = message_peek_field_string(m, service_name_is_valid, &ri, item_size, &m->sender);
- if (r >= 0 && m->sender[0] == ':' && m->bus->bus_client && !m->bus->is_kernel) {
+ if (r >= 0 && m->sender[0] == ':' && m->bus->bus_client) {
m->creds.unique_name = (char*) m->sender;
m->creds.mask |= SD_BUS_CREDS_UNIQUE_NAME & m->bus->creds_mask;
}