chiark / gitweb /
Lennart Poettering [Wed, 21 Feb 2018 16:42:59 +0000 (17:42 +0100)]
basic: add a common syscall wrapper around reboot()
This mimics the raw_clone() call we have in place already and
establishes a new syscall wrapper raw_reboot() that wraps the kernel's
reboot() system call in a bit more low-level fashion that glibc's
reboot() wrapper. The main difference is that the extra "arg" argument
is supported.
Ultimately this just replaces the syscall wrapper implementation we
currently have at three places in our codebase by a single one.
With this change this means that all our syscall() invocations are
neatly separated out in static inline system call wrappers in our header
functions.
Lennart Poettering [Wed, 21 Feb 2018 16:27:34 +0000 (17:27 +0100)]
missing: always use __NR_ as prefix for syscall numbers
Apparently, both __NR_ and SYS_ are useful, but we mostly use __NR_
hence use it for these two cases too, so that we settle on __NR_
exclusively.
Lennart Poettering [Wed, 21 Feb 2018 16:25:01 +0000 (17:25 +0100)]
missing: Fix statx syscall ifdeffery
Fix a copy/paste mistake.
Fixes: #8238
Lennart Poettering [Wed, 21 Feb 2018 23:35:00 +0000 (00:35 +0100)]
tree-wide: reopen log when we need to log in FORK_CLOSE_ALL_FDS children
In a number of occasions we use FORK_CLOSE_ALL_FDS when forking off a
child, since we don't want to pass fds to the processes spawned (either
because we later want to execve() some other process there, or because
our child might hang around for longer than expected, in which case it
shouldn't keep our fd pinned). This also closes any logging fds, and
thus means logging is turned off in the child. If we want to do proper
logging, explicitly reopen the logs hence in the child at the right
time.
This is particularly crucial in the umount/remount children we fork off
the shutdown binary, as otherwise the children can't log, which is
why #8155 is harder to debug than necessary: the log messages we
generate about failing mount() system calls aren't actually visible on
screen, as they done in the child processes where the log fds are
closed.
Lennart Poettering [Wed, 21 Feb 2018 23:31:36 +0000 (00:31 +0100)]
log: only open kmsg on fallback if we actually want to use it
Previously, we'd try to open kmsg on failure of the journal/syslog even
if no automatic fallback to kmsg was requested — and we wouldn't even
use the open connection afterwards...
Zbigniew Jędrzejewski-Szmek [Wed, 21 Feb 2018 13:04:50 +0000 (14:04 +0100)]
missing_syscall: when adding syscall replacements, use different names (#8229)
In meson.build we check that functions are available using:
meson.get_compiler('c').has_function('foo')
which checks the following:
- if __stub_foo or __stub___foo are defined, return false
- if foo is declared (a pointer to the function can be taken), return true
- otherwise check for __builtin_memfd_create
_stub is documented by glibc as
It defines a symbol '__stub_FUNCTION' for each function
in the C library which is a stub, meaning it will fail
every time called, usually setting errno to ENOSYS.
So if __stub is defined, we know we don't want to use the glibc version, but
this doesn't tell us if the name itself is defined or not. If it _is_ defined,
and we define our replacement as an inline static function, we get an error:
In file included from ../src/basic/missing.h:1358:0,
from ../src/basic/util.h:47,
from ../src/basic/calendarspec.h:29,
from ../src/basic/calendarspec.c:34:
../src/basic/missing_syscall.h:65:19: error: static declaration of 'memfd_create' follows non-static declaration
static inline int memfd_create(const char *name, unsigned int flags) {
^~~~~~~~~~~~
.../usr/include/bits/mman-shared.h:46:5: note: previous declaration of 'memfd_create' was here
int memfd_create (const char *__name, unsigned int __flags) __THROW;
^~~~~~~~~~~~
To avoid this problem, call our inline functions different than glibc,
and use a #define to map the official name to our replacement.
Fixes #8099.
v2:
- use "missing_" as the prefix instead of "_"
v3:
- rebase and update for statx()
Unfortunately "statx" is also present in "struct statx", so the define
causes issues. Work around this by using a typedef.
I checked that systemd compiles with current glibc
(glibc-devel-2.26-24.fc27.x86_64) if HAVE_MEMFD_CREATE, HAVE_GETTID,
HAVE_PIVOT_ROOT, HAVE_SETNS, HAVE_RENAMEAT2, HAVE_KCMP, HAVE_KEYCTL,
HAVE_COPY_FILE_RANGE, HAVE_BPF, HAVE_STATX are forced to 0.
Setting HAVE_NAME_TO_HANDLE_AT to 0 causes an issue, but it's not because of
the define, but because of struct file_handle.
Zbigniew Jędrzejewski-Szmek [Tue, 20 Feb 2018 16:13:41 +0000 (17:13 +0100)]
test-user-util: skip most tests for nobody if synthentization is off
When synthetisation is turned off, there's just too many ways those tests can
go wrong. We are not interested in verifying that the db on disk is correct,
let's just skip all checks.
In the first version of this patch, I recorded if we detected a mismatch during
configuration and only skipped tests in that case, but actually it is possible
to change the host configuration between our configuration phase and running
of the tests. It's just more robust to skip always. (This is particularly true
if tests are installed.)
Zbigniew Jędrzejewski-Szmek [Tue, 20 Feb 2018 21:10:45 +0000 (22:10 +0100)]
test-user-util: print function delimiters
This makes it easier to see what is going on. Crashes may happen in a
nested test_{uid,gid}_to_name_one() function, and the default backtrace
doesn't show the actual string being tested.
Zbigniew Jędrzejewski-Szmek [Tue, 20 Feb 2018 13:53:09 +0000 (14:53 +0100)]
Yu Watanabe [Thu, 15 Feb 2018 00:43:02 +0000 (09:43 +0900)]
mount-util: call mount_option_mangle() in mount_verbose()
Yu Watanabe [Thu, 15 Feb 2018 00:32:04 +0000 (09:32 +0900)]
mount-util: add mount_option_mangle()
This is used in the later commits.
Lennart Poettering [Tue, 20 Feb 2018 11:48:33 +0000 (12:48 +0100)]
xattr-util: use crtime/btime if statx() is available for implementation of fd_setcrtime() and friends
The Linux kernel exposes the birth time now for files through statx()
hence make use of it where available. We keep the xattr logic in place
for this however, since only a subset of file systems on Linux currently
expose the birth time. NFS and tmpfs for example do not support it. OTOH
there are other file systems that do support the birth time but might
not support xattrs (smb…), hence make the best of the two, in particular
in order to deal with journal files copied between file system types and
to maintain compatibility with older file systems that are updated to
newer version of the file system.
Lennart Poettering [Tue, 20 Feb 2018 11:46:14 +0000 (12:46 +0100)]
xattr-util: support AT_EMPTY_PATH in fgetxattrat_fake()
Let's expose fstatat() like behaviour if AT_EMPTY_PATH is defined.
Also, check the specified flags returning EINVAL on the flags we don't
emulate.
Lennart Poettering [Mon, 19 Feb 2018 17:37:50 +0000 (18:37 +0100)]
io-util: add an unlikely decorator for a test that should never hold
Lennart Poettering [Mon, 19 Feb 2018 17:24:36 +0000 (18:24 +0100)]
tree-wide: make use of fsync_directory_of_file() all over the place
Let's make use this at various places we call fsync(), to make things
fully reliable, as the kernel devs suggest to first fsync() files and
then fsync() the directories they are located in.
Lennart Poettering [Mon, 19 Feb 2018 17:23:38 +0000 (18:23 +0100)]
fs-util: move fsync_directory_of_file() into generic code
This function used by the journal code is pretty useful generically,
let's move it to fs-util.c to make it useful for other code too.
Lennart Poettering [Mon, 19 Feb 2018 17:01:05 +0000 (18:01 +0100)]
stat-util: unify code that checks whether something is a regular file
Let's add a common implementation for regular file checks, that are
careful to return the right error code (EISDIR/EISLNK/EBADFD) when we
are encountering a wrong file node.
Zbigniew Jędrzejewski-Szmek [Fri, 16 Feb 2018 09:34:00 +0000 (10:34 +0100)]
tests: add a simple test for utf8_n_codepoints()
Zbigniew Jędrzejewski-Szmek [Fri, 16 Feb 2018 09:27:47 +0000 (10:27 +0100)]
Some comment adjustments
Follow up for review of #8184.
Zbigniew Jędrzejewski-Szmek [Fri, 16 Feb 2018 09:17:46 +0000 (10:17 +0100)]
pid1: do not initialize join_controllers by default
We're moving towards unified cgroup hierarchy where this is not necessary.
This makes main.c a bit simpler.
Zbigniew Jędrzejewski-Szmek [Fri, 16 Feb 2018 08:56:29 +0000 (09:56 +0100)]
Move config_parse_join_controllers to shared, add test
config_parse_join_controllers would free the destination argument on failure,
which is contrary to our normal style, where failed parsing has no effect.
Moving it to shared also allows a test to be added.
Zbigniew Jędrzejewski-Szmek [Fri, 16 Feb 2018 08:29:57 +0000 (09:29 +0100)]
shared/conf-parser: define a macro for the repeating argument set
The arguments have to be indentical everywhere, so let's use a macro to
make things more readable. But only in the headers, in the .c files let's
keep them verbose so that it's easy to see the argument list.
Zbigniew Jędrzejewski-Szmek [Fri, 16 Feb 2018 06:03:13 +0000 (07:03 +0100)]
test-process-util: one more (void)
Zbigniew Jędrzejewski-Szmek [Fri, 16 Feb 2018 06:00:22 +0000 (07:00 +0100)]
Add some handling to remaining unlinkat calls
Coverity now started warning about this ("Calling unlinkat without checking
return value (as is done elsewhere 12 out of 15 times).", and it is right:
most of the time we should at list print a log message so people can figure
out something is wrong when this happens.
v2:
- use warning level in journald too (this is unlikely to happen ever, so it
should be safe to something that is visible by default).
Zbigniew Jędrzejewski-Szmek [Fri, 16 Feb 2018 05:58:33 +0000 (06:58 +0100)]
login,user-sessions: always warn when we fail to remove nologin file
This usually is very annoying to users who then cannot log in, so
make sure we always warn if that happens (selinux, or whatever other reason).
This reverts
a790812cb349c5cef95d1b4a20fc80ca08d3a145.
Caio Marcelo de Oliveira Filho [Mon, 19 Feb 2018 02:33:16 +0000 (18:33 -0800)]
meson: apply defaults if /etc/login.defs doesn't exist
Apply defaults for system_{uid,gid}_max even if the /etc/login.defs file
doesn't exist (e.g. in Clear Linux with no changes).
awk returns an empty string in case the file doesn't exist, causing meson to
fail in to_int(). So set the default if output is empty. This makes the BEGIN{}
blocks unnecessary, so remove them.
Caio Marcelo de Oliveira Filho [Mon, 19 Feb 2018 09:37:19 +0000 (01:37 -0800)]
meson: use multiline string syntax (#8214)
The single quote working with multiple lines is likely to be unintended. With
current versions of meson, it also causes error messages after it to report the
wrong line number. Use the documented syntax instead.
Zbigniew Jędrzejewski-Szmek [Fri, 16 Feb 2018 11:48:55 +0000 (12:48 +0100)]
meson: drop unnecessary "transformation" of policy files
Those files don't contain any @variables@, so the configuration step was just
copying them to build/. Let's avoid that, and fix their suffixes while at it.
Zbigniew Jędrzejewski-Szmek [Fri, 16 Feb 2018 11:37:42 +0000 (12:37 +0100)]
meson: drop double .in suffix for o.fd.systemd1.policy file
This file is now undergoing just one transformation, so drop the unnecessary
suffix.
Gunnar Hjalmarsson [Thu, 15 Feb 2018 20:21:58 +0000 (21:21 +0100)]
Gettextize policy files
* Don't merge translations into the files
* Add gettext-domain="systemd" to description and message
Closes #8162, replaces #8118.
Zbigniew Jędrzejewski-Szmek [Thu, 15 Feb 2018 12:14:35 +0000 (13:14 +0100)]
logind: change check_gc to may_gc everywhere
Zbigniew Jędrzejewski-Szmek [Thu, 15 Feb 2018 10:43:08 +0000 (11:43 +0100)]
meson: add -Dmemory-accounting-default=true|false
This makes it easy to set the default for distributions and users which want to
default to off because they primarily use older kernels.
Lennart Poettering [Fri, 9 Feb 2018 18:59:53 +0000 (19:59 +0100)]
pid1: turn memory accounting on by default now
After discussions with @htejun it appears it's OK now to enable memory
accounting by default for all units without affecting system performance
too badly. facebook has made good experiences with deploying memory
accounting across their infrastructure.
This hence turns MemoryAccounting= from opt-in to opt-out, similar to
how TasksAccounting= is already handled. The other accounting options
remain off, their performance impact is too big still.
Lennart Poettering [Wed, 14 Feb 2018 17:41:03 +0000 (18:41 +0100)]
utf8: add utf8_n_codepoints() for counting complete utf8 codepoints in a string
Lennart Poettering [Wed, 14 Feb 2018 16:30:37 +0000 (17:30 +0100)]
terminal-util: make resolve_dev_console() less weird
Let's normalize the behaviour: return a negative errno style error code,
and return the resolved string directly as argument.
Lennart Poettering [Wed, 14 Feb 2018 13:56:17 +0000 (14:56 +0100)]
terminal-util: modernize get_kernel_consoles() a bit
Also, make sure when we run in a container, we don't use the data from
/sys at all, but immediately fall back to /dev/console itself.
Lennart Poettering [Wed, 14 Feb 2018 13:30:30 +0000 (14:30 +0100)]
tty-ask-password-agent: reenable color for boot-time password prompt
The password prompt used to be highlighted, and that was a good thing.
Let's fix things to make the prompt highlighted again.
Fixes: #3853
Lennart Poettering [Wed, 14 Feb 2018 13:28:17 +0000 (14:28 +0100)]
terminal-util: add some explanatory comments
Lennart Poettering [Wed, 14 Feb 2018 13:28:00 +0000 (14:28 +0100)]
update TODO
Lennart Poettering [Wed, 14 Feb 2018 13:27:31 +0000 (14:27 +0100)]
process: shortcut getenv_for_pid() for our own process
Lennart Poettering [Tue, 13 Feb 2018 22:53:34 +0000 (23:53 +0100)]
terminal-util: minor, trivial fixes and improvements
Lennart Poettering [Tue, 13 Feb 2018 22:50:26 +0000 (23:50 +0100)]
terminal-util: when making /dev/null or the console stdio, forget cached terminal features
Let's forget all relevant terminal features we learnt when we make a
console or /dev/null stdin/stdout/stderr.
Also, while we are at it, let's drop the various _unlikely_ and
_likely_ annotiations around the terminal feature caches. In many cases
we call the relevant functions only once in which cases the annotations
are likely to do just harm and no good. After all we can't know if the
specific code will call us just once or many times...
Lennart Poettering [Tue, 13 Feb 2018 20:24:37 +0000 (21:24 +0100)]
terminal-util: rework acquire_terminal()
This modernizes acquire_terminal() in a couple of ways:
1. The three boolean arguments are replaced by a flags parameter, that
should be more descriptive in what it does.
2. We now properly handle inotify queue overruns
3. We use _cleanup_ for closing the fds now, to shorten the code quite a
bit.
Behaviour should not be altered by this.
Lennart Poettering [Wed, 7 Feb 2018 22:03:13 +0000 (23:03 +0100)]
update TODO
Lennart Poettering [Wed, 7 Feb 2018 21:52:52 +0000 (22:52 +0100)]
core: add new new bus call for migrating foreign processes to scope/service units
This adds a new bus call to service and scope units called
AttachProcesses() that moves arbitrary processes into the cgroup of the
unit. The primary user for this new API is systemd itself: the systemd
--user instance uses this call of the systemd --system instance to
migrate processes if itself gets the request to migrate processes and
the kernel refuses this due to access restrictions.
The primary use-case of this is to make "systemd-run --scope --user …"
invoked from user session scopes work correctly on pure cgroupsv2
environments. There, the kernel refuses to migrate processes between two
unprivileged-owned cgroups unless the requestor as well as the ownership
of the closest parent cgroup all match. This however is not the case
between the session-XYZ.scope unit of a login session and the
user@ABC.service of the systemd --user instance.
The new logic always tries to move the processes on its own, but if
that doesn't work when being the user manager, then the system manager
is asked to do it instead.
The new operation is relatively restrictive: it will only allow to move
the processes like this if the caller is root, or the UID of the target
unit, caller and process all match. Note that this means that
unprivileged users cannot attach processes to scope units, as those do
not have "owning" users (i.e. they have now User= field).
Fixes: #3388
Lennart Poettering [Wed, 7 Feb 2018 21:28:42 +0000 (22:28 +0100)]
sd-bus: synthesize a description for user/system bus if otherwise unset
Let's make debugging easier, by synthesizing a name when we have some
indication what kind of bus this is.
Lennart Poettering [Wed, 7 Feb 2018 17:11:18 +0000 (18:11 +0100)]
user-util: also consider /bin/false and /bin/true as non-shell
Lennart Poettering [Tue, 6 Feb 2018 14:59:55 +0000 (15:59 +0100)]
process-util: be more careful in is_kernel_thread()
This reworks is_kernel_thread() a bit. Instead of checking whether
/proc/$pid/cmdline is entirely empty we now parse the 'flags' field from
/proc/$pid/stat and check the PF_KTHREAD flag, which directly encodes
whether something is a kernel thread.
Why all this? With current kernels userspace processes can set their
command line to empty too (through PR_SET_MM_ARG_START and friends), and
could potentially confuse us. Hence, let's use a more reliable way to
detect kernels like this.
Lennart Poettering [Tue, 6 Feb 2018 10:57:35 +0000 (11:57 +0100)]
cgroup: add a new "can_delegate" flag to the unit vtable, and set it for scope and service units only
Currently we allowed delegation for alluntis with cgroup backing
except for slices. Let's make this a bit more strict for now, and only
allow this in service and scope units.
Let's also add a generic accessor unit_cgroup_delegate() for checking
whether a unit has delegation turned on that checks the new bool first.
Also, when doing transient units, let's explcitly refuse turning on
delegation for unit types that don#t support it. This is mostly
cosmetical as we wouldn't act on the delegation request anyway, but
certainly helpful for debugging.
Davide Cavalca [Wed, 14 Feb 2018 13:08:50 +0000 (05:08 -0800)]
meson: factor out daemon/event/id128 sources into variables (#8170)
Lennart Poettering [Fri, 9 Feb 2018 08:52:36 +0000 (09:52 +0100)]
rm-rf: make flags fields easier to read
Lennart Poettering [Fri, 9 Feb 2018 08:50:31 +0000 (09:50 +0100)]
fs-util: add new unlinkat_deallocate() helper
This new helper not only removes a file from a directory but also
ensures its space on disk is deallocated, by either punching a hole over
the full file or truncating the file afterwards if the file's link
counter is 0. This is useful in "vacuuming" algorithms to ensure that
client's can't keep the disk space the vacuuming is supposed to recover
pinned simply by keeping an fd open to it.
Lennart Poettering [Fri, 9 Feb 2018 08:50:13 +0000 (09:50 +0100)]
copy: wrap some unlink() calls in (void) casts
Lennart Poettering [Thu, 8 Feb 2018 17:58:35 +0000 (18:58 +0100)]
tree-wide: use path_hash_ops instead of string_hash_ops whenever we key by a path
Let's make use of our new hash_ops!
Lennart Poettering [Thu, 8 Feb 2018 17:31:15 +0000 (18:31 +0100)]
hash-func: add generic hash_ops implementation for hashing paths
This is similar to string_hash_ops but operates one file system paths
specifically. It will ensure that "/foo//bar" and "///foo/bar" are
considered to be the same path for hashmap purposes.
This makes use of the existing path_compare() API, and adds a matching
hashing function for it.
Note that relative and absolute paths will hash to different values,
however whether the path is suffixed with a slash or not is not
detected. This matches the existing path_compare() behaviour, and
follows the logic that on Linux there can't be two different objects at
path /foo/bar and /foo/bar/ either.
Lennart Poettering [Thu, 8 Feb 2018 16:37:56 +0000 (17:37 +0100)]
hash-funcs: remove redundant definition of devt_hash_ops
We should assign a value only in the .c file, not in both the .c and .h
file.
Lennart Poettering [Thu, 8 Feb 2018 16:14:37 +0000 (17:14 +0100)]
journal: move code that checks for network fs to stat-util.[ch]
We have similar code in stat-util.[ch] and managing this at a central
place almost definitely is the better choice.
Zbigniew Jędrzejewski-Szmek [Wed, 14 Feb 2018 08:34:46 +0000 (09:34 +0100)]
Yu Watanabe [Fri, 9 Feb 2018 08:52:05 +0000 (17:52 +0900)]
socket-util: drop getnameinfo_pretty()
Yu Watanabe [Fri, 9 Feb 2018 07:58:56 +0000 (16:58 +0900)]
fs-util: drop readlink_and_make_absolute_root()
Yu Watanabe [Fri, 9 Feb 2018 07:49:54 +0000 (16:49 +0900)]
fs-util: drop readlink_and_canonicalize()
Zbigniew Jędrzejewski-Szmek [Fri, 9 Feb 2018 12:31:37 +0000 (13:31 +0100)]
basic/socket-util: drop use of NI_IDN_USE_STD3_ASCII_RULES
The only use of socknameinfo_pretty() is in src/journal-remote/journal-remote.c,
to determine the output filename.
Replaces #8120.
Lennart Poettering [Fri, 9 Feb 2018 16:53:28 +0000 (17:53 +0100)]
fd-util: move certain fds above fd #2 (#8129)
This adds some paranoia code that moves some of the fds we allocate for
longer periods of times to fds > 2 if they are allocated below this
boundary. This is a paranoid safety thing, in order to avoid that
external code might end up erroneously use our fds under the assumption
they were valid stdin/stdout/stderr. Think: some app closes
stdin/stdout/stderr and then invokes 'fprintf(stderr, …' which causes
writes on our fds.
This both adds the helper to do the moving as well as ports over a
number of users to this new logic. Since we don't want to litter all our
code with invocations of this I tried to strictly focus on fds we keep
open for long periods of times only and only in code that is frequently
loaded into foreign programs (under the assumptions that in our own
codebase we are smart enough to always keep stdin/stdout/stderr
allocated to avoid this pitfall). Specifically this means all code used
by NSS and our sd-xyz API:
1. our logging APIs
2. sd-event
3. sd-bus
4. sd-resolve
5. sd-netlink
This changed was inspired by this:
https://github.com/systemd/systemd/issues/8075#issuecomment-
363689755
This shows that apparently IRL there are programs that do close
stdin/stdout/stderr, and we should accomodate for that.
Note that this won't fix any bugs, this just makes sure that buggy
programs are less likely to interfere with out own code.
Simon Fowler [Fri, 9 Feb 2018 16:37:39 +0000 (02:37 +1000)]
Suspend on lid close based on power status. (#8016)
This change adds support for controlling the suspend-on-lid-close
behaviour based on the power status as well as whether the machine is
docked or has an external monitor. For backwards compatibility the new
configuration file variable is ignored completely by default, and must
be set explicitly before being considered in any decisions.
Shawn Landden [Sat, 3 Feb 2018 18:16:33 +0000 (10:16 -0800)]
sd-bus: cleanup ssh sessions (Closes: #8076)
we still invoke ssh unnecessarily when there in incompatible or erreneous input
The fallow-up to finish that would make the code a bit more verbose,
as it would require repeating this bit:
```
r = bus_connect_transport(arg_transport, arg_host, false, &bus);
if (r < 0) {
log_error_errno(r, "Failed to create bus connection: %m");
goto finish;
}
sd_bus_set_allow_interactive_authorization(bus, arg_ask_password);
```
in every verb, after parsing.
v2: add waitpid() to avoid a zombie process, switch to SIGTERM from SIGKILL
v3: refactor, wait in bus_start_address()
Yu Watanabe [Fri, 9 Feb 2018 07:19:11 +0000 (16:19 +0900)]
sd-bus: explicitly convert int to bool
Yu Watanabe [Fri, 9 Feb 2018 07:21:51 +0000 (16:21 +0900)]
sd-bus: use free_and_replace()
Yu Watanabe [Fri, 9 Feb 2018 07:21:29 +0000 (16:21 +0900)]
sd-bus: avoid potential memory leaks
Zbigniew Jędrzejewski-Szmek [Mon, 5 Feb 2018 13:53:11 +0000 (14:53 +0100)]
tmpfiles: allow admin/runtime overrides to runtime config
This is very similar to
d16a1c1bb6. For tmpfiles this is much less useful
compared to sysusers, but let's add this anyway for consistency.
Lennart Poettering [Wed, 7 Feb 2018 02:10:09 +0000 (03:10 +0100)]
process-util: use raw_getpid() in getpid_cache() internally (#8115)
We have the raw_getpid() definition in place anyway, and it's certainly
beneficial to expose the same semantics on pre glibc 2.24 and after it
too, hence always bypass glibc for this, and always cache things on our
side.
Fixes: #8113
Yu Watanabe [Tue, 6 Feb 2018 03:17:50 +0000 (12:17 +0900)]
core/execute: make arguments constant if possible
Also make functions static if possible.
Zbigniew Jędrzejewski-Szmek [Mon, 5 Feb 2018 08:48:38 +0000 (09:48 +0100)]
test: add a simple smoke test for string_hashsum()
This is enough to show memory leakages pointed out by Stef Bon <stefbon@gmail.com>.
Zbigniew Jędrzejewski-Szmek [Wed, 31 Jan 2018 14:37:02 +0000 (15:37 +0100)]
sysusers: allow admin/runtime overrides to command-line config
When used in a package installation script, we want to invoke systemd-sysusers
before that package is installed (so it can contain files owned by the newly
created user), so the configuration to use is specified on the command
line. This should be a copy of the configuration that will be installed as
/usr/lib/sysusers.d/package.conf. We still want to obey any overrides in
/etc/sysusers.d or /run/sysusers.d in the usual fashion. Otherwise, we'd get a
different result when systemd-sysusers is run with a copy of the new config on
the command line and when systemd-sysusers is run at boot after package
instalation. In the second case any files in /etc or /run have higher priority,
so the same should happen when the configuration is given on the command line.
More generally, we want the behaviour in this special case to be as close to
the case where the file is finally on disk as possible, so we have to read all
configuration files, since they all might contain overrides and additional
configuration that matters. Even files that have lower priority might specify
additional groups for the user we are creating. Thus, we need to read all
configuration, but insert our new configuration somewhere with the right
priority.
If --target=/path/to/file.conf is given on the command line, we gather the list
of files, and pretend that the command-line config is read from
/path/to/file.conf (doesn't matter if the file on disk actually exists or
not). All package scripts should use this option to obtain consistent and
idempotent behaviour.
The corner case when --target= is specified and there are no positional
arguments is disallowed.
v1:
- version with --config-name=
v2:
- disallow --config-name= and no positional args
v3:
- remove --config-name=
v4:
- add --target= and rework the code completely
v5:
- fix argcounting bug and add example in man page
v6:
- rename --target to --replace
Zbigniew Jędrzejewski-Szmek [Thu, 1 Feb 2018 11:50:18 +0000 (12:50 +0100)]
basic/strv: add function to insert items at position
Zbigniew Jędrzejewski-Szmek [Tue, 30 Jan 2018 13:28:10 +0000 (14:28 +0100)]
sysusers: allow the shell to be specified
This is necessary for some system users where the "login shell" is
set to a specific binary.
Zbigniew Jędrzejewski-Szmek [Mon, 29 Jan 2018 13:23:31 +0000 (14:23 +0100)]
sysusers: emit a bit more info at debug level when locking fails
This is the first error message when running unprivileged, and the message is
unspecific, so let's at least add some logging at debug level to make this less
confusing.
MilhouseVH [Mon, 5 Feb 2018 05:26:57 +0000 (05:26 +0000)]
kernel 3.10 compat: RTAX_QUICKACK not added until 3.11.0 (#8094)
Zbigniew Jędrzejewski-Szmek [Fri, 2 Feb 2018 13:34:00 +0000 (14:34 +0100)]
basic/hashmap: tweak code to avoid pointless gcc warning
gcc says:
[196/1142] Compiling C object 'src/basic/basic@sta/hashmap.c.o'.
../src/basic/hashmap.c: In function ‘cachemem_maintain’:
../src/basic/hashmap.c:1913:17: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
mem->active = r = true;
^~~
which conflates two things: the first is transitive assignent a = b = c = d;
the second is assignment of the value of an expression, which happens to be a
an assignment expression here, and boolean. While the second _should_ be
parenthesized, the first should _not_, and it's more natural to understand
our code as the first, and gcc should treat this as an exception and not emit
the warning. But since it's a while until this will be fixed, let's update
our code too.
tblume [Thu, 1 Feb 2018 21:46:15 +0000 (22:46 +0100)]
meson.build: make docdir configurable (#8068)
SUSE is using a different docdir, so the path should be configurable
Vito Caputo [Sat, 27 Jan 2018 21:10:39 +0000 (13:10 -0800)]
test-hashmap: test IteratedCache
Add some rudimentary testing of the new IteratedCache
Vito Caputo [Sat, 27 Jan 2018 00:38:01 +0000 (16:38 -0800)]
basic: implement the IteratedCache
Adds the basics of the IteratedCache and constructor support for the
Hashmap and OrderedHashmap types.
iterated_cache_get() is responsible for synchronizing the cache with
the associated Hashmap and making it available to the caller at the
supplied result pointers. Since iterated_cache_get() may need to
allocate memory, it may fail, so callers must check the return value.
On success, pointer arrays containing pointers to the associated
Hashmap's keys and values, in as-iterated order, are returned in
res_keys and res_values, respectively. Either may be supplied as NULL
to inhibit caching of the keys or values, respectively.
Note that if the cached Hashmap hasn't changed since the previous call
to iterated_cache_get(), and it's not a call activating caching of the
values or keys, the cost is effectively zero as the resulting pointers
will simply refer to the previously returned arrays as-is.
A cleanup function has also been added, iterated_cache_free().
This only frees the IteratedCache container and related arrays. The
associated Hashmap, its keys, and values are not affected. Also note
that the associated Hashmap does not automatically free its associated
IteratedCache when freed.
One could, in theory, safely access the arrays returned by a
successful iterated_cache_get() call after its associated Hashmap has
been freed, including the referenced values and keys. Provided the
iterated_cache_get() was performed prior to the hashmap free, and that
the type of hashmap free performed didn't free keys and/or values as
well.
Vito Caputo [Sun, 8 Oct 2017 23:28:04 +0000 (16:28 -0700)]
basic: track dirty state in HashmapBase
This only adds marking the HashmapBase as dirty, no clearing of
the dirty state happens yet.
No functional changes.
Lennart Poettering [Wed, 31 Jan 2018 18:53:16 +0000 (19:53 +0100)]
update TODO
Yu Watanabe [Thu, 1 Feb 2018 09:11:02 +0000 (18:11 +0900)]
strv: drop strv_join_quoted() (#8057)
The function `strv_join_quoted()` is now not used, and has a bug
in the buffer size calculation when the strings needs to escaped,
as reported in #8056.
So, let's remove the function.
Closes #8056.
Sven Eden [Wed, 30 May 2018 05:54:20 +0000 (07:54 +0200)]
Save last mutual commit for migration of the v237-stable branch.
Zbigniew Jędrzejewski-Szmek [Wed, 21 Feb 2018 13:04:50 +0000 (14:04 +0100)]
missing_syscall: when adding syscall replacements, use different names (#8229)
In meson.build we check that functions are available using:
meson.get_compiler('c').has_function('foo')
which checks the following:
- if __stub_foo or __stub___foo are defined, return false
- if foo is declared (a pointer to the function can be taken), return true
- otherwise check for __builtin_memfd_create
_stub is documented by glibc as
It defines a symbol '__stub_FUNCTION' for each function
in the C library which is a stub, meaning it will fail
every time called, usually setting errno to ENOSYS.
So if __stub is defined, we know we don't want to use the glibc version, but
this doesn't tell us if the name itself is defined or not. If it _is_ defined,
and we define our replacement as an inline static function, we get an error:
In file included from ../src/basic/missing.h:1358:0,
from ../src/basic/util.h:47,
from ../src/basic/calendarspec.h:29,
from ../src/basic/calendarspec.c:34:
../src/basic/missing_syscall.h:65:19: error: static declaration of 'memfd_create' follows non-static declaration
static inline int memfd_create(const char *name, unsigned int flags) {
^~~~~~~~~~~~
.../usr/include/bits/mman-shared.h:46:5: note: previous declaration of 'memfd_create' was here
int memfd_create (const char *__name, unsigned int __flags) __THROW;
^~~~~~~~~~~~
To avoid this problem, call our inline functions different than glibc,
and use a #define to map the official name to our replacement.
Fixes #8099.
v2:
- use "missing_" as the prefix instead of "_"
v3:
- rebase and update for statx()
Unfortunately "statx" is also present in "struct statx", so the define
causes issues. Work around this by using a typedef.
I checked that systemd compiles with current glibc
(glibc-devel-2.26-24.fc27.x86_64) if HAVE_MEMFD_CREATE, HAVE_GETTID,
HAVE_PIVOT_ROOT, HAVE_SETNS, HAVE_RENAMEAT2, HAVE_KCMP, HAVE_KEYCTL,
HAVE_COPY_FILE_RANGE, HAVE_BPF, HAVE_STATX are forced to 0.
Setting HAVE_NAME_TO_HANDLE_AT to 0 causes an issue, but it's not because of
the define, but because of struct file_handle.
(cherry picked from commit
5187dd2c403caf92d09f3491e41f1ceb3f10491f)
Zbigniew Jędrzejewski-Szmek [Tue, 20 Feb 2018 16:13:41 +0000 (17:13 +0100)]
test-user-util: skip most tests for nobody if synthentization is off
When synthetisation is turned off, there's just too many ways those tests can
go wrong. We are not interested in verifying that the db on disk is correct,
let's just skip all checks.
In the first version of this patch, I recorded if we detected a mismatch during
configuration and only skipped tests in that case, but actually it is possible
to change the host configuration between our configuration phase and running
of the tests. It's just more robust to skip always. (This is particularly true
if tests are installed.)
(cherry picked from commit
7559b2da10b1513849f22312d09a2381569b4f06)
Zbigniew Jędrzejewski-Szmek [Tue, 20 Feb 2018 21:10:45 +0000 (22:10 +0100)]
test-user-util: print function delimiters
This makes it easier to see what is going on. Crashes may happen in a
nested test_{uid,gid}_to_name_one() function, and the default backtrace
doesn't show the actual string being tested.
(cherry picked from commit
52c6e6a8a0221530659c65090f18b16c45a9fc04)
Caio Marcelo de Oliveira Filho [Mon, 19 Feb 2018 02:33:16 +0000 (18:33 -0800)]
meson: apply defaults if /etc/login.defs doesn't exist
Apply defaults for system_{uid,gid}_max even if the /etc/login.defs file
doesn't exist (e.g. in Clear Linux with no changes).
awk returns an empty string in case the file doesn't exist, causing meson to
fail in to_int(). So set the default if output is empty. This makes the BEGIN{}
blocks unnecessary, so remove them.
(cherry picked from commit
2f62cf3552d48f518313bd6265bad6763e2b643b)
Caio Marcelo de Oliveira Filho [Mon, 19 Feb 2018 09:37:19 +0000 (01:37 -0800)]
meson: use multiline string syntax (#8214)
The single quote working with multiple lines is likely to be unintended. With
current versions of meson, it also causes error messages after it to report the
wrong line number. Use the documented syntax instead.
(cherry picked from commit
9e70f2f81821efa4797d89c06d1f04c11e86015e)
Lennart Poettering [Fri, 9 Feb 2018 08:50:31 +0000 (09:50 +0100)]
fs-util: add new unlinkat_deallocate() helper
This new helper not only removes a file from a directory but also
ensures its space on disk is deallocated, by either punching a hole over
the full file or truncating the file afterwards if the file's link
counter is 0. This is useful in "vacuuming" algorithms to ensure that
client's can't keep the disk space the vacuuming is supposed to recover
pinned simply by keeping an fd open to it.
(cherry picked from commit
43767d9d5e0ce8923828aebf9154da7af83916f7)
Lennart Poettering [Thu, 8 Feb 2018 17:31:15 +0000 (18:31 +0100)]
hash-func: add generic hash_ops implementation for hashing paths
This is similar to string_hash_ops but operates one file system paths
specifically. It will ensure that "/foo//bar" and "///foo/bar" are
considered to be the same path for hashmap purposes.
This makes use of the existing path_compare() API, and adds a matching
hashing function for it.
Note that relative and absolute paths will hash to different values,
however whether the path is suffixed with a slash or not is not
detected. This matches the existing path_compare() behaviour, and
follows the logic that on Linux there can't be two different objects at
path /foo/bar and /foo/bar/ either.
(cherry picked from commit
46e16b347f83d809ed3d34f26286f580dfd086ce)
Lennart Poettering [Thu, 8 Feb 2018 16:37:56 +0000 (17:37 +0100)]
hash-funcs: remove redundant definition of devt_hash_ops
We should assign a value only in the .c file, not in both the .c and .h
file.
(cherry picked from commit
9bac7d423f1d39737e2b7bc35c484ed0d79de73d)
Lennart Poettering [Thu, 8 Feb 2018 16:14:37 +0000 (17:14 +0100)]
journal: move code that checks for network fs to stat-util.[ch]
We have similar code in stat-util.[ch] and managing this at a central
place almost definitely is the better choice.
(cherry picked from commit
77f9fa3b8ea46c27e5a5e9270f71bf1b4000c3e0)
Shawn Landden [Sat, 3 Feb 2018 18:16:33 +0000 (10:16 -0800)]
sd-bus: cleanup ssh sessions (Closes: #8076)
we still invoke ssh unnecessarily when there in incompatible or erreneous input
The fallow-up to finish that would make the code a bit more verbose,
as it would require repeating this bit:
```
r = bus_connect_transport(arg_transport, arg_host, false, &bus);
if (r < 0) {
log_error_errno(r, "Failed to create bus connection: %m");
goto finish;
}
sd_bus_set_allow_interactive_authorization(bus, arg_ask_password);
```
in every verb, after parsing.
v2: add waitpid() to avoid a zombie process, switch to SIGTERM from SIGKILL
v3: refactor, wait in bus_start_address()
(cherry picked from commit
392cf1d05dbfa1395f6d99102e5ea41debb58fec)
Yu Watanabe [Fri, 9 Feb 2018 07:21:29 +0000 (16:21 +0900)]
sd-bus: avoid potential memory leaks
(cherry picked from commit
b4ca3f45dc5742ad76e8feebd363c490f92b804f)
Lennart Poettering [Wed, 7 Feb 2018 02:10:09 +0000 (03:10 +0100)]
process-util: use raw_getpid() in getpid_cache() internally (#8115)
We have the raw_getpid() definition in place anyway, and it's certainly
beneficial to expose the same semantics on pre glibc 2.24 and after it
too, hence always bypass glibc for this, and always cache things on our
side.
Fixes: #8113
(cherry picked from commit
996def17f99bb3f41f82032860dfcb98ff19c3ae)
Zbigniew Jędrzejewski-Szmek [Mon, 5 Feb 2018 08:48:38 +0000 (09:48 +0100)]
test: add a simple smoke test for string_hashsum()
This is enough to show memory leakages pointed out by Stef Bon <stefbon@gmail.com>.
(cherry picked from commit
bd181f27d4d0c16c500c9f49394213d1fbad1f09)
MilhouseVH [Mon, 5 Feb 2018 05:26:57 +0000 (05:26 +0000)]
kernel 3.10 compat: RTAX_QUICKACK not added until 3.11.0 (#8094)
(cherry picked from commit
ec79af69a1d159a43deb68c9ec1c31fe89743b6f)
Vito Caputo [Sat, 3 Feb 2018 11:09:08 +0000 (03:09 -0800)]
socket-util: fix getpeergroups() assert(fd) (#8080)
Don't assert on zero-value fds.
Fixes #8075.
(cherry picked from commit
75f40779607ea79f20441c7fb46744d04ee2c7ae)