shl_log: be more pedantic about errno-resets

errno sucks! But to make specifiers like %m work, we need to keep errno
valid until we call vfprintf() on the users code.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
shl_llog: be more pedantic with errno-resets

Set errno correctly directly before calling into the user's logging
helper. Otherwise, errno might have been reset in between. Stupid errno!

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
shl_llog: make llog_EXYZ helpers use llog_error

Errors like EINVAL, EFAULT and ENOMEM are actual errors. Don't hide these
messages behind LLOG_DEBUG.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
shl_llog: add llog_ERRNO() helper

This helper can be used whenever a syscall fails and glibc has set errno.
It prints the error code and message with a short introduction.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
shl_log: add log_EXYZ() helpers from llog

Same helpers as llog but for the main logger.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
shl_log: allow unlocked time-reading

Our logger is unlocked so the global time-variable may be initialized by
two threads at the same time. This doesn't matter, though. Add a comment
why and fix a possible negative time-diff.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
shl_log: add log_sev_max as maximum log-level

log_sev_max defines the maximum log-level which is not discarded.
Severities above LOG_SEV_NUM (inclusive) are still accepted so users can
render messages without log-levels.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
shl_log: init time even if log is discarded

We should initialize the log-timer even if the message is discarded.
Otherwise, silent startups are not possible.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
pty: don't return empty buffers during peek

If the ring-end is at pos 0, we don't need two buffers as the second
buffer would be empty.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
l+og: add l?og_EPIPE helpers

Similar to EINVAL/etc., the EPIPE handler can be used if a file-descriptor
is closed unexpectedly (eg., HUP on timerfd..).

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
ring: add separate shl_ring helper

The shl_ring helper is a basic, but fast, ring buffer implementation. It
is mostly copied from pty but with proper namespacing.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>