static int stdout_stream_log(StdoutStream *s, const char *p) {
struct iovec iovec[N_IOVEC_META_FIELDS + 5];
- 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;
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);
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);
#endif
server_dispatch_message(s->server, iovec, n, ELEMENTSOF(iovec), &s->ucred, NULL, label, label_len, s->unit_id, priority, 0);
-
- free(message);
- free(syslog_priority);
- free(syslog_facility);
- free(syslog_identifier);
-
return 0;
}
if (s->server) {
assert(s->server->n_stdout_streams > 0);
s->server->n_stdout_streams --;
- LIST_REMOVE(StdoutStream, stdout_stream, s->server->stdout_streams, s);
+ LIST_REMOVE(stdout_stream, s->server->stdout_streams, s);
}
if (s->fd >= 0) {
#endif
free(s->identifier);
+ free(s->unit_id);
free(s);
}
}
stream->server = s;
- LIST_PREPEND(StdoutStream, stdout_stream, s->stdout_streams, stream);
+ LIST_PREPEND(stdout_stream, s->stdout_streams, stream);
s->n_stdout_streams ++;
return 0;
int server_open_stdout_socket(Server *s) {
int r;
- struct epoll_event ev;
+ struct epoll_event ev = { .events = EPOLLIN };
assert(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");