Commit Graph

53 Commits

Author SHA1 Message Date
Lennart Poettering 4850d39ab7 journald: add a couple of static asserts checking logging constants
Whenever we include a log level or facility in a journal string field, make sure the compiler checks for us that that's
actually the right thing to do.
2016-01-26 14:43:24 +01:00
Zbigniew Jędrzejewski-Szmek 4941e4aca9 journal: silently skip failing large messages if journald is missing
We treated -ENOENT errors with silent failure, for small messages.
Do the same for large messages.
2015-12-03 11:44:59 -05:00
Zbigniew Jędrzejewski-Szmek 726f4c4738 journal: unbreak sd_journal_sendv
Borked since
commit 3ee897d6c2
Author: Lennart Poettering <lennart@poettering.net>
Date:   Wed Sep 23 01:00:04 2015 +0200

    tree-wide: port more code to use send_one_fd() and receive_one_fd()

because here our fd is not connected and we need to specify
the address.
2015-12-03 09:14:01 -05:00
Zbigniew Jędrzejewski-Szmek 9a7800af08 journal: addition and multiplication do not commute 2015-12-03 09:14:01 -05:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering 15a5e95075 util-lib: split out printf() helpers to stdio-util.h 2015-10-27 13:25:57 +01:00
Lennart Poettering 0d39fa9c69 util-lib: move more file I/O related calls into fileio.[ch] 2015-10-27 13:25:55 +01:00
Lennart Poettering c004493cde util-lib: split out IO related calls to io-util.[ch] 2015-10-26 01:24:38 +01:00
Lennart Poettering 3ffd4af220 util-lib: split out fd-related operations into fd-util.[ch]
There are more than enough to deserve their own .c file, hence move them
over.
2015-10-25 13:19:18 +01:00
Lennart Poettering 07630cea1f util-lib: split our string related calls from util.[ch] into its own file string-util.[ch]
There are more than enough calls doing string manipulations to deserve
its own files, hence do something about it.

This patch also sorts the #include blocks of all files that needed to be
updated, according to the sorting suggestions from CODING_STYLE. Since
pretty much every file needs our string manipulation functions this
effectively means that most files have sorted #include blocks now.

Also touches a few unrelated include files.
2015-10-24 23:05:02 +02:00
Lennart Poettering 3ee897d6c2 tree-wide: port more code to use send_one_fd() and receive_one_fd()
Also, make it slightly more powerful, by accepting a flags argument, and
make it safe for handling if more than one cmsg attribute happens to be
attached.
2015-09-29 21:08:37 +02:00
Zbigniew Jędrzejewski-Szmek 5ffa8c8181 Add a snprinf wrapper which checks that the buffer was big enough
If we scale our buffer to be wide enough for the format string, we
should expect that the calculation was correct.

char_array_0() invocations are removed, since snprintf nul-terminates
the output in any case.

A similar wrapper is used for strftime calls, but only in timedatectl.c.
2015-02-01 17:21:39 -05:00
Zbigniew Jędrzejewski-Szmek 1fa2f38f0f Assorted format fixes
Types used for pids and uids in various interfaces are unpredictable.
Too bad.
2015-01-22 01:14:52 -05:00
Zbigniew Jędrzejewski-Szmek 553acb7b6b treewide: sanitize loop_write
loop_write() didn't follow the usual systemd rules and returned status
partially in errno and required extensive checks from callers. Some of
the callers dealt with this properly, but many did not, treating
partial writes as successful. Simplify things by conforming to usual rules.
2014-12-09 21:36:08 -05:00
Lennart Poettering a09abc4ae0 memfd: rename memfd.h to memfd-util.h to avoid any confusion with any libc provided headers 2014-10-30 18:32:37 +01:00
Lennart Poettering 73843b5258 memfd: always use our internal utility functions where we have them 2014-10-30 18:28:37 +01:00
Lennart Poettering c79e98eadd journal: when sending huge log messages prefer memfds over temporary files in /dev/shm
Previously when a log message grew beyond the maximum AF_UNIX/SOCK_DGRAM
datagram limit we'd send an fd to a deleted file in /dev/shm instead.
Because the sender could still modify the file after delivery we had to
immediately copy the data on the receiving side.

With memfds we can optimize this logic, and also remove the dependency
on /dev/shm: simply send a sealed memfd around, and if we detect the
seal memory map the fd and use it directly.
2014-10-30 17:36:02 +01:00
Zbigniew Jędrzejewski-Szmek 61c024b328 journal-send.c: use automatic cleanup 2014-06-19 08:53:31 -04:00
Lennart Poettering 03e334a1c7 util: replace close_nointr_nofail() by a more useful safe_close()
safe_close() automatically becomes a NOP when a negative fd is passed,
and returns -1 unconditionally. This makes it easy to write lines like
this:

        fd = safe_close(fd);

Which will close an fd if it is open, and reset the fd variable
correctly.

By making use of this new scheme we can drop a > 200 lines of code that
was required to test for non-negative fds or to reset the closed fd
variable afterwards.
2014-03-18 19:31:34 +01:00
Zbigniew Jędrzejewski-Szmek 87b0284327 Get rid of write_safe
Current glibc implementation is safe. Kernel does this atomically,
and write is actually implemented through writev. So if write is
async-signal-safe, than writev pretty much must be too.
2014-01-28 19:07:12 -05:00
Zbigniew Jędrzejewski-Szmek 65b3903ff5 journal: guarantee async-signal-safety in sd_journald_sendv
signal(7) provides a list of functions which may be called from a
signal handler. Other functions, which only call those functions and
don't access global memory and are reentrant are also safe.
sd_j_sendv was mostly OK, but would call mkostemp and writev in a
fallback path, which are unsafe.

Being able to call sd_j_sendv in a async-signal-safe way is important
because it allows it be used in signal handlers.

Safety is achieved by replacing mkostemp with open(O_TMPFILE) and an
open-coded writev replacement which uses write. Unfortunately,
O_TMPFILE is only available on kernels >= 3.11. When O_TMPFILE is
unavailable, an open-coded mkostemp is used.

https://bugzilla.gnome.org/show_bug.cgi?id=722889
2014-01-27 23:17:02 -05:00
Zbigniew Jędrzejewski-Szmek 8e33886ec5 Replace mkostemp+unlink with open(O_TMPFILE)
This will only work on Linux >= 3.11, and probably not on all
filesystems. Fallback code is provided.
2014-01-27 23:17:02 -05:00
Zbigniew Jędrzejewski-Szmek 6c045c0b4c journal: fail silently in sd_j_sendv() if journal is unavailable
"syslog(3) and sd_journal_print() may largely be used interchangeably
functionality-wise" according to sd_journal_print(3). This socket
should be always available except in rare circumstatances, and we
don't random applications to fail on logging, so let's do what syslog
did. The alternative of forcing all callers to do error handling for
this rare case doesn't really have any benefits, since if they can't
log there isn't much they can do anyway.

https://bugzilla.redhat.com/show_bug.cgi?id=1023041
2013-12-03 12:11:18 -05:00
Thomas Hindoe Paaboel Andersen 1ae464e093 Use assert_return in more of the public API 2013-12-02 23:13:58 +01:00
Lennart Poettering 44b601bc79 macro: clean up usage of gcc attributes
Always use our own macros, and name all our own macros the same style.
2013-10-16 06:14:59 +02:00
Shawn Landden 2a0e069256 remove hasprefix(), use startswith() 2013-08-22 00:52:14 -04:00
Zbigniew Jędrzejewski-Szmek fd59d9f298 Add hasprefix macro to check prefixes of fixed length 2013-06-20 23:03:58 -04:00
Zbigniew Jędrzejewski-Szmek 6e5abe1564 journal: use initialization instead of zeroing 2013-06-13 23:32:14 -04:00
Zbigniew Jędrzejewski-Szmek 44a6b1b680 Add __attribute__((const, pure, format)) in various places
I'm assuming that it's fine if a _const_ or _pure_ function
calls assert. It is assumed that the assert won't trigger,
and even if it does, it can only trigger on the first call
with a given set of parameters, and we don't care if the
compiler moves the order of calls.
2013-05-02 22:52:09 -04:00
Lennart Poettering 5c0aa72a49 util: add a bit of syntactic sugar for saving/restoring errno 2013-04-02 17:47:59 +02:00
Zbigniew Jędrzejewski-Szmek 29abad107f journal: fix warning about pointer arithmetic
../src/journal/journal-send.c: In function 'sd_journal_sendv':
../src/journal/journal-send.c:250:73: warning: pointer of type 'void *' used in arithmetic [-Wpointer-arith]
2012-11-25 21:43:44 +01:00
Lennart Poettering ee55db4144 journal-send: always send SYSLOG_IDENTIFIER, if we have it
https://bugzilla.redhat.com/show_bug.cgi?id=872193
2012-11-20 21:39:16 +01:00
Lennart Poettering 3ed08c446c journal-send: unify a bit of code 2012-11-20 21:39:16 +01:00
Lennart Poettering 07c289875f journal-send: simplification 2012-10-03 11:55:38 -04:00
Lennart Poettering 72f1d5a288 journal: also use new VA_FORMAT_ADVANCE() macro in sd_journal_send() 2012-09-24 23:42:03 +02:00
Lennart Poettering a6e87e90ed journalctl: rework JSON output mode
This splits the JSON output mode into different modes: json and
json-pretty. The former printing one entry per line, the latter showing
JSON objects nicely indented and in multiple lines to make it easier to
read for humans.
2012-09-05 15:25:32 -07:00
Lennart Poettering 18c7ed186b journal: add sd_journal_perror() to API 2012-08-01 19:53:23 +02:00
Lennart Poettering 8b38f3cc3e journal: fix sd_journal_stream_fd() 2012-06-22 00:19:13 +02:00
Lennart Poettering 25d042e815 journal: fix missing variable initialization 2012-04-12 17:43:33 +02:00
Lennart Poettering 5430f7f2bc relicense to LGPLv2.1 (with exceptions)
We finally got the OK from all contributors with non-trivial commits to
relicense systemd from GPL2+ to LGPL2.1+.

Some udev bits continue to be GPL2+ for now, but we are looking into
relicensing them too, to allow free copy/paste of all code within
systemd.

The bits that used to be MIT continue to be MIT.

The big benefit of the relicensing is that closed source code may now
link against libsystemd-login.so and friends.
2012-04-12 00:24:39 +02:00
Lennart Poettering b070e7f3c9 journal: implicitly add code location to all messages logged with the native interface
This logic can be turned off by defining SD_JOURNAL_SUPPRESS_LOCATION
before including sd-journal.h.

This also saves/restores errno in all logging functions, in order to be
useful as logging calls without side-effects.

This also adds a couple of __unlikely__ around the early checks in the
logging calls, in order to minimize the runtime impact.
2012-04-02 19:29:48 +02:00
Lennart Poettering bb99a35a87 log: increase socket buffers for logging by default 2012-01-27 18:57:37 +01:00
Lennart Poettering 9058851be7 journal: when sending journal data via file, place it in /dev/shm, to allow early boot operation, even if it sucks 2012-01-18 15:40:58 +01:00
Lennart Poettering 0dad12c190 journal: if the data to be sent is larger than the maximum datagram size resort to passing a temporary fd over native protocol 2012-01-14 01:54:33 +01:00
Lennart Poettering 5ba081b0fb log: make internal log api log directly to the journal 2012-01-12 04:34:31 +01:00
Lennart Poettering 4cd9a9d9ec journal: rename syslog tag to identifier since that's what we call it on the server side. 2012-01-05 21:46:48 +01:00
Lennart Poettering 86b9b8e70d sd-journal: close reading side of sd_journal_stream_fd() file descriptors 2012-01-05 21:39:31 +01:00
Lennart Poettering 259d2e7620 journal: move sockets into their own subdir 2012-01-05 20:24:16 +01:00
Lennart Poettering 224f2ee221 journald: add configuration file options to forward all logged data to kmsg, console, syslog 2012-01-05 15:39:03 +01:00
Lennart Poettering a5344d2c3b journal: add _public_ to all sd-journal calls, and add parameter checks 2012-01-03 21:08:58 +01:00