summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-10-11 19:33:30 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-10-13 17:56:54 -0400
commit7ca9dffae1988a885e2e79c4bdca68169f4ca5ff (patch)
treed7836418f5ca5481157e5f155ea3f92823e05dda
parent74dcc2df7b2a340c3e1fe9e61e5c8deb324c83d7 (diff)
journald: use greedy_realloc in one place
-rw-r--r--src/journal/journald-server.c39
1 files changed, 12 insertions, 27 deletions
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 29429f6ead..518e9ecc4e 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -1145,13 +1145,13 @@ int process_event(Server *s, struct epoll_event *ev) {
}
for (;;) {
- struct msghdr msghdr;
- struct iovec iovec;
struct ucred *ucred = NULL;
struct timeval *tv = NULL;
struct cmsghdr *cmsg;
char *label = NULL;
size_t label_len = 0;
+
+ struct iovec iovec;
union {
struct cmsghdr cmsghdr;
@@ -1168,7 +1168,14 @@ int process_event(Server *s, struct epoll_event *ev) {
CMSG_SPACE(sizeof(struct timeval)) +
CMSG_SPACE(sizeof(int)) + /* fd */
CMSG_SPACE(NAME_MAX)]; /* selinux label */
- } control;
+ } control = {};
+ struct msghdr msghdr = {
+ .msg_iov = &iovec,
+ .msg_iovlen = 1,
+ .msg_control = &control,
+ .msg_controllen = sizeof(control),
+ };
+
ssize_t n;
int v;
int *fds = NULL;
@@ -1179,36 +1186,14 @@ int process_event(Server *s, struct epoll_event *ev) {
return -errno;
}
- if (s->buffer_size < (size_t) v) {
- void *b;
- size_t l;
-
- l = MAX(LINE_MAX + (size_t) v, s->buffer_size * 2);
- b = realloc(s->buffer, l+1);
+ if (!GREEDY_REALLOC(s->buffer, s->buffer_size, LINE_MAX + (size_t) v))
+ return log_oom();
- if (!b) {
- log_error("Couldn't increase buffer.");
- return -ENOMEM;
- }
-
- s->buffer_size = l;
- s->buffer = b;
- }
-
- zero(iovec);
iovec.iov_base = s->buffer;
iovec.iov_len = s->buffer_size;
- zero(control);
- zero(msghdr);
- msghdr.msg_iov = &iovec;
- msghdr.msg_iovlen = 1;
- msghdr.msg_control = &control;
- msghdr.msg_controllen = sizeof(control);
-
n = recvmsg(ev->data.fd, &msghdr, MSG_DONTWAIT|MSG_CMSG_CLOEXEC);
if (n < 0) {
-
if (errno == EINTR || errno == EAGAIN)
return 1;