Commit graph

127 commits

Author SHA1 Message Date
Lennart Poettering dccca82b1a log: minimize includes in log.h
log.h really should only include the bare minimum of other headers, as
it is really pulled into pretty much everything else and already in
itself one of the most basic pieces of code we have.

Let's hence drop inclusion of:

1. sd-id128.h because it's entirely unneeded in current log.h
2. errno.h, dito.
3. sys/signalfd.h which we can replace by a simple struct forward
   declaration
4. process-util.h which was needed for getpid_cached() which we now hide
   in a funciton log_emergency_level() instead, which nicely abstracts
   the details away.
5. sys/socket.h which was needed for struct iovec, but a simple struct
   forward declaration suffices for that too.

Ultimately this actually makes our source tree larger (since users of
the functionality above must now include it themselves, log.h won't do
that for them), but I think it helps to untangle our web of includes a
tiny bit.

(Background: I'd like to isolate the generic bits of src/basic/ enough
so that we can do a git submodule import into casync for it)
2018-01-11 14:44:31 +01:00
Lennart Poettering b6e1fff13d process-util: add another fork_safe() flag for enabling LOG_ERR/LOG_WARN logging 2018-01-04 13:27:26 +01:00
Lennart Poettering 4c253ed1ca tree-wide: introduce new safe_fork() helper and port everything over
This adds a new safe_fork() wrapper around fork() and makes use of it
everywhere. The new wrapper does a couple of things we previously did
manually and separately in a safer, more correct and automatic way:

1. Optionally resets signal handlers/mask in the child

2. Sets a name on all processes we fork off right after forking off (and
   the patch assigns useful names for all processes we fork off now,
   following a systematic naming scheme: always enclosed in () – in order
   to indicate that these are not proper, exec()ed processes, but only
   forked off children, and if the process is long-running with only our
   own code, without execve()'ing something else, it gets am "sd-" prefix.)

3. Optionally closes all file descriptors in the child

4. Optionally sets a PR_SET_DEATHSIG to SIGTERM in the child, in a safe
   way so that the parent dying before this happens being handled
   safely.

5. Optionally reopens the logs

6. Optionally connects stdin/stdout/stderr to /dev/null

7. Debug logs about the forked off processes.
2017-12-25 11:48:21 +01:00
Lennart Poettering fbd0b64f44
tree-wide: make use of new STRLEN() macro everywhere (#7639)
Let's employ coccinelle to do this for us.

Follow-up for #7625.
2017-12-14 19:02:29 +01:00
Zbigniew Jędrzejewski-Szmek 1599f593d6 journal-remote: add helper function and use hashmap_free_with_destructor 2017-11-28 21:34:46 +01:00
Zbigniew Jędrzejewski-Szmek 53e1b68390 Add SPDX license identifiers to source files under the LGPL
This follows what the kernel is doing, c.f.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5fd54ace4721fc5ce2bb5aef6318fcf17f421460.
2017-11-19 19:08:15 +01:00
Lennart Poettering bcde742e78 conf-parser: turn three bool function params into a flags fields
This makes things more readable and fixes some issues with incorrect
flag propagation between the various flavours of config_parse().
2017-11-13 10:24:03 +01:00
martingh 723afa4f96 Reverting erroneous changes made of the course of adding a timeout to journal-remote event handling (#7219) 2017-11-01 10:15:38 +01:00
Yu Watanabe 2e293b4a14 journal-remote: set description to timer_event (#7234)
Follow-up for 5e38eb931f.
2017-11-01 10:13:00 +01:00
martingh 5e38eb931f Adding timer_event to wakeup as suggested by MHD_get_timeout (#7152) 2017-10-26 10:54:30 +02:00
Zbigniew Jędrzejewski-Szmek 349cc4a507 build-sys: use #if Y instead of #ifdef Y everywhere
The advantage is that is the name is mispellt, cpp will warn us.

$ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/"
$ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;'
$ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g'
$ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g'
+ manual changes to meson.build

squash! build-sys: use #if Y instead of #ifdef Y everywhere

v2:
- fix incorrect setting of HAVE_LIBIDN2
2017-10-04 12:09:29 +02:00
Yu Watanabe cb30d3ba66 journal-remote: show error if SplitMode=host with 'active' source is specified 2017-08-30 16:56:41 +09:00
Yu Watanabe 6b1b9f75c8 journal-remote: show error message if output file name does not end with .journal
`journalctl -o export | systemd-journal-remote -o /tmp/dir -`
gives the following error messages.
```
Failed to open output journal /tmp/dir: Invalid argument
Failed to get writer for source stdin: Invalid argument
Failed to create source for fd:0 (stdin): Invalid argument
```
And these are hard to understand what is the problem.
This commit makes journal-remote check whether the output file name
ends with .journal suffix or not, and if not, output error message.
2017-08-27 16:34:57 +09:00
Yu Watanabe e2e8683e6b microhttpd-util: add comment 2017-08-07 10:35:05 +09:00
Yu Watanabe a77e00a5dc journal-remote: remove MHD_USE_PEDANTIC_CHECKS from the default flags
Follow-up for 0105858734.
2017-08-06 23:26:46 +09:00
Yu Watanabe 0105858734 journal-remote: use MHD_OPTION_STRICT_FOR_CLIENT if MHD_USE_PEDANTIC_CHECKS is deprecated
The option MHD_OPTION_STRICT_FOR_CLIENT is provided since libmicrohttpd-0.9.54, and
MHD_USE_PEDANTIC_CHECKS will be deprecated in future.
This makes support both option.
2017-07-28 16:22:14 +09:00
Yu Watanabe c831aa7554 journal-remote,gateway: use MHD_USE_TLS instead of MHD_USE_SSL
The option is renamed in libmicrohttpd-0.9.52.
2017-07-28 13:37:10 +09:00
Lennart Poettering df0ff12775 tree-wide: make use of getpid_cached() wherever we can
This moves pretty much all uses of getpid() over to getpid_raw(). I
didn't specifically check whether the optimization is worth it for each
replacement, but in order to keep things simple and systematic I
switched over everything at once.
2017-07-20 20:27:24 +02:00
Martin Pitt 56744c037d Merge pull request #5756 from keszybz/make-cleanups
Various meson-independent cleanups from the meson patchset
2017-04-21 21:36:56 +02:00
Zbigniew Jędrzejewski-Szmek 58eb279840 microhttpd-util: silence warnings about deprecated options
C.f. 21b6ff3684.
2017-04-21 12:05:55 -04:00
Yu Watanabe da4128543f tree-wide: fix wrong indent (#5757)
Fixes wrong indent introduced by the commit 43688c49d1.
2017-04-19 08:48:29 +02:00
Zbigniew Jędrzejewski-Szmek b18453eda6 Move export format parsing from src/journal-remote/ to src/basic/
No functional change.
2017-02-14 23:56:48 -05:00
Zbigniew Jędrzejewski-Szmek 21b6ff3684 microhttpd-util: silence warnings about deprecated options 2017-01-31 14:04:55 -05:00
Dan Dedrick 800d3f3478 journal-remote: make the child pipe non-blocking
We are going to add this child as a source to our event loop so we don't
want to block when reading data from it as this will prevent us from
processing other events. Specifically this will block the signalfds
which means if we are waiting for data from curl we won't handle SIGTERM
or SIGINT until we happen to get more data.
2016-10-10 15:11:01 -04:00
Martin Pitt 6ac288a990 Merge pull request #4123 from keszybz/network-file-dropins
Network file dropins
2016-09-17 10:00:19 +02:00
Zbigniew Jędrzejewski-Szmek 43688c49d1 tree-wide: rename config_parse_many to …_nulstr
In preparation for adding a version which takes a strv.
2016-09-16 10:32:03 -04:00
Zbigniew Jędrzejewski-Szmek f5e757f1ce microhttpd-util: add the trailing newline automatically
It's prone to error and annoying to have to add it manually. It was
missing from a few places.
2016-09-13 20:10:56 -04:00
Zbigniew Jędrzejewski-Szmek 1b4cd64683 journal-remote: implement %m support in mhd_respondf
errno value is not protected (it is undefined after this function returns).
Various mhd_* functions are not documented to protect errno, so this could not
guaranteed anyway.
2016-09-13 20:10:56 -04:00
Vito Caputo 2604646c05 journal-remote: remove unnecessary gnutls includes (#3895)
journal-(gatewayd,remote).c don't actually utilize libgnutls even when
HAVE_GNUTLS is defined.
2016-08-05 00:05:34 -04:00
Zbigniew Jędrzejewski-Szmek 2d37cd5356 Add enable_disable() helper
In this patch "enabled" and "disabled" is used exclusively, but "enable" and
"disable" forms are need for the following patch.
2016-07-31 22:48:22 -04:00
Vito Caputo 313cefa1d9 tree-wide: make ++/-- usage consistent WRT spacing
Throughout the tree there's spurious use of spaces separating ++ and --
operators from their respective operands.  Make ++ and -- operator
consistent with the majority of existing uses; discard the spaces.
2016-02-22 20:32:04 -08:00
Vito Caputo b58c888f30 journal: defer journal closes on rotate
When we rotate journals, we must set offline and close the current one,
but don't generally need to wait for this to complete.

Instead, we'll initiate an asynchronous offline via
journal_file_set_offline(oldfile, false), and add the file to a
per-server set of deferred closes to be closed later when they
won't block.

There's one complication however; journal_file_open() via
journal_file_verify_header() assumes that any writable journal in the
online state is the product of an unclean shutdown or other form of
corruption.

Thus there's a need for journal_file_open() to be aware of deferred
closes and synchronize with their completion when opening preexisting
journals for writing.  To facilitate this the deferred closes set is
supplied to the journal_file_open() function where the deferred closes
may be closed synchronously before verifying the header in such
circumstances.
2016-02-19 18:50:20 -08:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Klearchos Chaloulos 8c6bcbf892 journal-remote: decrease microhttpd memory limit
Set the MHD_OPTION_CONNECTION_MEMORY_LIMIT to 128KB. The precious value was DATA_SIZE_MAX, which was defined as 1024*1024*768. This caused journal-remote to allocate 756MB for each journal-upload connection, thus exhausting the available memory.
2016-02-04 17:35:24 +02:00
Zbigniew Jędrzejewski-Szmek ce262e5760 Merge pull request #2425 from yuwata/journal-remote-v4
ZJS: remove unnecessary oom check after strdupa().
2016-01-24 11:49:31 -05:00
Yu Watanabe 2f1acf6f13 journal-remote: fix broken --getter option
This commit fixes the following broken --getter option:
when systemd-journal-remote is called with --getter option,
it causes the error meesage "Zero sources specified" and
the getter command will not be called.
2016-01-24 16:12:13 +09:00
Yu Watanabe d10accb0b1 journal-remote: output file name is determined by the remote hostname
When --url option is specified, e.g. --url='http://some.host:19531/entries'
retrieved remote journal entries will be stored to
/var/log/journal/remote/remote-some.host.journal
2016-01-24 16:11:21 +09:00
Yu Watanabe b68f6b0a79 journal-remote: make --url option support arbitrary url
Currently, --url option supports the only form like http(s)://some.host:19531.
This commit adds support to call systemd-journal-remote as follwos:
systemd-journal-remote --url='http://some.host:19531'
systemd-journal-remote --url='http://some.host:19531/'
systemd-journal-remote --url='http://some.host:19531/entries'
systemd-journal-remote --url='http://some.host:19531/entries?boot&follow'
The first three example result the same and retrieve all entries.
The last example retrieves only current boot entries and wait new events.
2016-01-24 15:45:47 +09:00
Daniel Mack 371859d6b5 Merge pull request #2080 from chaloulo/split-mode-host-remove-port-from-journal-filename
journal-remote: split-mode=host, remove port from journal filename
2016-01-22 09:47:59 +01:00
Susant Sahani 7b7afdfc07 systemd-activate: Add support for datagram sockets
core: Add flexible way to provide socket type
the socket type should be a diffrent argumet
in make_socket_fd . In this way we can set the socket
type like SOCK_STREAM SOCK_DGRAM in the address.

journal-remote: modify make_socket_fd
2016-01-22 09:41:44 +05:30
Zbigniew Jędrzejewski-Szmek ce7229a224 journal-remote: fix warning about deprecated µhttpd macro
src/journal-remote/journal-remote.c:590:13: warning: Value MHD_HTTP_METHOD_NOT_ACCEPTABLE is deprecated, use MHD_HTTP_NOT_ACCEPTABLE
                 return mhd_respond(connection, MHD_HTTP_METHOD_NOT_ACCEPTABLE,
             ^

The new define was added in 0.9.38. Instead of requiring the new
libmicrohttpd version, provide the fallback, it is trivial.
2016-01-18 15:21:28 -05:00
Michael Scherer 9d3737f13e Add Seal option in the configuration file for journald-remote
While journal received remotely can be sealed, it can only be done
on the command line using --seal, so for consistency, we will
also permit to set it in the configuration file.
2015-12-20 13:23:33 +01:00
Klearchos Chaloulos 366b7db4b6 journal-remote: split-mode=host, remove port from journal filename
When constructing the journal filename to store logs from a remote host, remove the port of the tcp connection, as the port will change with every reboot/connection loss between sender/reveiver machines. Having the port in the filename will cause a new journal file to be created for every reboot or connection loss.
For the implementation, a new argument "bool include_port" is added to the getpeername_pretty() function. This is passed to the sockaddr_pretty() function. The value of the include_port argument is set to true in all calls of getpeername_pretty(), except for 2 calls in journal-remote.c, where it is set to false.
2015-12-01 19:29:59 +02:00
Lennart Poettering 75eb615480 defs: rework CONF_DIRS_NULSTR() macro
The macro is generically useful for putting together search paths, hence
let's make it truly generic, by dropping the implicit ".d" appending it
does, and leave that to the caller. Also rename it from
CONF_DIRS_NULSTR() to CONF_PATHS_NULSTR(), since it's not strictly about
dirs that way, but any kind of file system path.

Also, mark CONF_DIR_SPLIT_USR() as internal macro by renaming it to
_CONF_PATHS_SPLIT_USR() so that the leading underscore indicates that
it's internal.
2015-11-10 17:31:31 +01:00
Michal Schmidt 709f6e46a3 treewide: use the negative error codes returned by our functions
Our functions return negative error codes.
Do not rely on errno being set after calling our own functions.
2015-11-05 13:44:06 +01:00
Lennart Poettering a0f29c767a util-lib: move CONF_DIRS_NULSTR definition to def.h
After all, this is not some compiler or C magic, but something very
specific to how systemd works, hence let's move it into def.h, and out
of macro.h
2015-11-03 17:45:11 +01:00
Lennart Poettering 3958325852 journal-remote: remove unused variable warning when building without GNUTLS. 2015-11-01 22:14:13 +01:00
Dongsu Park 5e3efccfc9 journal-remote: increase memory limit per connection to avoid errors with HTTPS
Explicitly set MHD_OPTION_CONNECTION_MEMORY_LIMIT to a larger value,
when setting up microhttpd, to give more memory per HTTP(S) connection.

This way systemd-journal-remote can now prevent microhttpd from failing
in creating response headers with messages like "Not enough memory for
write", especially when lots of HTTPS requests arrive. That's precisely
because MHD_OPTION_CONNECTION_MEMORY_LIMIT in libmicrohttpd defaults to
32768, which is in practice insufficient in this case.
See also https://gnunet.org/bugs/view.php?id=4007 for more details.

Fixes: https://github.com/coreos/bugs/issues/927
2015-10-30 15:12:48 +01:00
Susant Sahani b1f48e3c94 journal-remote: port to extract_first_word 2015-10-28 22:57:59 +05:30
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00