Commit graph

75 commits

Author SHA1 Message Date
Lennart Poettering 8fcde01280 util-lib: split stat()/statfs()/stavfs() related calls into stat-util.[ch] 2015-10-27 13:25:56 +01:00
Lennart Poettering 6bedfcbb29 util-lib: split string parsing related calls from util.[ch] into parse-util.[ch] 2015-10-27 13:25:55 +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 4f5dd3943b util: split out escaping code into escape.[ch]
This really deserves its own file, given how much code this is now.
2015-10-24 23:04:42 +02:00
Tom Gundersen 8c1ba93e2a Merge pull request #1406 from blaskovic/journal-remote-typo
journal-remote: typo in log_error when no sources are specified

[tomegun: this was a pun, but let's not do that]
2015-10-05 23:24:09 +02:00
Lennart Poettering ef08ced6b4 journal: make sure to set MHD_USE_PIPE_FOR_SHUTDOWN for libmicrohttpd servers
This makes sure libmicrohttpd won't call shutdown() on our listening
sockets, which make sure socket activation and re-activation will work
cleanly.

See:

https://github.com/systemd/systemd/pull/1286
https://lists.gnu.org/archive/html/libmicrohttpd/2015-09/msg00014.html

Fixes #1286
2015-09-30 23:59:06 +02:00
Lennart Poettering 3f6fd1ba65 util: introduce common version() implementation and use it everywhere
This also allows us to drop build.h from a ton of files, hence do so.
Since we touched the #includes of those files, let's order them properly
according to CODING_STYLE.
2015-09-29 21:08:37 +02:00
Branislav Blaskovic f823da67a6 journal-remote: typo in log_error when no sources are specified 2015-09-29 14:43:40 +02:00
Lennart Poettering 57255510c9 tree-wide: replace while(1) by for(;;) everywhere
Another Coccinelle script.
2015-09-09 14:59:53 +02:00
Lennart Poettering 1f6b411372 tree-wide: update empty-if coccinelle script to cover empty-while and more
Let's also clean up single-line while and for blocks.
2015-09-09 14:59:51 +02:00
Lennart Poettering 76ef789d26 tree-wide: make use of log_error_errno() return value
Turns this:

        r = -errno;
        log_error_errno(errno, "foo");

into this:

        r = log_error_errno(errno, "foo");

and this:

        r = log_error_errno(errno, "foo");
        return r;

into this:

        return log_error_errno(errno, "foo");
2015-09-09 08:20:20 +02:00
Richard Maw 8adaf7bd23 strv: convert strv_split_quotes into a generic strv_split_extract
strv_split_extract is to strv_split_quotes as extract_first_word was to
unquote_first_word.

Now there's extract_first_word for extracting a single argument,
extract_many_words for extracting a bounded number of arguments,
and strv_split_extract for extracting an arbitrary number of arguments.
2015-08-07 15:50:43 +00:00
Lennart Poettering 1938ac5136 socket-util: library calls shouldn't log on their own
Instead, make sure that all callers log properly.
2015-07-29 12:38:22 +02:00
Lennart Poettering 72c0a2c255 everywhere: port everything to sigprocmask_many() and friends
This ports a lot of manual code over to sigprocmask_many() and friends.

Also, we now consistly check for sigprocmask() failures with
assert_se(), since the call cannot realistically fail unless there's a
programming error.

Also encloses a few sd_event_add_signal() calls with (void) when we
ignore the return values for it knowingly.
2015-06-15 20:13:23 +02:00
Lennart Poettering ce30c8dcb4 tree-wide: whenever we fork off a foreign child process reset signal mask/handlers
Also, when the child is potentially long-running make sure to set a
death signal.

Also, ignore the result of the reset operations explicitly by casting
them to (void).
2015-06-10 01:28:58 +02:00
Lennart Poettering 24882e06c1 util: split out signal-util.[ch] from util.[ch]
No functional changes.
2015-05-29 20:14:11 +02:00
Harald Hoyer a7f7d1bde4 fix gcc warnings about uninitialized variables
like:

src/shared/install.c: In function ‘unit_file_lookup_state’:
src/shared/install.c:1861:16: warning: ‘r’ may be used uninitialized in
this function [-Wmaybe-uninitialized]
         return r < 0 ? r : state;
                ^
src/shared/install.c:1796:13: note: ‘r’ was declared here
         int r;
             ^
2015-03-27 14:57:38 +01:00
Lennart Poettering 4034a06ddb util: rework word parsing and c unescaping code
When parsing words from input files, optionally automatically unescape
the passed strings, controllable via a new flags parameter.

Make use of this in tmpfiles, and port everything else over, too.

This improves parsing quite a bit, since we no longer have to process the
same string multiple times with different calls, where an earlier call
might corrupt the input for a later call.
2015-03-26 11:56:22 +01:00
Zbigniew Jędrzejewski-Szmek d357562c48 µhttp-util: setup gnutls logs in one function 2015-03-13 23:42:16 -04:00
David Herrmann 15411c0cb1 tree-wide: there is no ENOTSUP on linux
Replace ENOTSUP by EOPNOTSUPP as this is what linux actually uses.
2015-03-13 14:10:39 +01:00
David Herrmann ff55c3c732 journal-remote: stop using EWOULDBLOCK
There is no reason to ever use EWOULDBLOCK. It's equivalent to EAGAIN on
all architectures on linux.
2015-03-13 14:10:35 +01:00
Zbigniew Jędrzejewski-Szmek 043945b938 journal-remote: process events without delay
journal-remote buffers input, and then parses it handling one journal entry at a time.
It was possible for useful data to be left in the buffer after some entries were
processesed. But all data would be already read from the fd, so there would be
no reason for the event loop to call the handler again. After some new data came in,
the handler would be called again, and would then process the "old" data in the buffer.

Fix this by enabling a handler wherever we process input data and do not exhaust data
from the input buffer (i.e. when EAGAIN was not encountered). The handler runs until
we encounter EAGAIN.

Looping over the input data is done in this roundabout way to allow the event loop
to dispatch other events in the meanwhile. If the loop was inside the handler, a
source which produced data fast enough could completely monopolize the process.

https://bugs.freedesktop.org/show_bug.cgi?id=89516
2015-03-13 00:26:02 -04:00
Zbigniew Jędrzejewski-Szmek f53f7c8fc4 journal-remote: check also for EWOULDBLOCK
This matches similar code elsewhere.
2015-03-13 00:26:02 -04:00
Zbigniew Jędrzejewski-Szmek 0e72da6fe8 journal-remote: downgrade routine messages to debug
https://bugs.freedesktop.org/show_bug.cgi?id=89486
2015-03-13 00:26:02 -04:00
Thomas Hindoe Paaboel Andersen 2eec67acbb remove unused includes
This patch removes includes that are not used. The removals were found with
include-what-you-use which checks if any of the symbols from a header is
in use.
2015-02-23 23:53:42 +01:00
Lennart Poettering 63c372cb9d util: rework strappenda(), and rename it strjoina()
After all it is now much more like strjoin() than strappend(). At the
same time, add support for NULL sentinels, even if they are normally not
necessary.
2015-02-03 02:05:59 +01: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
Thomas Hindoe Paaboel Andersen abc08d4d08 wrap a few *_FOREACH macros in curly braces
cppcheck would give up with "syntax error" without them. This led
to reports of syntax errors in unrelated locations and potentially
hid other errors
2014-12-12 21:57:44 +01:00
Josh Triplett bf257aed05 journald-remote,journal-upload: Support .d directories in the usual search paths 2014-11-29 13:55:32 -05:00
Michal Schmidt 4a62c710b6 treewide: another round of simplifications
Using the same scripts as in f647962d64 "treewide: yet more log_*_errno
+ return simplifications".
2014-11-28 19:57:32 +01:00
Michal Schmidt 56f64d9576 treewide: use log_*_errno whenever %m is in the format string
If the format string contains %m, clearly errno must have a meaningful
value, so we might as well use log_*_errno to have ERRNO= logged.

Using:
find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\((".*%m.*")/log_\1_errno(errno, \2/'

Plus some whitespace, linewrap, and indent adjustments.
2014-11-28 19:49:27 +01:00
Michal Schmidt f647962d64 treewide: yet more log_*_errno + return simplifications
Using:
find . -name '*.[ch]' | while read f; do perl -i.mmm -e \
 'local $/;
  local $_=<>;
  s/(if\s*\([^\n]+\))\s*{\n(\s*)(log_[a-z_]*_errno\(\s*([->a-zA-Z_]+)\s*,[^;]+);\s*return\s+\g4;\s+}/\1\n\2return \3;/msg;
  print;'
 $f
done

And a couple of manual whitespace fixups.
2014-11-28 18:56:16 +01:00
Michal Schmidt 23bbb0de4e treewide: more log_*_errno + return simplifications 2014-11-28 18:24:30 +01:00
Michal Schmidt eb56eb9b40 treewide: simplify log_*_errno(r,...) immediately followed by "return r" 2014-11-28 17:34:26 +01:00
Michal Schmidt c33b329709 treewide: more log_*_errno() conversions, multiline calls
Basically:

find . -name '*.[ch]' | while read f; do perl -i.mmm -e \
'local $/;
 local $_=<>;
 s/log_(debug|info|notice|warning|error|emergency)\("([^"]*)%s"([^;]*),\s*strerror\(-?([->a-zA-Z_]+)\)\);/log_\1_errno(\4, "\2%m"\3);/gms;print;' \
 $f; done

Plus manual indentation fixups.
2014-11-28 17:17:51 +01:00
Michal Schmidt da927ba997 treewide: no need to negate errno for log_*_errno()
It corrrectly handles both positive and negative errno values.
2014-11-28 13:29:21 +01:00
Michal Schmidt 0a1beeb642 treewide: auto-convert the simple cases to log_*_errno()
As a followup to 086891e5c1 "log: add an "error" parameter to all
low-level logging calls and intrdouce log_error_errno() as log calls
that take error numbers", use sed to convert the simple cases to use
the new macros:

find . -name '*.[ch]' | xargs sed -r -i -e \
's/log_(debug|info|notice|warning|error|emergency)\("(.*)%s"(.*), strerror\(-([a-zA-Z_]+)\)\);/log_\1_errno(-\4, "\2%m"\3);/'

Multi-line log_*() invocations are not covered.
And we also should add log_unit_*_errno().
2014-11-28 12:04:41 +01:00
Lennart Poettering f88e6be5ee strv: rework strv_split_quoted() to use unquote_first_word()
This should make the unquoting scheme a bit less naive.
2014-11-10 23:45:12 +01:00
Lennart Poettering f1f00dbb7f sd-event: implicitly set signal event source's descriptions to the signal name 2014-11-04 18:09:19 +01:00
Lennart Poettering 356779df90 sd-event: rename sd_event_source_set_name() to sd_event_source_get_name()
To mirror the recent name change of the concept for sd_bus objects,
follow the same logic for sd_event_source objects, too.
2014-11-04 18:09:19 +01:00
Zbigniew Jędrzejewski-Szmek cb41ff2922 shared/log: add log_trace as compile-time optional debugging
Repetetive messages can be annoying when running with
SYSTEMD_LOG_LEVEL=debug, but they are sometimes very useful
when debugging problems. Add log_trace which is like log_debug
but becomes a noop unless LOG_TRACE is defined during compilation.
This makes it easy to enable very verbose logging for a subset
of programs when compiling from source.
2014-10-23 00:27:57 -04:00
Zbigniew Jędrzejewski-Szmek a7736b14de journal-remote: add --split-mode to help 2014-10-23 00:26:33 -04:00
Zbigniew Jędrzejewski-Szmek 9ce998b937 journal-remote: better error message on failure
Return a proper code instead of simply NULL for failure.
2014-10-23 00:18:47 -04:00
Zbigniew Jędrzejewski-Szmek 1af719edc5 systemd-upload: print paths in help() 2014-10-23 00:18:15 -04:00
Zbigniew Jędrzejewski-Szmek 43300d9d38 journal-remote: give names to event sources
This possibility was recently added, and it makes debugging much nicer.
2014-10-23 00:18:13 -04:00
Zbigniew Jędrzejewski-Szmek 42b6bf75e4 journal-upload: fix socket activation 2014-10-23 00:18:10 -04:00
Zbigniew Jędrzejewski-Szmek 1f8af042d9 journal-remote: fix mem leak on error 2014-10-14 21:18:41 -04:00
Zbigniew Jędrzejewski-Szmek 70f1b2ddc6 journal-remote: fix handling of non-blocking sources
In the conversion to sd-event loop, handling of normal files got
broken. We do not want to perform non-blocking reads on them, but
simply do read() in a loop. Install a statically-enabled "source"
to do that.
2014-09-29 11:08:04 -04:00