chiark / gitweb /
elogind.git
5 years agomeson: drop 'name' argument in cc.has_argument() (#8823)
Yu Watanabe [Thu, 26 Apr 2018 08:53:10 +0000 (17:53 +0900)]
meson: drop 'name' argument in cc.has_argument() (#8823)

This fixes the following warning with clang and meson-0.46.0,
```
WARNING: Passed invalid keyword argument "name".
WARNING: This will become a hard error in the future.
WARNING: Passed invalid keyword argument "name".
WARNING: This will become a hard error in the future.
Compiler for C supports arguments -Wno-typedef-redefinition: YES
WARNING: Passed invalid keyword argument "name".
WARNING: This will become a hard error in the future.
WARNING: Passed invalid keyword argument "name".
WARNING: This will become a hard error in the future.
Compiler for C supports arguments -Wno-gnu-variable-sized-type-not-at-end: YES
```

5 years agoman: fix description of --value option for loginctl (#8820)
Yu Watanabe [Thu, 26 Apr 2018 07:51:11 +0000 (16:51 +0900)]
man: fix description of --value option for loginctl (#8820)

5 years agomeson: do not link libsystemd_static into libcore (#8813)
Zbigniew Jędrzejewski-Szmek [Wed, 25 Apr 2018 11:47:18 +0000 (13:47 +0200)]
meson: do not link libsystemd_static into libcore (#8813)

(or in terms of the names of the actual files on disk, do not link
libsystemd-shared-238.a into libcore.a).

libsystemd_static is linked into libsystemd_shared, which in turn means that
anything that links to libcore and libsystemd_shared will get libsystemd_static
twice:

$ cc -o systemd 'systemd@exe/src_core_main.c.o' -Wl,--no-undefined -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -pie -DVALGRIND -Wl,--start-group src/core/libcore.a src/shared/libsystemd-shared-238.a src/shared/libsystemd-shared-238.so -pthread -lrt -lseccomp -lselinux -lmount -lblkid -Wl,--end-group -lseccomp -lpam -L/lib64 -laudit -lkmod -lmount -lrt -lcap -lacl -lcryptsetup -lgcrypt -lip4tc -lip6tc -lseccomp -lselinux -lidn -llzma -llz4 -lblkid '-Wl,-rpath,$ORIGIN/src/shared' -Wl,-rpath-link,/home/zbyszek/src/systemd/build/src/shared

This propagation of the dependency seems correct (in the sense that meson is
doing the expected thing based on the given configuration). Linking was done
this way in the original meson conversion. I was probably trying to get
everything to compile and link, I'm not sure why this particular choice was
made. In the meantime, meson has gotten better at propagating dependencies, so
it's possible that this had slightly different effect in the original
conversion, but I did not verify this. Either way, I think we should drop this.

With the patch:
$ cc -o systemd 'systemd@exe/src_core_main.c.o' -Wl,--no-undefined -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -pie -DVALGRIND -Wl,--start-group src/core/libcore.a src/shared/libsystemd-shared-238.so -pthread -lrt -lseccomp -lselinux -lmount -Wl,--end-group -lblkid -lrt -lseccomp -lpam -L/lib64 -laudit -lkmod -lselinux -lmount '-Wl,-rpath,$ORIGIN/src/shared' -Wl,-rpath-link,/home/zbyszek/src/systemd/build/src/shared

This is more correct because we're not linking the same code twice.
With the patch, libystemd_static is used in exactly four places:
- src/shared/libsystemd-shared-238.so
- src/udev/libudev.so.1.6.10
- pam_systemd.so
- test-bus-error
(compared to a bunch more executables before, including systemd,
systemd-analyze, test-hostname, test-ns, etc.)

Size savings are also noticable:

$ size /var/tmp/inst?/usr/lib/systemd/libsystemd-shared-238.so
   text    data     bss     dec     hex filename
2397826  578488   15920 2992234  2da86a /var/tmp/inst1/usr/lib/systemd/libsystemd-shared-238.so
2397826  578488   15920 2992234  2da86a /var/tmp/inst2/usr/lib/systemd/libsystemd-shared-238.so

$ size /var/tmp/inst?/usr/lib/systemd/systemd
   text    data     bss     dec     hex filename
1858790  261688    9320 2129798  207f86 /var/tmp/inst1/usr/lib/systemd/systemd
1556358  258704    8072 1823134  1bd19e /var/tmp/inst2/usr/lib/systemd/systemd

$ du -s /var/tmp/inst?
52216 /var/tmp/inst1
50844 /var/tmp/inst2

https://github.com/google/oss-fuzz/issues/1330#issuecomment-384054530 might be related.

5 years agotree-wide: drop redundant _cleanup_ macros (#8810)
Lennart Poettering [Wed, 25 Apr 2018 10:31:45 +0000 (12:31 +0200)]
tree-wide: drop redundant _cleanup_ macros (#8810)

This drops a good number of type-specific _cleanup_ macros, and patches
all users to just use the generic ones.

In most recent code we abstained from defining type-specific macros, and
this basically removes all those added already, with the exception of
the really low-level ones.

Having explicit macros for this is not too useful, as the expression
without the extra macro is generally just 2ch wider. We should generally
emphesize generic code, unless there are really good reasons for
specific code, hence let's follow this in this case too.

Note that _cleanup_free_ and similar really low-level, libc'ish, Linux
API'ish macros continue to be defined, only the really high-level OO
ones are dropped. From now on this should really be the rule: for really
low-level stuff, such as memory allocation, fd handling and so one, go
ahead and define explicit per-type macros, but for high-level, specific
program code, just use the generic _cleanup_() macro directly, in order
to keep things simple and as readable as possible for the uninitiated.

Note that before this patch some of the APIs (notable libudev ones) were
already used with the high-level macros at some places and with the
generic _cleanup_ macro at others. With this patch we hence unify on the
latter.

5 years agofileio.c: fix incorrect mtime
Chris Lesiak [Tue, 24 Apr 2018 14:50:42 +0000 (09:50 -0500)]
fileio.c: fix incorrect mtime

A regression was introduced that caused the mtime of /etc/.updated
and /var/.updated to be the current time when systemd-update-done
ran instead of being copied from /usr.

This was nearly fixed, but due to fflush being called after mtime
was carefully set, it was overwritten with the current time.

Regression introduced in 872c40396384f9fa89b01baf4e739d28ed590299

A fix was just missed in 39c38d773fbe2b4f76ff29ecd3344640efb9a86c

Fixes #8806

5 years agoupdate TODO
Lennart Poettering [Fri, 20 Apr 2018 13:22:02 +0000 (15:22 +0200)]
update TODO

5 years agostring-util: use fflush_and_check() where appropriate
Lennart Poettering [Fri, 20 Apr 2018 13:22:29 +0000 (15:22 +0200)]
string-util: use fflush_and_check() where appropriate

5 years agostring-util: teach strip_tab_ansi() to deal with CSO sequences
Lennart Poettering [Fri, 20 Apr 2018 13:16:13 +0000 (15:16 +0200)]
string-util: teach strip_tab_ansi() to deal with CSO sequences

With the recent terminal_urlify() APIs we'll now sometimes generate
clickable link CSO sequences. Hence we should also be able to remove
them again from strings. This beefs up the logic to do so.

Follow-up for: 23b27b39d2a3a002ad827a2e8a9872a51495d797

5 years agobasic/log: do not use global errno in log_*_errno()
Zbigniew Jędrzejewski-Szmek [Tue, 24 Apr 2018 11:57:38 +0000 (13:57 +0200)]
basic/log: do not use global errno in log_*_errno()

Quoting https://github.com/systemd/systemd/pull/8760#discussion_r183321060:

> When we originally added the errno patching we went for a "best of both
> worlds" approach, i.e. that we override errno if an error is specified, but
> if no error is specified (i.e. 0 is passed as error code) then we use the
> previously set errno, similar in style how plain `printf()` would do it. In
> retrospect I think we almost never purposefully made use of the second,
> i.e. the plain `printf()` logic, but we multiple times ran into this case
> accidentally and introduced a bug. Hence yes, it probably makes sense to
> switch this over, and consistently ignore the `errno` already set and always
> override it with the error passed in. The only problem I see with that is: I
> wonder if there might be a case or two lurking somewhere where we actually
> made use of the "best of both worlds" approach, and if so, if we can detect
> where... (But then again, even if there is, and we fail to find those cases,
> maybe that's not all bad, as it's just a few new bugs against probably fixing
> many more old and future bugs, if you follow what I mean).

I scanned our codebase, and found some bugs in the value passed to log_*_errno,
but no intentional cases of error=0 being passed.

5 years agobasic/audit-util: always log the reason when disabling audit logs
Zbigniew Jędrzejewski-Szmek [Tue, 24 Apr 2018 11:46:58 +0000 (13:46 +0200)]
basic/audit-util: always log the reason when disabling audit logs

This state is cached, and it's seems OK to log at least once.

5 years agotree-wide: avoid assignment of r just to use in a comparison
Zbigniew Jędrzejewski-Szmek [Tue, 24 Apr 2018 11:44:09 +0000 (13:44 +0200)]
tree-wide: avoid assignment of r just to use in a comparison

This changes
  r = ...;
  if (r < 0)
to
  if (... < 0)
when r will not be used again.

5 years agofs-util: introduce fchmod_opath()
Franck Bui [Wed, 11 Apr 2018 14:58:49 +0000 (16:58 +0200)]
fs-util: introduce fchmod_opath()

fchmod(2) still doesn't take file descriptors opened with O_PATH.

5 years agotest: drop unused variables
Yu Watanabe [Tue, 24 Apr 2018 06:43:09 +0000 (15:43 +0900)]
test: drop unused variables

Follow-up for 49eb36596b72e568d4b9b785cd4544e58c89bdee.

5 years agologin: drop an unused variable
Yu Watanabe [Tue, 24 Apr 2018 06:42:00 +0000 (15:42 +0900)]
login: drop an unused variable

Follow-up for 99f1229d76da4b805f8f6c6e5e4a878d17d42f93.

5 years agobus-message: use streq_ptr() (#8786)
Yu Watanabe [Mon, 23 Apr 2018 08:13:26 +0000 (17:13 +0900)]
bus-message: use streq_ptr() (#8786)

5 years agoFix typo
Zbigniew Jędrzejewski-Szmek [Fri, 20 Apr 2018 09:09:44 +0000 (11:09 +0200)]
Fix typo

5 years agoupdate TODO
Lennart Poettering [Fri, 20 Apr 2018 16:09:53 +0000 (18:09 +0200)]
update TODO

5 years agonspawn: when running nspawn, set a $PATH including both bin + sbin by default (#8756)
Lennart Poettering [Fri, 20 Apr 2018 09:36:25 +0000 (11:36 +0200)]
nspawn: when running nspawn, set a $PATH including both bin + sbin by default (#8756)

We don't know what the container payload needs, hence default to a PATH
with both bin and sbin included, as well as / and /usr.

Follow-up for #8324

Fixes: #8698
5 years agoterminal: add internal API to format URLs for display in capable terminals
Lennart Poettering [Thu, 19 Apr 2018 15:48:53 +0000 (17:48 +0200)]
terminal: add internal API to format URLs for display in capable terminals

Newer terminals (in particular gnome-terminal) understand special escape
sequence for formatting clickable links. Let's support that to make our
tool output more clickable where that's appropriate.

For details see this:

https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda

The one big issue is that 'less' currently doesn't grok this, and
doesn't ignore sequence like regular terminal implementations do if they
don't support it. Hence for now, let's disable URL output if a pager is
used. We should revisit that though as soon as less added support for it
and enough time passed for it to enter various distributions.

5 years agotimedate: move error mapping to bus-common-errors.[ch]
Yu Watanabe [Tue, 17 Apr 2018 05:03:25 +0000 (14:03 +0900)]
timedate: move error mapping to bus-common-errors.[ch]

5 years agouser-util: trivial coding style fixes
Lennart Poettering [Thu, 19 Apr 2018 09:40:48 +0000 (11:40 +0200)]
user-util: trivial coding style fixes

Use C's downgrade-to-bool feature when comparing pointers against NULL,
as we usually do.

5 years agobash-completion: add completion for resolvectl
Yu Watanabe [Wed, 18 Apr 2018 18:26:54 +0000 (03:26 +0900)]
bash-completion: add completion for resolvectl

5 years agoman: create man page for resolvectl
Yu Watanabe [Wed, 18 Apr 2018 18:25:25 +0000 (03:25 +0900)]
man: create man page for resolvectl

5 years agoresolvectl: rename systemd-resolve to resolvectl
Yu Watanabe [Wed, 18 Apr 2018 18:24:23 +0000 (03:24 +0900)]
resolvectl: rename systemd-resolve to resolvectl

For the compatibility, `systemd-resolve` will be created as a symbolic
link to `resolvectl`.

5 years agotree-wide: drop spurious newlines (#8764)
Lennart Poettering [Thu, 19 Apr 2018 10:13:23 +0000 (12:13 +0200)]
tree-wide: drop spurious newlines (#8764)

Double newlines (i.e. one empty lines) are great to structure code. But
let's avoid triple newlines (i.e. two empty lines), quadruple newlines,
quintuple newlines, …, that's just spurious whitespace.

It's an easy way to drop 121 lines of code, and keeps the coding style
of our sources a bit tigther.

5 years agofs-util: export how many iterations chase_symlinks() executes at max
Lennart Poettering [Wed, 4 Apr 2018 15:06:12 +0000 (17:06 +0200)]
fs-util: export how many iterations chase_symlinks() executes at max

5 years agofs-util: add new CHASE_STEP flag to chase_symlinks()
Lennart Poettering [Wed, 4 Apr 2018 15:03:45 +0000 (17:03 +0200)]
fs-util: add new CHASE_STEP flag to chase_symlinks()

If the flag is set only a single step of the normalization is executed,
and the resulting path is returned.

This allows callers to normalize piecemeal, taking into account every
single intermediary path of the normalization.

5 years agosysusers: make sure to reset the returned value when EOF is reached in fget*ent_sane...
Franck Bui [Wed, 18 Apr 2018 16:32:21 +0000 (18:32 +0200)]
sysusers: make sure to reset the returned value when EOF is reached in fget*ent_sane() wrappers (#8737)

To indicate that the there're no more entries, these wrappers return false but
did leave the passed pointed unmodified.

However EOF is not an error and is a very common case so initialize the output
argument to NULL even in this case so callers don't need to do that.

Fixes: #8721
5 years agoupdate TODO
Lennart Poettering [Wed, 18 Apr 2018 10:42:22 +0000 (12:42 +0200)]
update TODO

5 years agotest-locale-util: show special glyphs
Zbigniew Jędrzejewski-Szmek [Wed, 18 Apr 2018 08:53:25 +0000 (10:53 +0200)]
test-locale-util: show special glyphs

This is mostly useful as a sanity check.

5 years agotest-utf8: add a smoke test for utf8_console_width()
Zbigniew Jędrzejewski-Szmek [Wed, 18 Apr 2018 08:57:01 +0000 (10:57 +0200)]
test-utf8: add a smoke test for utf8_console_width()

5 years agologinctl: port loginctl to format-table.[ch]
Lennart Poettering [Wed, 11 Apr 2018 19:37:38 +0000 (21:37 +0200)]
loginctl: port loginctl to format-table.[ch]

5 years agobasic: add minimalistic table formatter
Lennart Poettering [Wed, 11 Apr 2018 18:03:39 +0000 (20:03 +0200)]
basic: add minimalistic table formatter

We have plenty of code in our codebase that outputs tables to the
console, and all is homegrown and awful. Let's replace it with a generic
implementation that can do automatically what the old implementations
did manually.

Features:

1. Ellipsation (for fields overly long) and alignment (for
   fields overly short)

2. Sorting of rows

3. automatically copies formatting from the same cell in the row above

4. Heavy use of varargs to make putting together tables easy

5. can expand and compress tables, with weights

6. Has a minimal understanding of unicode wide characters in order to
   match unicode strings to character cell terminals.

7. Columns can be reordered and individually turned off.

8. pretty printing for various data types

And more.

5 years agopager: move pager.[ch] src/shared/ → src/basic/
Lennart Poettering [Wed, 11 Apr 2018 17:57:56 +0000 (19:57 +0200)]
pager: move pager.[ch] src/shared/ → src/basic/

pager.[ch] doesn't use any APIs from src/libsystemd/ or src/shared/
hence there's no reason for it to be in src/shared/, let's move it to
src/basic/ instead.

This enables us to use pager.[ch] APIs from other code in src/basic/,
for example pager_have() and suchlike.

5 years agostring-util: tweak ellipsation a bit
Lennart Poettering [Wed, 11 Apr 2018 17:52:25 +0000 (19:52 +0200)]
string-util: tweak ellipsation a bit

This primarily changes to things:

1. Ellipsation to 0, 1 or 2 characters is now supported. Previously we'd
   hit an assert if the new lengths was < 3, this is now permitted. The
   result strings won't show too much info still of course, but the code
   becomes a bit more generic and robust to use.

2. If a UTF-8 mode is disabled and the input string is pure ASCII, then
   "..." is used for ellipsation, otherwise (as before) "…". This means
   on a pure-ASCII system we should remain pure-ASCII, matching
   behaviour otherwise exposed with special_glyph() and friends. Note
   that we'll use "…" for ellipsiation as soon as either the locale
   settings indicate an UTF-8 mode or the input string already contains
   non-ASCII unicode characters.

Testing for these special cases is improved.

5 years agoutil: add qsort_r_safe(), similar to qsort_safe()
Lennart Poettering [Wed, 11 Apr 2018 17:51:39 +0000 (19:51 +0200)]
util: add qsort_r_safe(), similar to qsort_safe()

5 years agoutf8: add helper call for counting display width of strings
Lennart Poettering [Wed, 11 Apr 2018 17:50:53 +0000 (19:50 +0200)]
utf8: add helper call for counting display width of strings

5 years agolocale: add ellipsis as special glyph
Lennart Poettering [Wed, 11 Apr 2018 17:49:50 +0000 (19:49 +0200)]
locale: add ellipsis as special glyph

5 years agopath-lookup: properly chase paths when reducing with root dir (#8750)
Lennart Poettering [Wed, 18 Apr 2018 14:19:46 +0000 (16:19 +0200)]
path-lookup: properly chase paths when reducing with root dir (#8750)

Let's make this correct.

5 years agoutil-lib: introduce new empty_or_root() helper (#8746)
Lennart Poettering [Wed, 18 Apr 2018 12:20:49 +0000 (14:20 +0200)]
util-lib: introduce new empty_or_root() helper (#8746)

We check the same condition at various places. Let's add a trivial,
common helper for this, and use it everywhere.

It's not going to make things much faster or much shorter, but I think a
lot more readable

5 years agoman: add a new page with a general description of common syntax
Zbigniew Jędrzejewski-Szmek [Mon, 16 Apr 2018 15:09:58 +0000 (17:09 +0200)]
man: add a new page with a general description of common syntax

We have a common parser, but for the user it might be
completely unobvious that the same general rules apply
to all those files. Let's add a page about the basic syntax
so that the more specific pages don't have to repeat those
details.

5 years agomeson: fix indentation for systemd-time-sync-wait(5) entries
Zbigniew Jędrzejewski-Szmek [Mon, 16 Apr 2018 15:08:21 +0000 (17:08 +0200)]
meson: fix indentation for systemd-time-sync-wait(5) entries

Those files should not be updated manually, because then automatic updates
contain spurious "changes".

5 years agopolkit: normalize exit values of polkit_agent_open_if_enabled()
Lennart Poettering [Mon, 16 Apr 2018 19:37:12 +0000 (21:37 +0200)]
polkit: normalize exit values of polkit_agent_open_if_enabled()

It's strange eating up the errors here, hence don't. Let's leave this
to the caller.

5 years agopath-util: Finish DEFAULT_PATH_NULSTR with an extra NUL (#8745)
Filipe Brandenburger [Wed, 18 Apr 2018 05:46:03 +0000 (22:46 -0700)]
path-util: Finish DEFAULT_PATH_NULSTR with an extra NUL (#8745)

The NULSTR_FOREACH iterator needs to see an empty string at the end, so
we need to insert an extra NUL explicitly.

Also update PATH0_BIN_SBIN(x) to include an extra NUL terminator, rename
it to PATH_BIN_SBIN_NULSTR(x), which is more consistent with the similar
CONF_PATHS_NULSTR(x) macro.

Fixes: 5008da1ec1cf2cf8c15b702c4052e3a49583095d
5 years agobus-util: introduce bus_open_system_watch_bind_with_description()
Yu Watanabe [Tue, 17 Apr 2018 14:37:52 +0000 (23:37 +0900)]
bus-util: introduce bus_open_system_watch_bind_with_description()

Similar to 56fbd7187a5af44a90c258fbeb1f17114f226bb3, this adds
bus_open_system_watch_bind_with_description() to set description
for busses.

5 years agobasic/copy: fix awkward sentence
Zbigniew Jędrzejewski-Szmek [Fri, 13 Apr 2018 10:40:11 +0000 (12:40 +0200)]
basic/copy: fix awkward sentence

5 years agobasic/unit-name: remove duplicate check
Zbigniew Jędrzejewski-Szmek [Fri, 13 Apr 2018 10:38:11 +0000 (12:38 +0200)]
basic/unit-name: remove duplicate check

The check that was right below already covers this case.

5 years agologind: enable limiting of user session scopes using pam context objects (#8397)
Jan Synacek [Tue, 17 Apr 2018 14:42:44 +0000 (16:42 +0200)]
logind: enable limiting of user session scopes using pam context objects (#8397)

5 years agotest-execute: make find invocation a bit more efficent, increase timeout
Zbigniew Jędrzejewski-Szmek [Wed, 11 Apr 2018 14:50:48 +0000 (16:50 +0200)]
test-execute: make find invocation a bit more efficent, increase timeout

We go through the whole file system, so this test can take arbitrary time.  But
this test is still quite useful, so let's at least try to make it more efficent
by not descending at all into the directories we would filter out later on
anyway.

Also increase the timeout, in case the previous step doesn't help enough.

5 years agosystemd: do not require absolute paths in ExecStart
Zbigniew Jędrzejewski-Szmek [Sun, 25 Mar 2018 18:50:15 +0000 (20:50 +0200)]
systemd: do not require absolute paths in ExecStart

Absolute paths make everything simple and quick, but sometimes this requirement
can be annoying. A good example is calling 'test', which will be located in
/usr/bin/ or /bin depending on the distro. The need the provide the full path
makes it harder a portable unit file in such cases.

This patch uses a fixed search path (DEFAULT_PATH which was already used as the
default value of $PATH), and if a non-absolute file name is found, it is
immediately resolved to a full path using this search path when the unit is
loaded. After that, everything behaves as if an absolute path was specified. In
particular, the executable must exist when the unit is loaded.

5 years agotime-wait-sync: use watchfile to coordinate with timesyncd
Peter A. Bigot [Mon, 9 Apr 2018 18:39:16 +0000 (13:39 -0500)]
time-wait-sync: use watchfile to coordinate with timesyncd

Systems that have an accurate real-time clock may have an initial
unsynchronized time that is close enough to the synchronized time that
the final adjustment doesn't trigger a waking "clock set" event.  Have
timesyncd touch a file in its runtime directory as a secondary signal
for synchronization.  Continue to support the timerfd-based trigger as a
sufficient condition when the watchfile is not present.

Closes issue #8683

5 years agounit-name: add new unit_name_build_from_type() helper
Lennart Poettering [Thu, 22 Feb 2018 17:24:57 +0000 (18:24 +0100)]
unit-name: add new unit_name_build_from_type() helper

The new helper is much like unit_name_build() but expects a UnitType
value instead of a suffix.

5 years agocopy: rearrange flags field definition
Lennart Poettering [Fri, 23 Mar 2018 17:27:31 +0000 (18:27 +0100)]
copy: rearrange flags field definition

Let's use the usual 1U << 0,1,2,3,4 spelling for definiting flags enums.

5 years agocopy: reduce number of checks
Lennart Poettering [Fri, 23 Mar 2018 17:26:58 +0000 (18:26 +0100)]
copy: reduce number of checks

We check max_bytes twice here, let's simplify that, and reduce one level
of indentation.

5 years agocopy: drop _unlikely_() that isn't obviously the case
Lennart Poettering [Fri, 23 Mar 2018 17:24:07 +0000 (18:24 +0100)]
copy: drop _unlikely_() that isn't obviously the case

If a tool only invokes copy_bytes() a single time the _unlikely_() will always be
wrong, and is hence not useful. Let's drop it and let the compiler
figure our what to do, instead of misleading it.

Also, some coding style imprvoements.

5 years agocopy: hide in copy_bytes() the strange way splice() handles O_NONBLOCK
Lennart Poettering [Fri, 23 Mar 2018 16:44:15 +0000 (17:44 +0100)]
copy: hide in copy_bytes() the strange way splice() handles O_NONBLOCK

splice() ignores O_NONBLOCK on pipes but not on other fds. Let's handle
that properly, and query O_ONBLOCK manually in that case, ensuring
systematic behaviour in either case.

5 years agocopy: extend copy_bytes() a bit
Lennart Poettering [Fri, 23 Mar 2018 15:41:42 +0000 (16:41 +0100)]
copy: extend copy_bytes() a bit

Optionally, when we copy between fds with simple read/write, let's
return any remaining data we already read into the buffer if write
fails. This is useful to allow callers to use the read data otherwise,
perhaps implementing a different fallback for copying.

5 years agocopy: tweak reflink logic in copy_bytes() a bit
Lennart Poettering [Fri, 23 Mar 2018 15:36:56 +0000 (16:36 +0100)]
copy: tweak reflink logic in copy_bytes() a bit

Let's use btrfs_clone_range() if partial copies are desired. And use
btrfs_reflink() only for full-file reflinks.

5 years agocopy: add brief comment to copy_bytes() explaining its return values
Lennart Poettering [Fri, 9 Mar 2018 21:44:47 +0000 (22:44 +0100)]
copy: add brief comment to copy_bytes() explaining its return values

5 years agomacro: don't rely on C's downgrade-to-bool feature for numeric comparisons
Lennart Poettering [Wed, 11 Apr 2018 19:36:52 +0000 (21:36 +0200)]
macro: don't rely on C's downgrade-to-bool feature for numeric comparisons

5 years agoupdate TODO
Lennart Poettering [Fri, 6 Apr 2018 16:57:48 +0000 (18:57 +0200)]
update TODO

5 years agopath-util: document a few other special cases for last_path_component()
Lennart Poettering [Thu, 5 Apr 2018 16:00:39 +0000 (18:00 +0200)]
path-util: document a few other special cases for last_path_component()

5 years agoprocess-util: add TAKE_PID(), similar to TAKE_PTR/TAKE_FD, but for child process...
Lennart Poettering [Tue, 27 Mar 2018 13:01:02 +0000 (15:01 +0200)]
process-util: add TAKE_PID(), similar to TAKE_PTR/TAKE_FD, but for child process PIDs

5 years agoutil: introduce typesafe_qsort(), a typesafe version of qsort()/qsort_safe()
Lennart Poettering [Tue, 27 Mar 2018 12:56:29 +0000 (14:56 +0200)]
util: introduce typesafe_qsort(), a typesafe version of qsort()/qsort_safe()

It does two things:

1. It derives the element size from the array argument type

2. It derives the right type for the function from the array argument
   type

Using this macro call should make the invocations of qsort() quite a bit
safer.

5 years agoshared/sleep-config: rename misnamed function
Zbigniew Jędrzejewski-Szmek [Wed, 11 Apr 2018 07:27:32 +0000 (09:27 +0200)]
shared/sleep-config: rename misnamed function

5 years agoshared/sleep-config: return a custom message when not enough swap for hibernation
Zbigniew Jędrzejewski-Szmek [Wed, 11 Apr 2018 06:51:06 +0000 (08:51 +0200)]
shared/sleep-config: return a custom message when not enough swap for hibernation

$ sudo swapoff -av
swapoff /dev/vda4
$ sudo systemctl hibernate
Failed to hibernate system via logind: Not enough swap space for hibernation

Fixes #6729.

5 years agologind: refuse operations if the target unit is masked or unavailable
Zbigniew Jędrzejewski-Szmek [Tue, 10 Apr 2018 11:15:00 +0000 (13:15 +0200)]
logind: refuse operations if the target unit is masked or unavailable

If hibernate.target is masked, and systemctl hibernate is invoked, havoc ensues.
logind starts the hibernation operation, but then doesn't go through with it;
gnome-shell segfaults. Let's be nice to the user and refuse doing anything in
that case.

$ sudo systemctl mask hibernate.target
$ busctl call org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager CanHibernate
s "no"
$ sudo systemctl hibernate
Failed to hibernate system via logind: Access denied
Failed to start hibernate.target: Unit hibernate.target is masked.

https://bugzilla.redhat.com/show_bug.cgi?id=1468003#c4

5 years agoshared/sleep-fix: fix check if s-then-h is possible
Zbigniew Jędrzejewski-Szmek [Tue, 10 Apr 2018 09:39:14 +0000 (11:39 +0200)]
shared/sleep-fix: fix check if s-then-h is possible

can_sleep() returns 0 if the operation is impossible, but
the code assumed that negative is returned in that case,
in effect reporting s2h was possible even if hibernation or
suspend were not possible.

5 years agoshared/sleep-config: get rid of explicit allocation size calculation
Zbigniew Jędrzejewski-Szmek [Tue, 10 Apr 2018 09:23:46 +0000 (11:23 +0200)]
shared/sleep-config: get rid of explicit allocation size calculation

5 years agotree-wide: drop license boilerplate
Zbigniew Jędrzejewski-Szmek [Fri, 6 Apr 2018 16:58:55 +0000 (18:58 +0200)]
tree-wide: drop license boilerplate

Files which are installed as-is (any .service and other unit files, .conf
files, .policy files, etc), are left as is. My assumption is that SPDX
identifiers are not yet that well known, so it's better to retain the
extended header to avoid any doubt.

I also kept any copyright lines. We can probably remove them, but it'd nice to
obtain explicit acks from all involved authors before doing that.

5 years agoupdate TODO
Lennart Poettering [Thu, 5 Apr 2018 11:07:31 +0000 (13:07 +0200)]
update TODO

5 years agotmpfiles: add a new return code for "operational failure" when processing
Zbigniew Jędrzejewski-Szmek [Thu, 29 Mar 2018 14:19:33 +0000 (16:19 +0200)]
tmpfiles: add a new return code for "operational failure" when processing

Things can fail, and we have no control over it:
- file system issues (immutable bits, file system errors, MAC refusals, etc)
- kernel refusing certain arguments when writing to /proc/sys or /sys
Let's add a new code for the case where we parsed configuration but failed
to execute it because of external errors.

5 years agotree-wide: use TAKE_PTR() and TAKE_FD() macros
Yu Watanabe [Thu, 5 Apr 2018 05:26:26 +0000 (14:26 +0900)]
tree-wide: use TAKE_PTR() and TAKE_FD() macros

5 years agofs-util: add shortcut for chase_symlinks() when it is called like open(O_PATH)
Lennart Poettering [Mon, 26 Mar 2018 14:34:54 +0000 (16:34 +0200)]
fs-util: add shortcut for chase_symlinks() when it is called like open(O_PATH)

Let's optimize things, and let the kernel chase the paths if none of the
features chase_symlinks() offers are actually used.

5 years agofs-util: add calls that combine chase_symlinks() and open()/opendir() in one
Lennart Poettering [Mon, 26 Mar 2018 12:15:43 +0000 (14:15 +0200)]
fs-util: add calls that combine chase_symlinks() and open()/opendir() in one

This is useful when opening files within disk images, as we'll then take
the relative root directory properly into account.

5 years agofd-util: introduce fd_reopen() helper for reopening an fd
Lennart Poettering [Mon, 26 Mar 2018 11:25:51 +0000 (13:25 +0200)]
fd-util: introduce fd_reopen() helper for reopening an fd

We have the same code for this in place at various locations, let's
unify that. Also, let's repurpose test-fs-util.c as a test for this new
helper cal..

5 years agoupdate TODO
Lennart Poettering [Thu, 29 Mar 2018 15:47:03 +0000 (17:47 +0200)]
update TODO

5 years agosd-bus: allow description to be set for system/user busses (#8594)
Zbigniew Jędrzejewski-Szmek [Thu, 29 Mar 2018 14:14:11 +0000 (16:14 +0200)]
sd-bus: allow description to be set for system/user busses (#8594)

sd_bus_open/sd_bus_open_system/sd_bus_open_user are convenient, but
don't allow the description to be set. After they return, the bus is
is already started, and sd_bus_set_description() fails with -EBUSY.
It would be possible to allow sd_bus_set_description() to update the
description "live", but messages are already emitted from sd_bus_open
functions, so it's better to allow the description to be set in
sd_bus_open/sd_bus_open_system/sd_bus_open_user.

Fixes message like:
Bus n/a: changing state UNSET → OPENING

5 years agomeson_options.txt: Fix some trailing whitespaces in mask blocks.
Sven Eden [Fri, 29 Jun 2018 05:49:28 +0000 (07:49 +0200)]
meson_options.txt: Fix some trailing whitespaces in mask blocks.

5 years agosleep: Move the error level debugging for write_mode and write_state
Mario Limonciello [Thu, 29 Mar 2018 13:56:23 +0000 (08:56 -0500)]
sleep: Move the error level debugging for write_mode and write_state

This makes it more consistent with other code used in the file.

Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
5 years agosleep: Add support for setting a disk offset when hibernating
Mario Limonciello [Thu, 8 Mar 2018 08:41:50 +0000 (02:41 -0600)]
sleep: Add support for setting a disk offset when hibernating

The Linux kernel is adding support for configuring the offset
into a disk.  This allows swapfiles to be more usable as users
will no longer need to set the offset on their kernel command
line.

Use this API in systemd when hibernating as well.

Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
5 years agosd-event: use _cleanup_ to manage temporary references
Zbigniew Jędrzejewski-Szmek [Sat, 7 Apr 2018 17:14:37 +0000 (19:14 +0200)]
sd-event: use _cleanup_ to manage temporary references

5 years agoupdate TODO
Lennart Poettering [Thu, 5 Apr 2018 11:07:31 +0000 (13:07 +0200)]
update TODO

5 years agotmpfiles: add a new return code for "operational failure" when processing
Zbigniew Jędrzejewski-Szmek [Thu, 29 Mar 2018 14:19:33 +0000 (16:19 +0200)]
tmpfiles: add a new return code for "operational failure" when processing

Things can fail, and we have no control over it:
- file system issues (immutable bits, file system errors, MAC refusals, etc)
- kernel refusing certain arguments when writing to /proc/sys or /sys
Let's add a new code for the case where we parsed configuration but failed
to execute it because of external errors.

5 years agotree-wide: use TAKE_PTR() and TAKE_FD() macros
Yu Watanabe [Thu, 5 Apr 2018 05:26:26 +0000 (14:26 +0900)]
tree-wide: use TAKE_PTR() and TAKE_FD() macros

5 years agobus-util: fix a meaningless assertion
Yu Watanabe [Thu, 29 Mar 2018 12:20:30 +0000 (21:20 +0900)]
bus-util: fix a meaningless assertion

5 years agofs-util: add shortcut for chase_symlinks() when it is called like open(O_PATH)
Lennart Poettering [Mon, 26 Mar 2018 14:34:54 +0000 (16:34 +0200)]
fs-util: add shortcut for chase_symlinks() when it is called like open(O_PATH)

Let's optimize things, and let the kernel chase the paths if none of the
features chase_symlinks() offers are actually used.

5 years agofs-util: add calls that combine chase_symlinks() and open()/opendir() in one
Lennart Poettering [Mon, 26 Mar 2018 12:15:43 +0000 (14:15 +0200)]
fs-util: add calls that combine chase_symlinks() and open()/opendir() in one

This is useful when opening files within disk images, as we'll then take
the relative root directory properly into account.

5 years agofd-util: introduce fd_reopen() helper for reopening an fd
Lennart Poettering [Mon, 26 Mar 2018 11:25:51 +0000 (13:25 +0200)]
fd-util: introduce fd_reopen() helper for reopening an fd

We have the same code for this in place at various locations, let's
unify that. Also, let's repurpose test-fs-util.c as a test for this new
helper cal..

5 years agounits: use `systemctl exit` to kill the user manager (#8648)
Filipe Brandenburger [Wed, 4 Apr 2018 09:14:37 +0000 (02:14 -0700)]
units: use `systemctl exit` to kill the user manager (#8648)

Use `systemctl --user --force exit` to implement the systemd-exit
user service.

This removes our dependence on an external `kill` binary and the
concerns about whether they recognize SIGRTMIN+n by name or what their
interpretation of SIGRTMIN is.

Tested: `systemctl --user start systemd-exit.service` kills the
  `systemd --user` instance for my user.

5 years agooss-fuzz: Fallback to `ninja-build` when available (#8641)
Filipe Brandenburger [Wed, 4 Apr 2018 07:32:59 +0000 (00:32 -0700)]
oss-fuzz: Fallback to `ninja-build` when available (#8641)

The ninja binary is deployed as `ninja-build` in older distros such as
RHEL 7/CentOS 7.  Detect that and use `ninja-build` instead of `ninja`
when it's available.

5 years agoupdate TODO
Lennart Poettering [Thu, 29 Mar 2018 15:47:03 +0000 (17:47 +0200)]
update TODO

5 years agocore: skip the removal of cgroups in the TEST_RUN_MINIMAL mode (#8622)
Evgeny Vereshchagin [Tue, 3 Apr 2018 13:04:22 +0000 (16:04 +0300)]
core: skip the removal of cgroups in the TEST_RUN_MINIMAL mode (#8622)

When `systemd` is run in the TEST_RUN_MINIMAL mode, it doesn't really
set up cgroups, so it shouldn't try to remove anything.

Closes https://github.com/systemd/systemd/issues/8474.

5 years agosd-bus: allow description to be set for system/user busses (#8594)
Zbigniew Jędrzejewski-Szmek [Thu, 29 Mar 2018 14:14:11 +0000 (16:14 +0200)]
sd-bus: allow description to be set for system/user busses (#8594)

sd_bus_open/sd_bus_open_system/sd_bus_open_user are convenient, but
don't allow the description to be set. After they return, the bus is
is already started, and sd_bus_set_description() fails with -EBUSY.
It would be possible to allow sd_bus_set_description() to update the
description "live", but messages are already emitted from sd_bus_open
functions, so it's better to allow the description to be set in
sd_bus_open/sd_bus_open_system/sd_bus_open_user.

Fixes message like:
Bus n/a: changing state UNSET → OPENING

5 years agotree-wide: remove unused variables (#8612)
Yu Watanabe [Thu, 29 Mar 2018 10:50:50 +0000 (19:50 +0900)]
tree-wide: remove unused variables (#8612)

5 years agoRename suspend-to-hibernate to suspend-then-hibernate
Mario Limonciello [Wed, 28 Mar 2018 16:00:06 +0000 (11:00 -0500)]
Rename suspend-to-hibernate to suspend-then-hibernate

Per some discussion with Gnome folks, they would prefer this name
as it's more descriptive of what's happening.

5 years agomachine-image,mount-setup: minor coding style fixes
Lennart Poettering [Wed, 28 Mar 2018 15:07:42 +0000 (17:07 +0200)]
machine-image,mount-setup: minor coding style fixes

5 years agoinhibit: make use of EXIT_SUCCESS where appropriate
Lennart Poettering [Tue, 27 Mar 2018 12:58:21 +0000 (14:58 +0200)]
inhibit: make use of EXIT_SUCCESS where appropriate

5 years agoutil: check for overflows in xbsearch_r()
Lennart Poettering [Tue, 27 Mar 2018 12:56:04 +0000 (14:56 +0200)]
util: check for overflows in xbsearch_r()

5 years agoupdate TODO
Lennart Poettering [Tue, 20 Mar 2018 19:26:15 +0000 (20:26 +0100)]
update TODO