Commit graph

1575 commits

Author SHA1 Message Date
Lennart Poettering ec6bdf7259 copy: rework copy_file_atomic() to copy the specified file via O_TMPFILE if possible 2018-06-07 17:40:14 +02:00
Zbigniew Jędrzejewski-Szmek 869881a6cb test-bus-util: add a test for destroy callbacks 2018-06-06 23:01:57 +02:00
Zbigniew Jędrzejewski-Szmek 24924cc959 test-bus-util: add a simple test for bus_request_name_async_may_reload_dbus()
This shows a minor memleak:
==1883== 24 bytes in 1 blocks are definitely lost in loss record 1 of 1
==1883==    at 0x4C2DBAB: malloc (vg_replace_malloc.c:299)
==1883==    by 0x4E9D385: malloc_multiply (alloc-util.h:69)
==1883==    by 0x4EA2959: bus_request_name_async_may_reload_dbus (bus-util.c:1841)
==1883==    by ...

The exchange of messages is truncated at two different points: once right
after the first callback is requested, and the second time after the full
sequence has run (usually resulting in an error because of policy).
2018-06-06 23:01:25 +02:00
Lennart Poettering 9264cc39ce main: split out reading of /proc/sys/fs/nr_open into its own function
This doesn't really reduce the code size over all, but it does make main.c
shorter and more readable, and that's always a good thing.
2018-06-06 14:39:15 +02:00
Zbigniew Jędrzejewski-Szmek a1230ff972 basic/log: add the log_struct terminator to macro
This way all callers do not need to specify it.
Exhaustively tested by running test-log under valgrind ;)
2018-06-04 13:46:03 +02:00
Lennart Poettering b5b74e4b12
Merge pull request #9167 from keszybz/ellipsization
Ellipsization fixes based on unit-testing and fuzzing
2018-06-04 13:45:03 +02:00
Zbigniew Jędrzejewski-Szmek cb747347ac
Merge pull request #9149 from yuwata/fix-9107
path-util: introduce path_simplify()
2018-06-04 10:13:40 +02:00
Yu Watanabe a6dffbb7e7 test: fix function name 2018-06-04 09:33:45 +02:00
Yu Watanabe f106314c89 conf-parser: remove redundant utf8-validity check 2018-06-04 01:38:54 +09:00
Yu Watanabe 2b633119a0 test: add test for trailing dot in WorkingDirectory= and RuntimeDirectory= 2018-06-03 23:59:51 +09:00
Yu Watanabe cd4f53c5b5 conf-parse: use path_simplify_and_warn() in config_parse_path() 2018-06-03 23:57:30 +09:00
Yu Watanabe 4805426279 path-util: make path_make_relative() support path including dots 2018-06-03 23:54:32 +09:00
Yu Watanabe 858d36c1ec path-util: introduce path_simplify()
The function is similar to path_kill_slashes() but also removes
initial './', trailing '/.', and '/./' in the path.
When the second argument of path_simplify() is false, then it
behaves as the same as path_kill_slashes(). Hence, this also
replaces path_kill_slashes() with path_simplify().
2018-06-03 23:39:26 +09:00
Zbigniew Jędrzejewski-Szmek 9924aef690 test-ellipsize: add tests for ellipsize_mem, fix bugs
First, ellipsize() and ellipsize_mem() should not read past the input
buffer. Those functions take an explicit length for the input data, so they
should not assume that the buffer is terminated by a nul.

Second, ellipsization was off in various cases where wide on multi-byte
characters were used.

We had some basic test for ellipsize(), but apparently it wasn't enough to
catch more serious cases.

Should fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=8686.
2018-06-02 21:53:25 +02:00
Zbigniew Jędrzejewski-Szmek 4dae3ef6c0
Merge pull request #9156 from shr-project/jansa/gcc8
time-util: fix build with gcc8 -Werror=format-truncation=
2018-06-02 16:18:59 +02:00
Zbigniew Jędrzejewski-Szmek f1880a4b02 test-time-util: print names of test functions
This makes it easier to find the right spot in the long output.
2018-06-02 10:41:26 +02:00
Mike Gilbert 96f64eb574 basic: set errno in raw_clone() on sparc
sparc sets the carry bit when a syscall fails. Use this information to
set errno and return -1 as appropriate.

The added test case calls raw_clone() with flags known to be invalid
according to the clone(2) manpage.
2018-06-02 09:48:19 +02:00
Lennart Poettering ce26882553 process-util: also filter non-printable characters in get_process_com()
We already do that in get_process_cmdline(), which is very similar in
behaviour otherwise. Hence, let's be safe and also filter them in
get_process_comm(). Let's try to retain as much information as we can
though and escape rather than suppress unprintable characters. Let's not
increase comm names beyond the kernel limit on such names however.

Also see discussion about this here:

https://marc.info/?l=linux-api&m=152649570404881&w=2
2018-06-01 21:53:13 +02:00
Lennart Poettering 61f6e27671 string-util: tweak cellescape() a bit
For short buffer sizes cellescape() was a bit wasteful, as it might
suffice to to drop a single character to find enough place for the full
four byte ellipsis, if that one character was a four character escape.
With this rework we'll guarantee to drop the minimum number of
characters from the end to fit in the ellipsis.

If the buffers we write to are large this doesn't matter much. However,
if they are short (as they are when talking about the process comm
field) then it starts to matter that we put as much information as we
can in the space we get.
2018-06-01 21:49:16 +02:00
Lennart Poettering 92f14395cd missing: define kernel internal limit TASK_COMM_LEN in userspace too
We already use it at two places, and we are about to add one too.
Arbitrary literally hardcoded limits suck.
2018-06-01 21:49:16 +02:00
Lennart Poettering 89544ae658
Merge pull request #9014 from keszybz/fuzz-journal-remote
A fuzzer for journal-remote
2018-05-31 15:33:44 +02:00
Zbigniew Jędrzejewski-Szmek 4d9685be5f Use const char* for timestamp strings which we don't plan to modify
Makes the intent a bit clearer.
2018-05-31 14:30:23 +02:00
Zbigniew Jędrzejewski-Szmek d3d280242c Always allow timestamps to be printed
If the timestamp is above 9999-12-30, (or 2038-something-something on 32 bit),
use XXXX-XX-XX XX:XX:XX as the replacement.

The problem with refusing to print timestamps is that our code accepts such
timestamps, so we can't really just refuse to process them afterwards. Also, it
makes journal files non-portable, because suddently we might completely refuse
to print entries which are totally OK on a different machine.
2018-05-31 14:30:23 +02:00
Zbigniew Jędrzejewski-Szmek 8409f68858 basic/string-util: add a convenience function to cescape mostly-ascii fields
It's not supposed to be the most efficient, but instead fast and simple to use.

I kept the logic in ellipsize_mem() to use unicode ellipsis even in non-unicode
locales. I'm not quite convinced things should be this way, especially that with
this patch it'd actually be simpler to always use "…" in unicode locale and "..."
otherwise, but Lennart wanted it this way for some reason.
2018-05-31 14:27:07 +02:00
Lennart Poettering 2f0726c08f coccinelle says we should use EOPNOTSUPP rather than ENOTSUP 2018-05-31 12:06:54 +02:00
Lennart Poettering 9b8ff18319 string-util: add new memory_startswith() helper
We have code like this at various placer, let's make things shorter and
more readable with a helper for it.
2018-05-30 13:07:40 +02:00
Zbigniew Jędrzejewski-Szmek 018eaf7445 test-tables,test-network-tables: add a few more tests 2018-05-28 10:40:00 +02:00
Zbigniew Jędrzejewski-Szmek 279eadd933 test-tables*: sort 2018-05-28 10:32:52 +02:00
Lennart Poettering 3e36211be0 conf-files: beef up conf-files.[ch] a bit
This adds fozr new flags:

- If CONF_FILES_DIRECTORY is specified conf_file_list() and friends
  will look for directories only.

- Similar CONF_FILES_REGULAR means we'll look only for regular files.

- If CONF_FILES_BASENAME is specified the resulting list will contain
  only the basenames of all discovered files or directories, not the
  full paths.

- If CONF_FILES_FILTER_MASKED is specified the resulting list will have
  masked entries removed (i.e. those symlinked to /dev/null and
  suchlike)

These four flags are useful for discovering portable service profile
information.

While we are at it, also improve a couple of other things:

- More debug logging

- use path_hash_ops instead of string_hash_ops when putting together the
  path lists
2018-05-24 17:01:57 +02:00
Lennart Poettering d58ad743f9 os-util: add helpers for finding /etc/os-release
Place this new helpers in a new source file os-util.[ch], and move the
existing and related call path_is_os_tree() to it as well.
2018-05-24 17:01:57 +02:00
Lennart Poettering 1a5a177eaf fileio: accept FILE* in addition to path in parse_env_file()
Most our other parsing functions do this, let's do this here too,
internally we accept that anyway. Also, the closely related
load_env_file() and load_env_file_pairs() also do this, so let's be
systematic.
2018-05-24 17:01:57 +02:00
Lennart Poettering 4960ce43ff fd-util: add new helper call fd_duplicate_data_fd()
This call creates an fd from another fd containing the same data.
Specifically, repeated read() on the returned fd should return the same
data as the original fd. This call is useful when we want to copy data
out of disk images and suchlike, and want to be pass fds with the data
around without having to keep the disk image continously mounted.

The implementation tries to be somewhat smart and tries to prefer
memfds/pipes over files in /tmp or /var/tmp based on the size of the
data, but has appropropriate fallbacks in place.
2018-05-24 17:01:57 +02:00
Lennart Poettering cdc0f9be92
Merge pull request #8817 from yuwata/cleanup-nsflags
core: allow to specify RestrictNamespaces= multiple times
2018-05-24 16:49:13 +02:00
Zbigniew Jędrzejewski-Szmek 994282d2de test-sizeof: show that a small 64 field is not enough to force the enum to be 64 bits
On both 32 and 64 bits, the result is:
enum Enum → 32 bits, unsigned
enum BigEnum → 32 bits, unsigned
enum BigEnum2 → 64 bits, unsigned
big_enum2_pos → 4
big_enum2_neg → 8

The last two lines show that even if the enum is 64 bit, and the field of an
enum is defined with UINT64_C(), the field can still be smaller.
2018-05-22 10:09:07 +02:00
Lennart Poettering 6f8fa29465
Merge pull request #8981 from keszybz/ratelimit-and-dbus
Ratelimit renaming and dbus error message fix
2018-05-18 21:38:30 +02:00
Lennart Poettering c385b10a13
Merge pull request #8993 from keszybz/sd-resolve-coverity-and-related-fixes
sd-resolve coverity and related fixes
2018-05-18 20:30:12 +02:00
Zbigniew Jędrzejewski-Szmek 627d2bac24 fs-util,test: add helper to remove tempfiles
This simplifies the use of tempfiles in tests and fixes "leaked"
temporary files in test-fileio, test-catalog, test-conf-parser.

Not the whole tree is converted.
2018-05-18 20:11:31 +02:00
Lennart Poettering 4f424df760 core: move config_parse_limit() to the generic conf-parser.[ch]
That way we can use it in nspawn.

Also, while we are at it, let's rename the call config_parse_rlimit(),
i.e. insert the "r", to clarify what kind of limit this is about.
2018-05-17 20:36:52 +02:00
Lennart Poettering 6550c24c7f rlimit-util: rework rlimit_{from|to}_string() to work without "Limit" prefix
let's make the call more generic, so that we can also easily use it for
parsing "RLIMIT_xyz" style constants.
2018-05-17 20:36:52 +02:00
Felipe Sateler 57b7a260c2 core: undo the dependency inversion between unit.h and all unit types 2018-05-15 14:24:34 -04:00
Zbigniew Jędrzejewski-Szmek 9421cab6db test-copy: remove unnecessary initialization
Initializing just some of the values doesn't make sense. We should handle them
all in the same way. In those tests there are no jumps, all steps are covered
with assert_se(), so we know everything will be set if we get to the end of the
function. And _not_ initializing those variables has the advantage that it
allows valgrind to catch potential initalization errors in the function being
tested.
2018-05-14 17:22:22 +02:00
Zbigniew Jędrzejewski-Szmek dcd6361ea1 tree-wide: do not wrap assert_se in extra parentheses
We were inconsitently using them in some cases, but in majority not.
Using assignment in assert_se is very common, not an exception like in
'if', so let's drop the extra parens everywhere.
2018-05-14 17:22:22 +02:00
Yu Watanabe 3ecdd18f87 test: use _cleanup_hashmap_free_ instread of _cleanup_(hashmap_freep) 2018-05-14 14:14:17 +09:00
Zbigniew Jędrzejewski-Szmek 7994ac1d85 Rename ratelimit_test to ratelimit_below
When I see "test", I have to think three times what the return value
means. With "below" this is immediately clear. ratelimit_below(&limit)
sounds almost like English and is imho immediately obvious.

(I also considered ratelimit_ok, but this strongly implies that being under the
limit is somehow better. Most of the times this is true, but then we use the
ratelimit to detect triple-c-a-d, and "ok" doesn't fit so well there.)

C.f. a1bcaa07.
2018-05-13 22:08:30 +02:00
Yu Watanabe b4152e9be1 test: add tests for unit_name_from_dbus_path() 2018-05-13 18:44:25 +02:00
Zbigniew Jędrzejewski-Szmek 88136bbc98
Merge pull request #8962 from floppym/issue8905
basic: timezone_is_valid: check for magic bytes "TZif"
2018-05-13 18:43:11 +02:00
Mike Gilbert 089fb8653f basic: add log_level argument to timezone_is_valid 2018-05-12 15:20:13 -04:00
Zbigniew Jędrzejewski-Szmek 2407ed7b63
Merge pull request #8924 from yuwata/fix-3682
resolve: allow whitespaces in the digest
2018-05-11 11:48:05 +02:00
Lennart Poettering cb91deaf77 terminal-util: add a function that shows a pretty separator line
Follow-up for #8824
2018-05-11 08:15:33 +02:00
Yu Watanabe 2d2c21afb2 test: do not call alloca() inside the list of arguments 2018-05-11 15:01:35 +09:00