journal-send.c revision 1ae464e09376853c52075ec4d8a6bfc4b4036d0c
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering This file is part of systemd.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Copyright 2011 Lennart Poettering
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is free software; you can redistribute it and/or modify it
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering under the terms of the GNU Lesser General Public License as published by
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering (at your option) any later version.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering systemd is distributed in the hope that it will be useful, but
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering Lesser General Public License for more details.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering You should have received a copy of the GNU Lesser General Public License
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering char **_f = &(f); \
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering } while(false)
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering/* We open a single fd, and we'll share it with the current process,
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * all its threads, and all its subprocesses. This means we need to
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * initialize it atomically, and need to operate on it atomically
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering * never assuming we are the only user */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poetteringstatic int journal_fd(void) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering if (!__sync_bool_compare_and_swap(&fd_plus_one, 0, fd+1)) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering_public_ int sd_journal_print(int priority, const char *format, ...) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering r = sd_journal_printv(priority, format, ap);
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering_public_ int sd_journal_printv(int priority, const char *format, va_list ap) {
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering /* FIXME: Instead of limiting things to LINE_MAX we could do a
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering C99 variable-length array on the stack here in a loop. */
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering char buffer[8 + LINE_MAX], p[11]; struct iovec iov[2];
74b2466e14a1961bf3ac0e8a60cfaceec705bd59Lennart Poettering snprintf(p, sizeof(p), "PRIORITY=%i", priority & LOG_PRIMASK);
char_array_0(p);
_printf_(1, 0) static int fill_iovec_sprintf(const char *format, va_list ap, int extra, struct iovec **_iov) {
if (extra > 0) {
if (!iov) {
r = -ENOMEM;
goto fail;
i = extra;
while (format) {
struct iovec *c;
char *buffer;
r = -ENOMEM;
goto fail;
iov = c;
r = -ENOMEM;
goto fail;
fail:
if (_unlikely_(i < 0)) {
goto finish;
struct iovec *w;
uint64_t *l;
ssize_t k;
} control;
bool have_syslog_identifier = false;
char *c, *nl;
return -EINVAL;
return -EINVAL;
if (nl) {
return -EINVAL;
w[j].iov_base = &l[i];
w[j++] = iov[i];
if (!have_syslog_identifier &&
return fd;
return -errno;
if (buffer_fd < 0)
return -errno;
return -errno;
return -errno;
return -errno;
size_t n, k;
char buffer[n];
errno = 0;
if (errno == 0) {
return -errno;
int fd;
char *header;
size_t l;
ssize_t r;
if (fd < 0)
return -errno;
return -errno;
return -errno;
if (!identifier)
if ((size_t) r != l) {
return -errno;
return fd;
_public_ int sd_journal_print_with_location(int priority, const char *file, const char *line, const char *func, const char *format, ...) {
_public_ int sd_journal_printv_with_location(int priority, const char *file, const char *line, const char *func, const char *format, va_list ap) {
char_array_0(p);
_public_ int sd_journal_send_with_location(const char *file, const char *line, const char *func, const char *format, ...) {
if (_unlikely_(i < 0)) {
goto finish;
const char *func,
const char *func,
const char *message) {