chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
bus: let's use GREEDY_REALLOC() when allocating space for containers
[elogind.git]
/
src
/
libsystemd-bus
/
bus-message.c
diff --git
a/src/libsystemd-bus/bus-message.c
b/src/libsystemd-bus/bus-message.c
index 35a46786009881d336550a60e20ac766979d82c2..3f70f6f30ec448a2ec1112b2764681ee6a30b2dd 100644
(file)
--- a/
src/libsystemd-bus/bus-message.c
+++ b/
src/libsystemd-bus/bus-message.c
@@
-113,7
+113,7
@@
static void message_reset_containers(sd_bus_message *m) {
free(m->containers);
m->containers = NULL;
free(m->containers);
m->containers = NULL;
- m->n_containers = 0;
+ m->n_containers =
m->containers_allocated =
0;
m->root_container.index = 0;
}
m->root_container.index = 0;
}
@@
-791,7
+791,9
@@
_public_ sd_bus_message* sd_bus_message_ref(sd_bus_message *m) {
}
_public_ sd_bus_message* sd_bus_message_unref(sd_bus_message *m) {
}
_public_ sd_bus_message* sd_bus_message_unref(sd_bus_message *m) {
- assert_return(m, NULL);
+
+ if (!m)
+ return NULL;
assert(m->n_ref > 0);
m->n_ref--;
assert(m->n_ref > 0);
m->n_ref--;
@@
-1107,7
+1109,7
@@
static int message_add_offset(sd_bus_message *m, size_t offset) {
if (!c->need_offsets)
return 0;
if (!c->need_offsets)
return 0;
- if (!GREEDY_REALLOC(c->offsets, c->
n_
offsets_allocated, c->n_offsets + 1))
+ if (!GREEDY_REALLOC(c->offsets, c->offsets_allocated, c->n_offsets + 1))
return -ENOMEM;
c->offsets[c->n_offsets++] = offset;
return -ENOMEM;
c->offsets[c->n_offsets++] = offset;
@@
-1841,14
+1843,11
@@
_public_ int sd_bus_message_open_container(
assert_return(!m->poisoned, -ESTALE);
/* Make sure we have space for one more container */
assert_return(!m->poisoned, -ESTALE);
/* Make sure we have space for one more container */
- w = realloc(m->containers, sizeof(struct bus_container) * (m->n_containers + 1));
- if (!w) {
+ if (!GREEDY_REALLOC(m->containers, m->containers_allocated, m->n_containers + 1)) {
m->poisoned = true;
return -ENOMEM;
}
m->poisoned = true;
return -ENOMEM;
}
- m->containers = w;
-
c = message_get_container(m);
signature = strdup(contents);
c = message_get_container(m);
signature = strdup(contents);
@@
-1879,14
+1878,14
@@
_public_ int sd_bus_message_open_container(
}
/* OK, let's fill it in */
}
/* OK, let's fill it in */
- w
+=
m->n_containers++;
+ w
= m->containers +
m->n_containers++;
w->enclosing = type;
w->signature = signature;
w->index = 0;
w->array_size = array_size;
w->before = before;
w->begin = begin;
w->enclosing = type;
w->signature = signature;
w->index = 0;
w->array_size = array_size;
w->before = before;
w->begin = begin;
- w->n_offsets = w->
n_
offsets_allocated = 0;
+ w->n_offsets = w->offsets_allocated = 0;
w->offsets = NULL;
w->need_offsets = need_offsets;
w->offsets = NULL;
w->need_offsets = need_offsets;
@@
-1894,9
+1893,7
@@
_public_ int sd_bus_message_open_container(
}
static size_t determine_word_size(size_t sz, size_t extra) {
}
static size_t determine_word_size(size_t sz, size_t extra) {
- if (sz <= 0 && extra == 0)
- return 0;
- else if (sz + extra <= 0xFF)
+ if (sz + extra <= 0xFF)
return 1;
else if (sz + extra*2 <= 0xFFFF)
return 2;
return 1;
else if (sz + extra*2 <= 0xFFFF)
return 2;
@@
-2695,7
+2692,7
@@
static int bus_message_close_header(sd_bus_message *m) {
return 0;
}
return 0;
}
-int bus_message_seal(sd_bus_message *m, uint64_t serial) {
+int bus_message_seal(sd_bus_message *m, uint64_t serial
, usec_t timeout
) {
struct bus_body_part *part;
size_t l, a;
unsigned i;
struct bus_body_part *part;
size_t l, a;
unsigned i;
@@
-2742,6
+2739,7
@@
int bus_message_seal(sd_bus_message *m, uint64_t serial) {
return r;
m->header->serial = serial;
return r;
m->header->serial = serial;
+ m->timeout = m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED ? 0 : timeout;
/* Add padding at the end of the fields part, since we know
* the body needs to start at an 8 byte alignment. We made
/* Add padding at the end of the fields part, since we know
* the body needs to start at an 8 byte alignment. We made
@@
-3063,7
+3061,7
@@
static int message_peek_body(
}
part = find_part(m, start, nbytes, (void**) &q);
}
part = find_part(m, start, nbytes, (void**) &q);
- if (!part ||
!q
)
+ if (!part ||
(nbytes > 0 && !q)
)
return -EBADMSG;
*rindex = end;
return -EBADMSG;
*rindex = end;
@@
-3853,10
+3851,8
@@
_public_ int sd_bus_message_enter_container(sd_bus_message *m,
if (m->n_containers >= BUS_CONTAINER_DEPTH)
return -EBADMSG;
if (m->n_containers >= BUS_CONTAINER_DEPTH)
return -EBADMSG;
- w = realloc(m->containers, sizeof(struct bus_container) * (m->n_containers + 1));
- if (!w)
+ if (!GREEDY_REALLOC(m->containers, m->containers_allocated, m->n_containers + 1))
return -ENOMEM;
return -ENOMEM;
- m->containers = w;
if (message_end_of_signature(m))
return -ENXIO;
if (message_end_of_signature(m))
return -ENXIO;
@@
-3891,7
+3887,7
@@
_public_ int sd_bus_message_enter_container(sd_bus_message *m,
}
/* OK, let's fill it in */
}
/* OK, let's fill it in */
- w
+=
m->n_containers++;
+ w
= m->containers +
m->n_containers++;
w->enclosing = type;
w->signature = signature;
w->index = 0;
w->enclosing = type;
w->signature = signature;
w->index = 0;
@@
-4150,6
+4146,9
@@
_public_ int sd_bus_message_rewind(sd_bus_message *m, int complete) {
m->rindex = c->begin;
}
m->rindex = c->begin;
}
+ c->offset_index = 0;
+ c->item_size = (c->n_offsets > 0 ? c->offsets[0] : c->end) - c->begin;
+
return !isempty(c->signature);
}
return !isempty(c->signature);
}
@@
-4848,7
+4847,7
@@
int bus_message_parse_fields(sd_bus_message *m) {
uint32_t unix_fds = 0;
void *offsets = NULL;
unsigned n_offsets = 0;
uint32_t unix_fds = 0;
void *offsets = NULL;
unsigned n_offsets = 0;
- size_t sz;
+ size_t sz
= 0
;
unsigned i = 0;
assert(m);
unsigned i = 0;
assert(m);
@@
-5082,9
+5081,6
@@
int bus_message_parse_fields(sd_bus_message *m) {
if (m->n_fds != unix_fds)
return -EBADMSG;
if (m->n_fds != unix_fds)
return -EBADMSG;
- if (isempty(m->root_container.signature) != (BUS_MESSAGE_BODY_SIZE(m) == 0))
- return -EBADMSG;
-
switch (m->header->type) {
case SD_BUS_MESSAGE_SIGNAL:
switch (m->header->type) {
case SD_BUS_MESSAGE_SIGNAL: