journal-send.c revision 7f3e62571a63ac90de6ac5eefeeb8d3e9aa6f49e
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2011 Lennart Poettering
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <stddef.h>
#include "sd-journal.h"
#include "util.h"
/* We open a single fd, and we'll share it with the current process,
* all its threads, and all its subprocesses. This means we need to
* initialize it atomically, and need to operate on it atomically
* never assuming we are the only user */
static int journal_fd(void) {
int fd;
static int fd_plus_one = 0;
if (fd_plus_one > 0)
return fd_plus_one - 1;
if (fd < 0)
return -errno;
goto retry;
}
return fd;
}
int sd_journal_print(const char *format, ...) {
int r;
return r;
}
}
int sd_journal_send(const char *format, ...) {
int r, n = 0, i = 0, j;
while (format) {
struct iovec *c;
char *buffer;
if (i >= n) {
if (!c) {
r = -ENOMEM;
goto fail;
}
iov = c;
}
r = -ENOMEM;
goto fail;
}
}
r = sd_journal_sendv(iov, i);
fail:
for (j = 0; j < i; j++)
return r;
}
int fd;
struct iovec *w;
uint64_t *l;
int i, j = 0;
struct sockaddr_un sa;
if (!iov || n <= 0)
return -EINVAL;
for (i = 0; i < n; i++) {
char *c, *nl;
if (!c)
return -EINVAL;
if (nl) {
if (nl < c)
return -EINVAL;
/* Already includes a newline? Bummer, then
* let's write the variable name, then a
* newline, then the size (64bit LE), followed
* by the data and a final newline */
j++;
IOVEC_SET_STRING(w[j++], "\n");
w[j].iov_base = &l[i];
j++;
w[j].iov_base = c + 1;
j++;
} else
/* Nothing special? Then just add the line and
* append a newline */
w[j++] = iov[i];
IOVEC_SET_STRING(w[j++], "\n");
}
fd = journal_fd();
if (fd < 0)
return fd;
mh.msg_iovlen = j;
return -errno;
return 0;
}