summaryrefslogtreecommitdiff
path: root/src/journal/journald-stream.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-12-10 06:17:01 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-12-10 20:38:33 -0500
commite3bfb7be07d9b1f4ebb12eb22c4c8bcd2a988d51 (patch)
tree8aa9b6fb9388832a96ce0c37167198e88f26da4d /src/journal/journald-stream.c
parent90d14d2015dda79c7b465b74dd3aaf2dfc25d43c (diff)
journald: malloc less when streaming messages
Diffstat (limited to 'src/journal/journald-stream.c')
-rw-r--r--src/journal/journald-stream.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c
index 42a846b8ea..5c15a56bac 100644
--- a/src/journal/journald-stream.c
+++ b/src/journal/journald-stream.c
@@ -76,9 +76,11 @@ struct StdoutStream {
static int stdout_stream_log(StdoutStream *s, const char *p) {
struct iovec iovec[N_IOVEC_META_FIELDS + 5];
- _cleanup_free_ char *message = NULL, *syslog_priority = NULL, *syslog_facility = NULL, *syslog_identifier = NULL;
- unsigned n = 0;
int priority;
+ char syslog_priority[] = "PRIORITY=\0";
+ char syslog_facility[sizeof("SYSLOG_FACILITY=") + DECIMAL_STR_MAX(priority)];
+ _cleanup_free_ char *message = NULL, *syslog_identifier = NULL;
+ unsigned n = 0;
char *label = NULL;
size_t label_len = 0;
@@ -91,7 +93,7 @@ static int stdout_stream_log(StdoutStream *s, const char *p) {
priority = s->priority;
if (s->level_prefix)
- syslog_parse_priority((char**) &p, &priority, false);
+ syslog_parse_priority(&p, &priority, false);
if (s->forward_to_syslog || s->server->forward_to_syslog)
server_forward_syslog(s->server, syslog_fixup_facility(priority), s->identifier, p, &s->ucred, NULL);
@@ -104,12 +106,13 @@ static int stdout_stream_log(StdoutStream *s, const char *p) {
IOVEC_SET_STRING(iovec[n++], "_TRANSPORT=stdout");
- if (asprintf(&syslog_priority, "PRIORITY=%i", priority & LOG_PRIMASK) >= 0)
- IOVEC_SET_STRING(iovec[n++], syslog_priority);
+ syslog_priority[strlen("PRIORITY=")] = '0' + LOG_PRI(priority);
+ IOVEC_SET_STRING(iovec[n++], syslog_priority);
- if (priority & LOG_FACMASK)
- if (asprintf(&syslog_facility, "SYSLOG_FACILITY=%i", LOG_FAC(priority)) >= 0)
- IOVEC_SET_STRING(iovec[n++], syslog_facility);
+ if (priority & LOG_FACMASK) {
+ snprintf(syslog_facility, sizeof(syslog_facility), "SYSLOG_FACILITY=%i", LOG_FAC(priority));
+ IOVEC_SET_STRING(iovec[n++], syslog_facility);
+ }
if (s->identifier) {
syslog_identifier = strappend("SYSLOG_IDENTIFIER=", s->identifier);
@@ -411,7 +414,7 @@ fail:
int server_open_stdout_socket(Server *s) {
int r;
- struct epoll_event ev;
+ struct epoll_event ev = { .events = EPOLLIN };
assert(s);
@@ -444,8 +447,6 @@ int server_open_stdout_socket(Server *s) {
} else
fd_nonblock(s->stdout_fd, 1);
- zero(ev);
- ev.events = EPOLLIN;
ev.data.fd = s->stdout_fd;
if (epoll_ctl(s->epoll_fd, EPOLL_CTL_ADD, s->stdout_fd, &ev) < 0) {
log_error("Failed to add stdout server fd to epoll object: %m");