Commit graph

18860 commits

Author SHA1 Message Date
Lennart Poettering 3a274a218d execute: fix type of open_terminal_as() flags parameter
It's the flags parameter we propagate here, not the mode parameter,
hence let's name it properly, and use the right type.
2017-11-17 11:13:44 +01:00
Lennart Poettering 9f617cd09f bus-unit-util: drop #ifdef HAVE_SECCOMP from bus client side
Whether seccomp is supported or not is a server implementation detail,
the client should not be altered by that, and clients should be able to talk
to servers configured differently than the client, hence drop the
HAVE_SECCOMP ifdeffery here.

(This would be different if we'd need libseccomp or so to implement the
client, but we don't)
2017-11-17 11:13:44 +01:00
Lennart Poettering da543f6a77 test: add tests for StandardInputText= and StandardInputData= 2017-11-17 11:13:44 +01:00
Lennart Poettering 08f3be7a38 core: add two new unit file settings: StandardInputData= + StandardInputText=
Both permit configuring data to pass through STDIN to an invoked
process. StandardInputText= accepts a line of text (possibly with
embedded C-style escapes as well as unit specifiers), which is appended
to the buffer to pass as stdin, followed by a single newline.
StandardInputData= is similar, but accepts arbitrary base64 encoded
data, and will not resolve specifiers or C-style escapes, nor append
newlines.

This may be used to pass input/configuration data to services, directly
in-line from unit files, either in a cooked or in a more raw format.
2017-11-17 11:13:44 +01:00
Lennart Poettering 11f5d82507 proc-cmdline: minor runlevel_to_target() coding style fixes
Let's not mix function calls and variable declarations, as well as
assignments and comparison in one expression.
2017-11-17 11:13:44 +01:00
Lennart Poettering a3ab8f2a99 hexdcoct: dump to stdout if FILE* is specified as NULL
We do a logic like that at various other places, let's do it here too,
to make this as little surprising as possible.
2017-11-17 11:13:44 +01:00
Lennart Poettering ae6e414a61 hexdecoct: slightly extend the unbase64mem() API and related
If the string length is specified as (size_t) -1, let's use that as
indicator for determining the length on our own. This makes it
slightlier shorter to invoke these APIs for a very common case.

Also, do some minor other coding style updates, and add assert()s here
and there.
2017-11-17 11:13:44 +01:00
Lennart Poettering 6bbfdc672b bus-unit-util: propagate errors where it makes sense, don't make up EINVAL
This is not only more technically correct, but also shortens our code
quite a bit.
2017-11-17 11:13:44 +01:00
Lennart Poettering a548e14d69 fd-util: add new acquire_data_fd() API helper
All this function does is place some data in an in-memory read-only fd,
that may be read back to get the original data back.

Doing this in a way that works everywhere, given the different kernels
we support as well as different privilege levels is surprisingly
complex.
2017-11-17 11:13:44 +01:00
Lennart Poettering 9bd6a50e90 core: clean up config_parse_exec_input() a bit
Mostly coding style fixes, but most importantly, initialize
c->std_input only after we know the free_and_strdup() invocation
succeeded, so that we don't leave half-initialized fields around on
failure.
2017-11-17 11:13:44 +01:00
Lennart Poettering 7fa0dcb6e3 core: drop config_parse_input() as it is unused 2017-11-17 11:13:44 +01:00
Lennart Poettering 1fb0682e78 execute: check whether we are actually on a TTY before doing TIOCSCTTY
Given that Linux assigns the same ioctl numbers ot multiple subsystems,
we should be careful when invoking ioctls, so that we don't end up
calling something we wouldn't want to call.
2017-11-17 11:13:44 +01:00
Lennart Poettering 046a82c1b2 fd-util: add new helper move_fd() and make use of it
We are using the same pattern at various places: call dup2() on an fd,
and close the old fd, usually in combination with some O_CLOEXEC
fiddling. Let's add a little helper for this, and port a few obvious
cases over.
2017-11-17 11:13:44 +01:00
Lennart Poettering 3603efdea5 nspawn: make recursive chown()ing logic safe for being aborted in the middle
We currently use the ownership of the top-level directory as a hint
whether we need to descent into the whole tree to chown() it recursively
or not. This is problematic with the previous chown()ing algorithm, as
when descending into the tree we'd first chown() and then descend
further down, which meant that the top-level directory would be chowned
first, and an aborted recursive chowning would appear on the next
invocation as successful, even though it was not. Let's reshuffle things
a bit, to make the re-chown()ing safe regarding interruptions:

a) We chown() the dir we are looking at last, and descent into all its
   children first. That way we know that if the top-level dir is
   properly owned everything inside of it is properly owned too.

b) Before starting a chown()ing operation, we mark the top-level
   directory as owned by a special "busy" UID range, which we can use to
   recognize whether a tree was fully chowned: if it is marked as busy,
   it's definitely not fully chowned, as the busy ownership will only be
   fixed as final step of the chowning.

Fixes: #6292
2017-11-17 11:12:33 +01:00
Lennart Poettering 14f8ccc755 nspawn: add missing #pragma once to header file 2017-11-17 11:12:33 +01:00
Lennart Poettering 57a4359ee0 fs-util: add access_fd() which is like access() but for fds
Linux doesn't have faccess(), hence let's emulate it. Linux has access()
and faccessat() but neither allows checking the access rights of an fd
passed in directly.
2017-11-17 11:12:33 +01:00
Zbigniew Jędrzejewski-Szmek 05d69e0294 test-cgroup-util: skip cg hierarchy tests when necessary (#7371) 2017-11-17 11:10:21 +01:00
Yu Watanabe 1bdfc7b951 core/cgroup: assigning empty string to Delegate= resets list of controllers (#7336)
Before this, assigning empty string to Delegate= makes no change to the
controller list. This is inconsistent to the other options that take list
of strings. After this, when empty string is assigned to Delegate=, the
list of controllers is reset. Such behavior is consistent to other options
and useful for drop-in configs.

Closes #7334.
2017-11-17 10:04:25 +01:00
Lennart Poettering cefdf55b58
Merge pull request #7357 from yuwata/7314-mod
mount: add "-G" as shortcut for "--property=CollectMode=inactive-or-failed"
2017-11-17 09:49:07 +01:00
Evgeny Vereshchagin 5535d8f7a9 cgroup: assume the use of v1 when all the preceding checks fail (#7366)
This patch restores the default that was changed in 2977724b09,
making the tools depending on it work again.

Closes: #6477 and https://github.com/lxc/lxc/issues/1669
2017-11-17 09:47:49 +01:00
Yu Watanabe de345d3464 mount: show which argument is invalid 2017-11-17 16:43:38 +09:00
Yu Watanabe dc3364832c mount: add "-G" as shortcut for "--property=CollectMode=inactive-or-failed" 2017-11-17 16:43:33 +09:00
Lennart Poettering fe9d0be90b run: add "-G" as shortcut for "--property=CollectMode=inactive-or-failed"
This option is likely to be very useful for systemd-run invocations,
hence let's add a shortcut for it.

With this new concepts it's now very easy to put together systemd-run
invocations that leave zero artifacts in the system, including when they
fail.
2017-11-16 14:38:36 +01:00
Lennart Poettering 5afe510c89 core: add a new unit file setting CollectMode= for tweaking the GC logic
Right now, the option only takes one of two possible values "inactive"
or "inactive-or-failed", the former being the default, and exposing same
behaviour as the status quo ante. If set to "inactive-or-failed" units
may be collected by the GC logic when in the "failed" state too.

This logic should be a nicer alternative to using the "-" modifier for
ExecStart= and friends, as the exit data is collected and logged about
and only removed when the GC comes along. This should be useful in
particular for per-connection socket-activated services, as well as
"systemd-run" command lines that shall leave no artifacts in the
system.

I was thinking about whether to expose this as a boolean, but opted for
an enum instead, as I have the suspicion other tweaks like this might be
a added later on, in which case we extend this setting instead of having
to add yet another one.

Also, let's add some documentation for the GC logic.
2017-11-16 14:38:36 +01:00
Lennart Poettering 7eb2a8a125 unit: rework a bit how we keep the service fdstore from being destroyed during service restart
When preparing for a restart we quickly go through the DEAD/INACTIVE
service state before entering AUTO_RESTART. When doing this, we need to
make sure we don't destroy the FD store. Previously this was done by
checking the failure state of the unit, and keeping the FD store around
when the unit failed, under the assumption that the restart logic will
then get into action.

This is not entirely correct howver, as there might be failure states
that will no result in restarts.

With this commit we slightly alter the logic: a ref counter for the fd
store is added, that is increased right before we handle the restart
logic, and decreased again right-after.

This should ensure that the fdstore lives exactly as long as it needs.

Follow-up for f0bfbfac43.
2017-11-16 14:37:33 +01:00
Zbigniew Jędrzejewski-Szmek 88bff42450 test-unit-file: add test for config_parse_log_extra_fields() 2017-11-16 12:40:17 +01:00
Lennart Poettering d3070fbdf6 core: implement /run/systemd/units/-based path for passing unit info from PID 1 to journald
And let's make use of it to implement two new unit settings with it:

1. LogLevelMax= is a new per-unit setting that may be used to configure
   log priority filtering: set it to LogLevelMax=notice and only
   messages of level "notice" and lower (i.e. more important) will be
   processed, all others are dropped.

2. LogExtraFields= is a new per-unit setting for configuring per-unit
   journal fields, that are implicitly included in every log record
   generated by the unit's processes. It takes field/value pairs in the
   form of FOO=BAR.

Also, related to this, one exisiting unit setting is ported to this new
facility:

3. The invocation ID is now pulled from /run/systemd/units/ instead of
   cgroupfs xattrs. This substantially relaxes requirements of systemd
   on the kernel version and the privileges it runs with (specifically,
   cgroupfs xattrs are not available in containers, since they are
   stored in kernel memory, and hence are unsafe to permit to lesser
   privileged code).

/run/systemd/units/ is a new directory, which contains a number of files
and symlinks encoding the above information. PID 1 creates and manages
these files, and journald reads them from there.

Note that this is supposed to be a direct path between PID 1 and the
journal only, due to the special runtime environment the journal runs
in. Normally, today we shouldn't introduce new interfaces that (mis-)use
a file system as IPC framework, and instead just an IPC system, but this
is very hard to do between the journal and PID 1, as long as the IPC
system is a subject PID 1 manages, and itself a client to the journal.

This patch cleans up a couple of types used in journal code:
specifically we switch to size_t for a couple of memory-sizing values,
as size_t is the right choice for everything that is memory.

Fixes: #4089
Fixes: #3041
Fixes: #4441
2017-11-16 12:40:17 +01:00
Lennart Poettering 131819424d journald: when logging about dropped messages, include more meta data
When we drop messages of a unit, we log about. Let's add some structured
data to that. Let's include how many messages we dropped, but more
importantly, let's link up the message we generate to the unit we
dropped the messages from by using the "OBJECT" logic, i.e. by
generating OBJECT_SYSTEMD_UNIT= fields and suchlike, that "journalctl
-u" and friends already look for.

Fixes: #6494
2017-11-16 12:40:17 +01:00
Lennart Poettering 500cbc4e9e journal: reindent field mapping tables
Let's fix up whitespace so that the tables look nicely aligned.
2017-11-16 12:40:17 +01:00
Lennart Poettering dde2637476 journal: make use of IOVEC_MAKE() where it makes sense 2017-11-16 12:40:17 +01:00
Lennart Poettering 53978b98f9 journal: move valid_user_field() to journal-util.[ch] and rename it → journal_field_valid()
Being able to validate journal field names is useful outside of the
journal itself.
2017-11-16 12:40:17 +01:00
Lennart Poettering eabd4eb934
Merge pull request #7356 from keszybz/cgroup-and-manager-cleanups
Cgroup and manager cleanups
2017-11-16 11:37:20 +01:00
Franck Bui 4cef192357 tmpfiles: when /etc is not fully initialized, some specifiers are expected to be unresolvable (#6860)
In chroot environments, /etc might not be fully initialized: /etc/machine-id
can be missing for example. This makes the expansions of affected specifiers
impossible at that time.

These cases should not be considered as errors and such failures shouldn't be
logged at an error level therefore this patch downgrades the level used to
LOG_NOTICE in such cases.

Also this is logged at LOG_NOTICE only the first time and then downgrade to
LOG_DEBUG for the rest. That way, if debugging is enabled we get the full
output, but otherwise we only see only one message.

The expansion of specifiers is now self contained in a dedicated function
instead of being spread all over the place.
2017-11-16 11:27:29 +01:00
Alan Jenkins 28abce5d25 systemctl: other wayland sessions should inhibit shutdown, like x11 sessions do (#7353)
Update systemctl code to match the manpage for sd_session_get_type().

"wayland" sessions should be treated the same as "x11".  "mir" too, fwiw.
2017-11-16 11:02:34 +01:00
Stefan Agner 8006aa32ee sd-dhcp6-client: Implement FQDN Option (#7309)
Implement DHCPv6 option to exchange information about the Fully
Qualified Domain Name (FQDN) according to RFC 4704.

The RFC 4704 describes two models of operations in section 3,
currently only the second model is supported (DHCPv6 server
updates both the AAAA and the PTR RRs).

The existing DHCP Section Options SendHostname and Hostname are
sent as FQDN to the server. According to section 4.2 sending
only parts of its FQDN is allowed.

Fixes #4682.
2017-11-16 10:07:07 +01:00
Stefan Agner 9740eae694 sd-dhcp-client: validate hostnames stricter (#7308)
Technically DNS allows any ASCII character to be used in the
domain name. Also the DHCP specification for the FQDN option
(RFC 4702) does not put restriction on labels.

However, hostnames do have stricter requirements and typically
should only use characters from a-z (case insensitve), 0-9 and
minus.

Currently we require hostname/FQDN to be either a hostname or
a valid DNS name. Since dns_name_is_valid() allows any ASCII
characters this allows to specify hostnames which are typically
not valid.

Check hostname/FQDN more strictly and require them to pass both
tests. Specifically this requires the entire FQDN to be below 63.
2017-11-16 10:05:44 +01:00
Zbigniew Jędrzejewski-Szmek 17f01ace62 core/manager: just return an error if we fail halfway
We would continue, but still return an error at the end. This isn't useful
because we'd still error-out in main().

Also, add a missing error message when we fail to mkdir.
2017-11-15 22:58:24 +01:00
Zbigniew Jędrzejewski-Szmek d4c819ed23 core: fix message about detected memory hierarchy
Just the error check and message were wrong, otherwise the logic was OK.
2017-11-15 22:58:24 +01:00
Zbigniew Jędrzejewski-Szmek 073e8f0956 test-cgroup-util: add basic test for cg_all_unified/cg_hybrid_unified/cg_unified_controller 2017-11-15 22:58:24 +01:00
Zbigniew Jędrzejewski-Szmek 9aa2113365 util-lib: add debug messages when checking cgroup layout
This has become very complex, let's make it a bit easier to diagnose.
2017-11-15 22:58:24 +01:00
Zbigniew Jędrzejewski-Szmek 47a78d4102 Use plural DelegateControllers= consistently 2017-11-15 22:58:24 +01:00
Lennart Poettering 0986658d51
Merge pull request #6866 from sourcejedi/set-linger2
logind: fix `loginctl enable-linger`
2017-11-15 11:15:15 +01:00
Lennart Poettering f6e11b394e core: fix bus property logic for RequiresMountsFor= dependencies (#7332)
We get a pointer to a pointer to a Hashmap, instead of just a pointer to
a Hashmap, let's handle that properly.
2017-11-14 21:50:59 +01:00
Zbigniew Jędrzejewski-Szmek 5aa9556306
Merge pull request #7313 from keszybz/msgformat
i18n: drop intltool use, use meson's merge_file directly
2017-11-14 21:48:42 +01:00
Michal Sekletar 56692c5dbc udev: net_setup_link: don't error out when we couldn't apply link config (#7328)
It is possible that kernel will reject our netlink message that
configures the link. However, we should always make sure that interface
will be named properly otherwise we can leave interfaces having
unpredictable kernel names. Thus we don't return early and continue to
export name and link file properties.

Suggested-by: Tom Gundersen <teg@jklm.no>
2017-11-14 19:29:37 +01:00
Alan Jenkins 34160d9195 logind: fix SetLinger to authorize by client's effective User ID
SetLinger is authorized by the PolicyKit action "set-self-linger", if it is
not passed an explicit UID.

According to comments we were determining the default UID from the client's
session.  However, user processes e.g. which are run from a terminal
emulator do not necessarily belong to a session scope unit.  They may
equally be started from the systemd user manager [1][2].  Actually the
comment was wrong, and it would also have worked for processes
started from the systemd user manager.

Nevertheless it seems to involve fetching "augmented credentials" i.e.
it's using a racy method, so we shouldn't have been authenticating based
on it.

We could change the default UID, but that raises issues especially for
consistency between the methods.  Instead we can just use the clients
effective UID for authorization.

This commit also fixes `loginctl enable-linger $USER` to match the docs
that say it was equivalent to `loginctl enable-linger` (given that $USER
matches the callers user and owner_uid).  Previously, the former would not
have suceeded for unpriviliged users in the default configuration.

[1] It seems the main meaning of per-session scopes is tracking the PAM
login process.  Killing that provokes logind to revoke device access.  Less
circularly, killing it provokes getty to hangup the TTY.

[2] User units may be started with an environment which includes
XDG_SESSION_ID (presuambly GNOME does this?).  Or not.
2017-11-14 18:15:33 +00:00
Alan Jenkins 545f779f5c loginctl: enable-linger does not need fallback to XDG_SESSION_ID
To maintain consistency with `loginctl user-status`, drop the fallback to
XDG_SESSION_ID for `loginctl enable-linger`.  The fallback was unnecessary
and also incorrect: it passed the numeric value of the session identifier
as a UID value.
2017-11-14 18:15:33 +00:00
Alan Jenkins 7b33c6228f logind: comment use of *_get_session()
The manpages tell that such calls have quite limited meaning.  logind has
a few in the implementation of what remains of the session concept.

At the same time, logind basically exposes sd_pid_get_session() as public
API.  This is absolutely required, to retain compatability e.g. with Xorg.
But client code will work in more situations if it avoids assuming that it
runs in a session itself.

Its use inside the login session could be replaced with $XDG_SESSION_ID
(which pam_systemd sets).  I don't know whether it would be useful to
change Xorg at this point or not.  But if you were building something new,
you would think about whether you want to support running it in a systemd
service.

Comment these logind API features, acknowledging the reason they exist is
based in history.  I.e. help readers avoid drawing implications from their
existence which apply to history, but not the current general case.

Finally, searching these revealed a call to sd_pid_get_session() in
implementing some types of logind inhibitors.  So these inhibitors don't
work as intended when taken from inside a systemd user service :(.  Comment
this as well, deferring it as ticket #6852.
2017-11-14 18:15:33 +00:00
Alan Jenkins 095b8833d6 logind: more specific error message for unknown users
If you try to run `loginctl user-status` on a non-logged in user to see
whether "Linger" is enabled, it doesn't work.

If you're already an expert in logind, the fact that the user is considered
unknown actually tells you the user is not lingering.  So, probably they
they do not have lingering enabled.  I think we can point towards this
without being misleading.

I also reword it because I thought it was slightly confusing to run
`loginctl user-status root` and get an error back about "User 0".  Try to
be more specific, that it is "User ID 0".
2017-11-14 18:15:33 +00:00
Alan Jenkins e4d2984bf8 logind: "self" objects which do not apply - return specific error messages
It's confusing that the bus API has aliases like "session/self" that return
an error based on ENXIO, when it also has methods that return e.g.
NO_SESSION_FOR_PID for the same problem.  The latter kind of error includes
more specifically helpful messages.

"user/self" is the odd one out; it returns a generic UnknownObject error
when it is not applicable to the caller.  It's not clear whether this was
intentional, but at first I thought it was more correct.  More
specifically, user_object_find() was returning 0 for "user/self", in the
same situations (more or less) where user_node_enumerator() was omitting
"user/self".  I thought that was a good idea, because returning e.g. -ENXIO instead
suggested that there _is_ something specific on that path.  And it could be
confused with errors of the method being called.

Therefore I suggested changing the enumerator, always admitting that there
is a handler for the path "foo/self", but returning a specific error when
queried.  However this interacts poorly with tools like D-Feet or `busctl`.
In either tool, looking at logind would show an error message, and then go
on to omit "user/self" in the normal listing.  These tools are very useful,
so we don't want to interfere with them.

I think we can change the error codes without causing problems.  The self
objects were not listed in the documentation.  They have been suggested to
other projects - but without reference to error reporting.  "seat/self" is
used by various Wayland compositors for VT switching, but they don't appear
to reference specific errors.

We _could_ insist on the link between enumeration and UnknownObject, and
standardize on that as the error for the aliases.  But I'm not aware of any
practical complaints, that we returned an error from an object that didn't
exist.

Instead, let's unify the codepaths for "user/self" vs GetUserByPid(0) etc.
We will return the most helpful error message we can think of, if the
object does not exist.  E.g. for "session/self", we might return an error
that the caller does not belong to a session.  If one of the compositors is
ever simplified to use "session/self" in initialization, users would be
able to trigger such errors (e.g. run `gnome-shell` inside gnome-terminal).
The message text will most likely be logged.  The user might not know what
the "session" is, but at least we'll be pointing towards the right
questions.  I think it should also be clearer for development / debugging.

Unifying the code paths is also slightly helpful for auditing / marking
calls to sd_bus_creds_get_session() in subsequent commits.
2017-11-14 18:15:22 +00:00
Alan Jenkins aeb075704b logind: remove an obscure dbus error from GetSessionByPID(0) and friends
GetSessionByPID(0) can fail with NO_SESSION_FOR_PID.  More obscurely, if
the session is abandoned, it can return NO_SUCH_SESSION.  It is not clear
that the latter was intended.  The message associated with the former,
hints that this was overlooked.

We don't have a document enumerating the errors.  Any specific
error-handling in client code, e.g. translated messages, would also be
liable to overlook the more obscure error code.

I can't see any equivalent condition for GetUserByPID(0).  On the other
hand, the code did not return NO_USER_FOR_PID where it probably should.
The relevant code is right next to that for GetSessionByPID(0), so it will
be simpler to understand if both follow the same pattern.
2017-11-14 18:12:42 +00:00
Lennart Poettering 9efebb65d4
busctl: fix minor memory leak in busctl (#7331)
Fixes: #7330
2017-11-14 17:59:50 +01:00
Zbigniew Jędrzejewski-Szmek d79a2f5fab po: add a copy of polkit its rules
It's just a few lines, but this way we avoid a dependency on polkit, and
can use meson's i18n stuff on older distros.
2017-11-14 16:18:27 +01:00
Yu Watanabe 99c1401807 core/dbus-unit: add property_get_requires_mounts_for() to send correct message (#7322)
PR #7186 changes requires_mounts_for from strv to Hashmap.
So, it is necessary to implement a function for getting the property RequiresMountsFor=.
This introduces property_get_requires_mounts_for() which reads the Hashmap
and sends messages to bus.

Fixes #7321.
2017-11-14 09:01:21 +01:00
Zeal Jagannatha ab0fc8711b Fix error message when binding files (#7196)
If you use machinectl to bind a file into a container, it responds with a confusing error message about a temporary directory not being a directory.

I just swapped it to error with the source that was passed, rather than the tmpdir.

It would also be nice to be able to bind files, but that's a separate issue (#7195).

Before the change:

root@epona /var/lib/sandbox $ cat bar/foo 
Hello world!
root@epona /var/lib/sandbox $ machinectl bind testing /var/lib/sandbox/bar/foo /foo
Failed to bind mount: Failed to overmount /tmp/propagate.W5TNsj/mount: Not a directory

After the change:

root@epona /var/lib/sandbox $ machinectl bind testing /var/lib/sandbox/bar/foo /foo
Failed to bind mount: Failed to overmount /var/lib/sandbox/bar/foo: Not a directory
2017-11-14 08:11:41 +01:00
Lennart Poettering 861f16d267 systemctl: print a friendly message when systemctl is invoked, but PID 1 is not systemd (#7318)
We only show this message when we can't talk to systemd, so that client
side install can work.

Fixes: https://bugzilla.freedesktop.org/show_bug.cgi?id=69962
2017-11-13 22:03:32 +01:00
Lennart Poettering ab8519c28b core: only warn about BPF/cgroup missing once per runtime (#7319)
Let's reduce the amount of noise a bit, there's little point in
complaining loudly about every single unit like this, let's complain
only about the first one, and then downgrade the log level to LOG_DEBUG
for the other cases.

Fixes: #7188
2017-11-13 22:02:51 +01:00
Topi Miettinen 9c6888ac45 basic: remove redundant check (#7320)
The check is redundant as the whole block is only evaluated if
__IGNORE_pkey_mprotect is not defined. Change to #else.
2017-11-13 22:00:03 +01:00
Zbigniew Jędrzejewski-Szmek c81217920e i18n: drop intltool use, use meson's merge_file directly
This didn't work during the initial conversion to meson, but should now.
A sufficiently new polkit is also required, for the .its rules files.

Note that https://github.com/mesonbuild/meson/blob/master/docs/markdown/i18n-module.md
says that 'install' argument was added in meson 0.43.0. If this is accurate,
warnigs might be generated with older mesons. Fedora has 0.43.0 across the
board, but other distros probably don't, but I guess that a warning is
prefereable to having to update do latest meson.

The advantages are:
- one less dependency (intltool)
- using the generic implementation instead of our open-coded calls
- we don't need to use the fake "_" prefixes in XML

Replaces #1609, fixes #7300.
2017-11-13 21:35:28 +01:00
Lennart Poettering f38326f21a
Merge pull request #7284 from poettering/cgroup-delegate-mask
add a concept of delegating cgroups per unit while enabling specific controllers
2017-11-13 12:14:23 +01:00
Lennart Poettering 10d67460f5 install: drop redundant printing of unit name (#7296)
We already print it as part of log_syntax() internal logic, don't print
it again, and in particular, don't print it at the end of log line, such
a strange place.

Follow-up for: 142468d895
2017-11-13 11:12:01 +01:00
Lennart Poettering 93e93da5cc
bpf-firewall: properly handle kernels where BPF cgroup is disabled but TRIE maps are enabled (#7298)
So far, we assumed that kernels where TRIE was on also supported
BPF/cgroup stuff. That's not a correct assumption to make, hence check
for both features separately.

Fixes: #7054
2017-11-13 10:56:43 +01:00
Lennart Poettering bd1750f7fe
Merge pull request #7310 from keszybz/missing-pkey_mprotect
basic/missing: add numbers for pkey_mprotect
2017-11-13 10:55:00 +01:00
Lennart Poettering 0263828039 core: rework the Delegate= unit file setting to take a list of controller names
Previously it was not possible to select which controllers to enable for
a unit where Delegate=yes was set, as all controllers were enabled. With
this change, this is made configurable, and thus delegation units can
pick specifically what they want to manage themselves, and what they
don't care about.
2017-11-13 10:49:15 +01:00
Lennart Poettering 800f478c2f core: downgrade a log message from error to warning
Messages that do not indicate a failing operation, but where we continue
operation should be at LOG_WARN, not at LOG_ERR.
2017-11-13 10:49:15 +01:00
Lennart Poettering 7546145e26 string-util: add delete_trailing_chars() and skip_leading_chars() helpers
And let's port over a couple of users to the new APIs.
2017-11-13 10:47:15 +01:00
Lennart Poettering 78f3c4bca5 conf-parser: reindent some strangely indented function headers 2017-11-13 10:24:03 +01:00
Lennart Poettering bcde742e78 conf-parser: turn three bool function params into a flags fields
This makes things more readable and fixes some issues with incorrect
flag propagation between the various flavours of config_parse().
2017-11-13 10:24:03 +01:00
Lennart Poettering 92b5e60542 conf-parser: simplify things a bit by using strextend() 2017-11-13 10:24:03 +01:00
Lennart Poettering 57d6f70019 fileio: make use of DEFINE_TRIVIAL_CLEANUP_FUNC where it makes sense 2017-11-13 10:24:03 +01:00
Lennart Poettering 3160497017 cgroup: make use of unit_get_subtree_mask() where appropriate
subtree_mask is own_mask | members_mask, let's make use of that to
shorten a few things
2017-11-13 10:24:03 +01:00
Lennart Poettering ec635a2d21 cgroup: improve cg_mask_to_string a bit, and add tests for it 2017-11-13 10:24:03 +01:00
Lennart Poettering 00b4a24743 cgroup-util: add brief comments clarifying which controllers are v2-only and which v1-only 2017-11-13 10:24:03 +01:00
Lennart Poettering 4e0c20de97 namespace: set up OS hierarchy only after mounting the new root, not before
Otherwise it's a pointless excercise, as we'll set up an empty directory
tree that's never going to be used.

Hence, let's move this around a bit, so that we do the basesystem
initialization exactly when RootImage= or RootDirectory= are used, but
not otherwise.
2017-11-13 10:22:36 +01:00
Robin McCorkell 521cdf01e4 Fix creating independent VTI tunnel (#7303) 2017-11-13 10:14:36 +01:00
Zbigniew Jędrzejewski-Szmek 91691f1d3e shared/seccomp: skip pkey_mprotect protections if the syscall is unknown
When compiling with an old kernel on architectures for which the
number is not defined in missing.h, a warning is generated in missing.h.
Let's just skip the protection in this case, to allow build to proceed.
2017-11-13 09:35:49 +01:00
Zbigniew Jędrzejewski-Szmek 213f2883c0 basic/missing: add numbers for pkey_mprotect
Follow-up for b835eeb4ec.
2017-11-13 09:27:53 +01:00
Zbigniew Jędrzejewski-Szmek b835eeb4ec
shared/seccomp: disallow pkey_mprotect the same as mprotect for W^X mappings (#7295)
MemoryDenyWriteExecution policy could be be bypassed by using pkey_mprotect
instead of mprotect to create an executable writable mapping.

The impact is mitigated by the fact that the man page says "Note that this
feature is fully available on x86-64, and partially on x86", so hopefully
people do not rely on it as a sole security measure.

Found by Karin Hossen and Thomas Imbert from Sogeti ESEC R&D.

https://bugs.launchpad.net/bugs/1725348
2017-11-12 17:28:48 +01:00
Lennart Poettering ce5faeac1f seccomp: include ARM set_tls in @default (#7297)
Fixes: #7135
2017-11-12 16:34:43 +01:00
Lennart Poettering aa2b10daec networkd: improve interface rename log message a bit (#7299)
Let's clarify that it's not networkd that renames interfaces, but
something else (for example, udev's link builtin based on .link files)

This doesn't change any logic, it just rewords the message a bit, to
clarify that we only log this for informational purposes, not because we
execute the rename operation ourselves.

Fixes: #7143
2017-11-12 16:26:58 +01:00
Zbigniew Jędrzejewski-Szmek edc3eff50f
Merge pull request #7301 from poettering/loginctl-ellipsize
Fix loginctl seat sysfs tree ellipsation logic.

Simple reproducer:
loginctl --full seat-status seat0|cat
→ after this PR, all lines are shown in full. Before, lines were ellipsized to terminal width.
2017-11-12 16:25:54 +01:00
Zbigniew Jędrzejewski-Szmek f886559e55
Merge pull request #7186 from poettering/track-deps
rework unit dependency data structure to track why deps get created
2017-11-12 16:14:41 +01:00
Yu Watanabe 74b1731c75 core/mount: fstype may be NULL 2017-11-12 14:27:25 +01:00
Lennart Poettering ecd48322c2 core: sd-bus can handle NULL strings nicely, let's use it
No need to set an empty string here, sd-bus serializes NULL as empty
string anway.
2017-11-12 14:27:19 +01:00
Yu Watanabe 7a18854fe7 test-execute: update test for SystemCallErrorNumber= 2017-11-11 21:54:29 +09:00
Yu Watanabe 3df90f24cc core: allow to specify errno number in SystemCallErrorNumber= 2017-11-11 21:54:24 +09:00
Yu Watanabe b4891260b9 test: add tests for syscall:errno style in SystemCallFilter= 2017-11-11 21:54:20 +09:00
Yu Watanabe 8cfa775f4f core: add support to specify errno in SystemCallFilter=
This makes each system call in SystemCallFilter= blacklist optionally
takes errno name or number after a colon. The errno takes precedence
over the one given by SystemCallErrorNumber=.

C.f. #7173.
Closes #7169.
2017-11-11 21:54:12 +09:00
Yu Watanabe 473d2ec39c test: add test for parse_errno() and parse_syscall_and_errno() 2017-11-11 21:53:56 +09:00
Yu Watanabe cf26c4a722 parse-util: add parse_errno() and parse_syscall_and_errno() 2017-11-11 21:29:17 +09:00
Yu Watanabe 1850d0d271 basic/errno-list: remove errno_max() and define ERRNO_MAX as 4095
In Linux kernel code, MAX_ERRNO is defined as 4095.
Here, we use that value for ERRNO_MAX.
2017-11-11 21:28:25 +09:00
Lennart Poettering 3850319be5 loginctl: rework sysfs tree dump, to honour --full and friends
Let's hook up the sysfs tree output with the output flags logic,
already used when dumping log lines or process trees. This way we get
very similar output handling for line breaking/ellipsation in all three
outputs of structured data.

Fixes: #7095
2017-11-10 21:44:29 +01:00
Lennart Poettering ddbc931986 string-util: when ellipsizing to a length if (size_t) -1, become a NOP
Let's say that (size_t) -1 (i.e. SIZE_T_MAX) is equivalent to
"unbounded" ellipsation, i.e. ellipsation as NOP. In which case the
relevant functions become little more than strdup()/strndup().

This is useful to simplify caller code in case we want to turn off
ellipsation in certain code paths with minimal caller-side handling for
this.
2017-11-10 21:41:53 +01:00
Lennart Poettering 459b9f9ff7 merge two lines in our get_output_flags() functions
loginctl, machinectl, systemctl all have very similar implementations of
a get_output_flags() functions. Simplify it by merging two lines that
set the same flag.
2017-11-10 21:40:47 +01:00
Lennart Poettering 0b3c84eb7d tree-wide: use _cleanup_(sd_bus_flush_close_unrefp) at various appropriate places
Let's shorten the code a bit.
2017-11-10 21:15:44 +01:00
Lennart Poettering d13b522751 pager: cache not only number of columns but also of lines before we open pager
Not that we need it, but let's do this as matter of completeness.
2017-11-10 21:10:17 +01:00
Lennart Poettering 9e29521e27 loginctl: invoke sigbus_install()
We show journal data, hence we should install the SIGBUS handler.

Similar for machinectl, where the same applies.
2017-11-10 21:09:13 +01:00
Lennart Poettering 3e3852b3c6 core: make "tmpfs" dependencies on swapfs a "default" dep, not an "implicit"
There should be a way to turn this logic of, and DefaultDependencies=
appears to be the right option for that, hence let's downgrade this
dependency type from "implicit" to "default, and thus honour
DefaultDependencies=.

This also drops mount_get_fstype() as we only have a single user needing
this now.

A follow-up for #7076.
2017-11-10 19:52:41 +01:00
Lennart Poettering dcebc9bae4 core: when a unit template is specified in SYSTEMD_WANTS=, instantiate it with sysfs path
This should make cases like the user's setup in #7109 a lot easier to
handle, as in that case we'll do the right escaping automatically.
2017-11-10 19:52:41 +01:00
Lennart Poettering 38b9b72ec1 core: remove SYSTEMD_WANTS udev property configured dependencies at the right moment
Previously dependencies configured with SYSTEMD_WANTS would be collected
on a device unit as long as it was loaded. let's fix that, and remove
dependencies again when SYTEMD_WANTS changes.
2017-11-10 19:45:29 +01:00
Lennart Poettering de04054349 device: Let's simplify device_add_udev_wants() a bit
Let's drop use of one variable and make the rest more explicit.
2017-11-10 19:45:29 +01:00
Lennart Poettering c999cf385a core: add internal API to remove dependencies again, based on dependency mask
let's make use of the dependency mask, and add internal API to remove
dependencies ago, based on bits in the dependency mask.
2017-11-10 19:45:29 +01:00
Lennart Poettering 40b1a32ca8 device: rework device_is_bound_by_mounts() a bit
Let's log when we can't parse the udev property, and always use the most
precise, correct types.
2017-11-10 19:45:29 +01:00
Lennart Poettering eef85c4a3f core: track why unit dependencies came to be
This replaces the dependencies Set* objects by Hashmap* objects, where
the key is the depending Unit, and the value is a bitmask encoding why
the specific dependency was created.

The bitmask contains a number of different, defined bits, that indicate
why dependencies exist, for example whether they are created due to
explicitly configured deps in files, by udev rules or implicitly.

Note that memory usage is not increased by this change, even though we
store more information, as we manage to encode the bit mask inside the
value pointer each Hashmap entry contains.

Why this all? When we know how a dependency came to be, we can update
dependencies correctly when a configuration source changes but others
are left unaltered. Specifically:

1. We can fix UDEV_WANTS dependency generation: so far we kept adding
   dependencies configured that way, but if a device lost such a
   dependency we couldn't them again as there was no scheme for removing
   of dependencies in place.

2. We can implement "pin-pointed" reload of unit files. If we know what
   dependencies were created as result of configuration in a unit file,
   then we know what to flush out when we want to reload it.

3. It's useful for debugging: "systemd-analyze dump" now shows
   this information, helping substantially with understanding how
   systemd's dependency tree came to be the way it came to be.
2017-11-10 19:45:29 +01:00
Lennart Poettering 8f50e86a86 gpt-auto-generator: make sure "r" is always set 2017-11-10 19:00:06 +01:00
Lennart Poettering e37fae1ea0 core: include a bad /var/run symlink in the "tainted" string 2017-11-10 19:00:06 +01:00
Lennart Poettering 45e1c7d5ca virt: trivial whitespace fixes 2017-11-10 19:00:06 +01:00
Boucman f332611abe device : reload when udev generates a "changed" event (#6850) 2017-11-10 17:00:32 +01:00
Lennart Poettering 8d644046d9
Merge pull request #7089 from oniko/luks2-support
LUKS2 support for systemd-cryptsetup and dissect-image
2017-11-10 16:16:36 +01:00
juga0 28522b0d8c networkd: set dhcp_use_routes to true when dhcp_anonymize is true (#7209)
It does not send duplicated options in the PRL.
Fix #7048.
2017-11-10 16:03:43 +01:00
Alan Jenkins 9b9881d75b core: add missing error_message cases (#6911)
We neglected to set error_message for errors which occur _after_ the
`finish` label.  These fatal errors only happen in paths where `finish`
was reached successfully, i.e. error_message has not already been set
(and this analysis is simple enough that this need not cause too much
headaches.  Also our new assignments to error_message come immediately
after execve() calls, which would have lost the error_message if it had
been set).

Also print a status message when we fail to exec init, otherwise the only
sign the user will see is `# ` :).

This addresses the lack of error messages pointed out in issue #6827.
2017-11-10 15:57:52 +01:00
Lennart Poettering 67595fce2d
Merge pull request #7096 from keszybz/logind-session-killing
Logind session killing fix
2017-11-10 15:51:39 +01:00
Zbigniew Jędrzejewski-Szmek 556c7bae0c basic/hashmap: add cleanup of memory pools (#7164)
It was dropped in 89439d4fc0. As a result, every
process that uses a hashmap allocates and then leaks the hashmap mempools.
The mempools are only allocated in the main thread, but we don't know where
the memory is used.

So let's check if we are the last thread and free the mempools then. This is
fairly heavy, because /proc/self/status has to be opened and parsed, but we do
it only when compiled for valgrind, i.e. not by default, and compared to running
under valgrind or asan, the extra cost is acceptable. The big advantage is that
we don't have to think or filter out this false positive.

As a micro-opt, cleanup is attempted only in the main thread. We could allow
any thread to check if it is the last one and perform cleanup, but that'd mean
that we'd have to _do_ the check in every thread. We don't use threads like
that, our non-main threads are always short-lived, so let's just accept the
possibility that we'll leak memory if a thread survives. The check is also
non-atomic, but it's called in a destructor of the main thread _and_ we do
cleanup only when there are no other threads, so the risk of some library
suddenly spawning another thread is very low. All in all, this is not perfect,
but should work in 999‰ of cases.

Fixes the following valgrind warning:

==22564== HEAP SUMMARY:
==22564==     in use at exit: 8,192 bytes in 2 blocks
==22564==   total heap usage: 243 allocs, 241 frees, 151,905 bytes allocated
==22564==
==22564== 4,096 bytes in 1 blocks are still reachable in loss record 1 of 2
==22564==    at 0x4C2FB6B: malloc (vg_replace_malloc.c:299)
==22564==    by 0x4F08A8C: mempool_alloc_tile (mempool.c:62)
==22564==    by 0x4F08B16: mempool_alloc0_tile (mempool.c:81)
==22564==    by 0x4EF8DE0: hashmap_base_new (hashmap.c:748)
==22564==    by 0x4EF8ED9: internal_hashmap_new (hashmap.c:782)
==22564==    by 0x11045D: test_hashmap_copy (test-hashmap-plain.c:87)
==22564==    by 0x115722: test_hashmap_funcs (test-hashmap-plain.c:914)
==22564==    by 0x10FC9D: main (test-hashmap.c:60)
==22564==
==22564== 4,096 bytes in 1 blocks are still reachable in loss record 2 of 2
==22564==    at 0x4C2FB6B: malloc (vg_replace_malloc.c:299)
==22564==    by 0x4F08A8C: mempool_alloc_tile (mempool.c:62)
==22564==    by 0x4F08B16: mempool_alloc0_tile (mempool.c:81)
==22564==    by 0x4EF8DE0: hashmap_base_new (hashmap.c:748)
==22564==    by 0x4EF8EF8: internal_ordered_hashmap_new (hashmap.c:786)
==22564==    by 0x10A2A0: test_ordered_hashmap_copy (test-hashmap-ordered.c:89)
==22564==    by 0x10F70F: test_ordered_hashmap_funcs (test-hashmap-ordered.c:916)
==22564==    by 0x10FCA2: main (test-hashmap.c:61)
==22564==
==22564== LEAK SUMMARY:
==22564==    definitely lost: 0 bytes in 0 blocks
==22564==    indirectly lost: 0 bytes in 0 blocks
==22564==      possibly lost: 0 bytes in 0 blocks
==22564==    still reachable: 8,192 bytes in 2 blocks
==22564==         suppressed: 0 bytes in 0 blocks

v2:
- check if we are the main thread

v3:
- check if there are no other threads
2017-11-10 15:44:58 +01:00
Antonio Rojas 8e6a7a8b2b Fix typo in statx macro (#7180)
This makes statx properly whitelisted in supported systems.
2017-11-10 11:07:36 +01:00
John Lin ff21046656 systemctl: fix memory leak (#7289)
Fixes: #7283
2017-11-10 10:32:25 +01:00
tblume ed457f1380 systemd-firstboot: add vconsole keymap support (#7035)
Enable systemd-firstboot to set the keymap.

RFE:

https://github.com/systemd/systemd/issues/6346
2017-11-10 10:31:44 +01:00
Yu Watanabe c54515b1e4 core/load-fragment: add RemoveIPC= (#7288)
PR #3865 introduced RemoveIPC= but the option is not listed in
load-fragment-gperf.gperf. So, the option could be used only via d-bus.
This adds RemoveIPC= in load-fragment-gperf.gperf. Then, now we can
set the option in unit files.

Fixes #7281.
2017-11-10 10:15:55 +01:00
Lennart Poettering 4deff0b92b
Merge pull request #7280 from yuwata/fix-7270-2
test-event: do not work in assert()
2017-11-09 14:26:42 +01:00
Lukáš Nykrýn f7576eb9fd cryptsetup: ignore _netdev, since it is used in generator (#7282) 2017-11-09 14:24:57 +01:00
Yu Watanabe 3fcf65c352 test-parse-util: add more tests, mainly for empty string 2017-11-09 18:39:50 +09:00
Yu Watanabe ccd1fc2f69 libsystemd-network: coding style fix 2017-11-09 18:39:41 +09:00
Yu Watanabe 1950011227 tree-wide: do not work in assert()
Follow-up for 85e55d14de.
2017-11-09 18:38:02 +09:00
Lennart Poettering f5f0dca0ce
Merge pull request #7112 from tstellar/udev-for-kfd
udev-rules: Add rules for /dev/kfd
2017-11-09 09:22:55 +01:00
Dimitri John Ledkov 02ec6e04fd test-bpf: use /bin/ping path (#7276)
This path to ping is compatible with both debian-like and usr-merged
distros. This keeps the test simple, and should thus pass everywhere.

Fixes: #7267
2017-11-08 20:04:55 +01:00
John Lin 142468d895 systemctl: respect [Install] section in drop-ins (#7158)
Fixes: #7114
2017-11-08 18:04:31 +01:00
Lennart Poettering f9007887a6
Merge pull request #7268 from yuwata/rfe-7262
timesync: make poll interval configurable
2017-11-08 17:35:56 +01:00
Lennart Poettering 376065ee26
Merge pull request #7275 from yuwata/fix-7070-7260
core: fixes related to RuntimeDirectory=, ReadWritePaths= and DynamicUser=
2017-11-08 17:34:39 +01:00
Tom Stellard 4e15a7343c udev-rules: Permission changes for /dev/dri/renderD*
- Remove the uaccess tag from /dev/dri/renderD*.
- Change the owning group from video to render.
- Change default mode to 0666.
- Add an option to allow users to set the access mode for these devices at
compile time.
2017-11-08 08:21:31 -08:00
Tom Stellard b8fd3d8220 udev-rules: Permission changes for /dev/kvm
- Remove uaccess tag from /dev/kvm.
- Change the default mode for /dev/kvm to 0666.
2017-11-08 08:17:49 -08:00
NeilBrown c44cac7c6c umount: always use MNT_FORCE in umount_all() (#7213)
The linux umount2() systemcall accepts a MNT_FORCE flags
which some filesystems honor, particularly FUSE and various
network filesystems such as NFS.
These filesystems can sometimes wait for an indefinite period
for a response from an external service, and the wait if
sometimes "uninterruptible" meaning that the process cannot be
killed.
Using MNT_FORCE causes any such request that are outstanding to
be aborted.  This normally allows the waiting process to
be killed.  It will then realease and reference it has to the
filesytem, this allowing the filesystem to be unmounted.

If there remain active references to the filesystem, MNT_FORCE
is *not* forcefull enough to unmount the filesystem anyway.

By the time that umount_all() is run by systemd-shutdown, all
filesystems *should* be unmounted, and sync() will have been
called.  Anything that remains cannot be unmounted in a
completely clean manner and just nees to be dealt with as firmly
as possible.  So use MNT_FORCE and try to explain why in the
comment.

Also enhance an earlier comment to explain why umount2() is
safe even though mount(MNT_REMOUNT) isn't.
2017-11-08 11:29:32 +03:00
Yu Watanabe 8092a48cc1 core/execute: do not create RuntimeDirectory= under private/ sub-directory
RuntimeDirectory= often used for sharing files or sockets with other
services. So, if creating them under private/ sub-directory, we cannot
set DynamicUser= to service units which want to share something through
RuntimeDirectory=.
This makes the directories given by RuntimeDirectory= are created under
/run/ even if DynamicUser= is set.

Fixes #7260.
2017-11-08 15:50:58 +09:00
Yu Watanabe 2bf13bd51e core/load-fragment: fix alignment 2017-11-08 15:49:22 +09:00
Yu Watanabe 652bb2637a core/execute: RuntimeDirectory= or friends requires mount namespace
Since #6940, RuntimeDirectory= or their friends imply BindPaths=.
So, if at least one of them are set, mount namespace is required.
2017-11-08 15:48:51 +09:00
Yu Watanabe 23fd04e92d test: add test for ReadOnlyPaths= with RuntimeDirectory= 2017-11-08 15:48:32 +09:00
Yu Watanabe d18aff0422 core: ReadWritePaths= and friends assume '+' prefix when BindPaths= or freinds are set
When at least one of BindPaths=, BindReadOnlyPaths=, RootImage=,
RuntimeDirectory= or their friends are set, systemd prepares
a namespace under /run/systemd/unit-root. Thus, ReadWritePaths=
or their friends without '+' prefix is completely meaningless.
So, let's assume '+' prefix when one of them are set.

Fixes #7070 and #7080.
2017-11-08 15:48:01 +09:00
Yu Watanabe 7bcef4efe6 core: remove compile_read_write_paths()
From 6c47cd7d3b, RuntimeDirectory= and
their friends also imply BindPaths=. Thus, implying ReadWritePaths=
is meaningless.
2017-11-08 15:07:22 +09:00
Yu Watanabe a4465d0d4c timesync: make poll interval configurable
This adds PollIntervalMinSec= and PollIntervalMaxSec= to timesyncd.conf

Closes #7262.
2017-11-08 01:47:38 +09:00
Alan Jenkins 3a58ca47ee systemctl: remove extra space character in output (#7250)
> See "systemctl  status fail-stop.service" and "journalctl  -xe" for
> details.
2017-11-07 19:18:10 +03:00
Alan Jenkins fec7615c07 core: simplify - don't add jobs to dbus queue if we immediately remove them (#7251)
job_finish_and_invalidate() calls job_free() to destroy jobs (and remove
them from the dbus queue).  So we don't need to add them to the dbus queue
first.

We only want to add jobs to the dbus queue if they're a restart job, which
we're transmogrifying into a start job and putting back into the system.
2017-11-07 19:14:15 +03:00
Shawn Landden ed440f6be9 condition: detect TOMOYO MAC (#7249)
TOMOYO is a Mandatory Access Control security module for Linux.
Rather than ship rules, TOMOYO features a learning mode.

http://tomoyo.osdn.jp/
http://tomoyo.osdn.jp/2.5/index.html.en
2017-11-07 19:12:36 +03:00
Zbigniew Jędrzejewski-Szmek 1ae17672a2 systemctl: add --dry-run argument 2017-11-07 15:15:09 +01:00
Zbigniew Jędrzejewski-Szmek af91818202 bootctl: move find_esp() to shared
In preparation for use in systemctl.

The original function that prints hints is renamed to find_esp_and_warn()
to make its purpose clearer.
2017-11-07 15:14:40 +01:00
Zbigniew Jędrzejewski-Szmek 64f05708cf bootctl: show unique titles 2017-11-07 15:14:23 +01:00
Zbigniew Jędrzejewski-Szmek 7e87c7d914 bootctl: add listing of loader entries 2017-11-07 15:14:21 +01:00
Yu Watanabe 85e55d14de tree-wide: do not work in assert() (#7271)
Fixes #7270.
2017-11-07 16:04:20 +03:00
Yu Watanabe f907cc1620 timesync: add RootDistanceMaxSec= to timesyncd.conf (#7215)
Closes #7211.
2017-11-05 07:39:34 +01:00
Lennart Poettering 6e9834ea0f
Merge pull request #7241 from keszybz/clang-warnings
Fixes for various clang warnings
2017-11-02 19:21:10 +01:00
Susant Sahani 74d42cd923 networkd: remove route - drop route type from netlink message. (#7240)
During startup of networkd we try to drop the configs. While droping
routes we filling ip route type and because of which message like
```
host: Could not drop route: Invalid argument
host: Could not drop route: Invalid argument
```
are shown.

Closed #6929
2017-11-02 21:36:03 +09:00
Zbigniew Jędrzejewski-Szmek 09571e3ffc test-util: silence clang warning about unaligned access 2017-11-01 23:10:25 +01:00
Zbigniew Jędrzejewski-Szmek 3f6914175c util-lib: mark variable with _unused_ to silence clang warning
_unused_ means "the variable is meant to be possible unused and gcc
will not generate a warning about it", which is exactly what we need here,
since we're only declaring it for the side effect of _cleanup_.
2017-11-01 23:10:25 +01:00
Zbigniew Jędrzejewski-Szmek 5180446051 journal: disable -Waddress-of-packed-member under clang
clang warns about a few sites like this:
../src/journal/journal-file.c:1780:48: warning: taking address of packed member 'entry_offset' of class or structure 'DataObject' may result in an unaligned pointer value [-Waddress-of-packed-member]
                                              &o->data.entry_offset,
                                               ^~~~~~~~~~~~~~~~~~~~
but DataObject.entry_offset will always be 8-byte aligned as long as
the DataObject structure is aligned. Similarly in other cases, the
field is always aligned. Let's just silence the warning to avoid noise.

gcc does not know -Waddress-of-packed-member, and would warn about an unknown
warning, so we need to conditionalize on __clang__.
2017-11-01 23:10:25 +01:00
Zbigniew Jędrzejewski-Szmek ecc3f340ab networkd: fix two format string mismatches
../src/network/networkd-link.c:3577:84: warning: format specifies type 'unsigned char' but the argument has type 'uint32_t' (aka 'unsigned int') [-Wformat]
                                route->dst_prefixlen, route->tos, route->priority, route->table, route->lifetime);
                                                                                   ^~~~~~~~~~~~
../src/network/networkd-manager.c:1146:132: warning: format specifies type 'unsigned char' but the argument has type 'uint32_t' (aka 'unsigned int') [-Wformat]
                        rule->from_prefixlen, space ? " " : "", to_str, rule->to_prefixlen, rule->tos, rule->fwmark, rule->fwmask, rule->table);
                                                                                                                                   ^~~~~~~~~~~

Also add some line breaks to make it easier to see which argument is for which
part of the format string.
2017-11-01 23:10:21 +01:00
Zbigniew Jędrzejewski-Szmek 3dad3203ab importd: remove IN_SET to avoid ambiguity
clang warns:
../src/import/importd.c:254:70: warning: 'break' is bound to current loop, GCC binds it to the enclosing loop [-Wgcc-compat]
                while ((e < t->log_message + t->log_message_size) && IN_SET(*e, 0, '\n'))
                                                                     ^
Let's just play it safe and not use IN_SET here.
2017-11-01 23:09:05 +01:00
Zbigniew Jędrzejewski-Szmek 1d3e682e12 journald: unitialized variable access
../src/journal/journald-native.c:341:13: warning: variable 'context' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
        if (ucred && pid_is_valid(ucred->pid)) {
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/journal/journald-native.c:350:42: note: uninitialized use occurs here
                                         context, ucred, tv, label, label_len);
                                         ^~~~~~~
../src/journal/journald-native.c:335:31: note: initialize the variable 'context' to silence this warning
        ClientContext *context;
                              ^
                               = NULL

Very nice reporting!

Functions that we call can handle context == NULL, so it's enough to simply
initialize the variable.
2017-11-01 23:08:21 +01:00
Zbigniew Jędrzejewski-Szmek ac097c841e Remove a bunch of unused variables
gcc does not warn about those, because of the _cleanup_ usage.
clang is smarter here.
2017-11-01 23:06:44 +01:00
Alan Jenkins 4cd9fa8176 core: failure to spawn ExecStartPost should not run ExecStop
Failure to spawn ExecStartPost was being handled differently to e.g.
EXIT_FAILURE returned by ExecStartPost.  It looks like this was an
oversight.  Fix to match documented behaviour.

`man systemd.service`:

> Note that if any of the commands specified in ExecStartPre=, ExecStart=,
> or ExecStartPost= fail (and are not prefixed with "-", see above) or time
> out before the service is fully up, execution continues with commands
> specified in ExecStopPost=, the commands in ExecStop= are skipped.
2017-11-01 15:28:50 +00:00
Alan Jenkins 79aafbd122 core: distinguish "Killing"/"Terminating"/"Stopping" for mount unit timeout
Update the timeout warnings for remount and unmount.  For consistency with
mount, for accuracy, and for consistency with their equivalents in
service.c.
2017-11-01 15:28:50 +00:00
Michal Sekletar 41dfa61d35 manager: fix connecting to bus when dbus is actually around (#7205)
manager_connect_bus() is called *before* manager_coldplug(). As a last
thing in service_coldplug() we set service state to
s->deserialized_state, and thus before we do that all services are
inactive and try_connect always evaluates to false. To fix that we must
look at deserialized state instead of current unit state.

Fixes #7146
2017-11-01 10:25:48 +01:00
martingh 723afa4f96 Reverting erroneous changes made of the course of adding a timeout to journal-remote event handling (#7219) 2017-11-01 10:15:38 +01:00
Yu Watanabe 2e293b4a14 journal-remote: set description to timer_event (#7234)
Follow-up for 5e38eb931f.
2017-11-01 10:13:00 +01:00
Alan Jenkins 0ed782021b
Merge pull request #7226 from sourcejedi/shutdown-misuse-commment
core: remove "misuse" of getpgid() in systemd-shutdown
2017-10-31 10:05:02 +00:00
Alan Jenkins 8ef3d66d14
Merge pull request #7218 from matijaskala/patch-4
fix compile errors on musl
2017-10-30 17:42:33 +00:00
Alan Jenkins 3448a96980 core: remove "misuse" of getpgid() in systemd-shutdown
Using `kill()`  with a signal of 0 is a slightly more documented idiom for
checking whether a process still exists.  It is mentioned explicitly in
man pages.  This avoids the need to comment the call as "misuse".
A comment is still necessary - in fact this idiom is even more confusing if
you don't know how it works.  But it's easy enough to explain.
2017-10-30 16:10:37 +00:00
aeywalee 75bcbcf2e7 Add sd_bus_message_new and sd_bus_message_seal as public functions (#6609) 2017-10-30 16:08:46 +01:00
Zbigniew Jędrzejewski-Szmek ecd9ded89b
Merge pull request #6996 from poettering/discover-block-device
add nspawn image discovery on block devices
2017-10-30 16:05:20 +01:00
Yu Watanabe 21df96c0b0 resolved: change newline position in stub-resolv.conf (#7216)
Follow-up for e6b2d948f8.
2017-10-30 10:34:41 +01:00
Matija Skala d7e454ba9c fix includes
sys/wait.h is needed for WEXITED macro

poll.h is more portable than sys/poll.h
2017-10-30 10:32:45 +01:00
Matija Skala 5a10b4d6bf fix compile error on musl
name '__in6_u.__u6_addr32' is specific to glibc

use 's6_addr32' macro instead
2017-10-30 10:15:31 +01:00
Zbigniew Jędrzejewski-Szmek 8a4b13c5cb treewide: unify identical definitions of polkit_agent_open_if_enabled() (#7187)
Follows the same pattern as pager_open() now.
2017-10-30 09:57:53 +01:00
Lars Karlitski cc25a67e2a journalctl: add --output-fields= (#7181)
This option allows restricting the shown fields in the output modes that
would normally show all fields. It allows clients that are only
interested in a subset of the fields to access those more efficiently.
Also, it makes the resulting size of the output more predictable.

It has no effect on the various `short` output modes, because those
already only show a subset of the fields.
2017-10-27 12:10:47 +09:00
Lennart Poettering 9672b58398 test: add simple test for validating some of the unit specifiers we support
(Also, sort list of test unit files in meson.build alphabetically, to
make future additions more systematic)
2017-10-26 18:01:04 +02:00
Lennart Poettering 14068e17f3 core: add support for expanding state/cache/log directory root in unit files
This augments %t which already resolves to the runtime directory root, and
should be useful for units that want to pass any of these paths in
command line arguments.

Example:

ExecStart=/usr/bin/mydaemon --datadir=%S/mydaemon

Why not expose a specifier resolving directly to the configured
state/runtime/cache/log dir? Three reasons:

1. Specifiers should be independent of configuration of the unit itself,
   and StateDirectory= and friends are unit configuration.  See
   03fc9c723c and related work.

2. We permit multiple StateDirectory= values per unit, and it hence
   wouldn't be clear which one is passed.

3. We already have %t for the runtime directory root, and we should
   continue with the same scheme.
2017-10-26 17:59:09 +02:00
Lennart Poettering 9fb0b9c70d machine-image: handle nicely if the user asks us to remove a symlinked image
Much like for dirs/raw images lets remove the symlink and not the
destination.
2017-10-26 17:54:56 +02:00
Lennart Poettering 759aaedc5c dissect: when we invoke dissection on a loop device with partscan help the user
This adds some simply detection logic for cases where dissection is
invoked on an externally created loop device, and partitions have been
detected on it, but partition scanning so far was off. If this is
detected we now print a brief message indicating what the issue is,
instead of failing with a useless EINVAL message the kernel passed to
us.
2017-10-26 17:54:56 +02:00
Lennart Poettering eb38edce88 machine-image: add partial discovery of block devices as images
This adds some basic discovery of block device images for nspawn and
friends. Note that this doesn't add searching for block devices using
udev, but instead expects users to symlink relevant block devices into
/var/lib/machines. Discovery is hence done exactly like for
dir/subvol/raw file images, except that what is found may be a (symlink
to) a block device.

For now, we do not support cloning these images, but removal, renaming
and read-only flags are supported to the point where that makes sense.

Fixe: #6990
2017-10-26 17:54:56 +02:00
Lennart Poettering 8c4a8ea2ac fs-util: small tweak in chase_symlinks()
If we follow an absolute symlink there's no need to prefix the path with
a "/", since by definition it already has one.

This helps suppressing double "/" in resolved paths containing absolute
symlinks.
2017-10-26 17:54:56 +02:00
Lennart Poettering f7c9f4a2a9 btrfs-util: when opening subvolume fds, always set O_NOFOLLOW
Some of the btrfs utility functions already used O_NOFOLLOW others
didn't. Let's streamline this, and refuse operation when we are called
for symlinks on "remove" and "snapshot" too.

In particular in the "remove" case following symlinks is a bad idea, and
is quite different from how unlink() and friends work, which always
remove the symlink, and not the destination, a logic we should follow
here too.
2017-10-26 17:54:56 +02:00
Razvan Cojocaru 530c1c3028 systemd-detect-virt: refine hypervisor detection (#7171)
Continue to try to get more details about the actual underlying
hypervisor with successive tests until none are available.
This fixes issue #7165.
2017-10-26 16:59:04 +02:00
Zbigniew Jędrzejewski-Szmek 8aeadf3052 Merge pull request #7184 from keszybz/resolved-loop
resolved: fix loop on packets with pseudo dns types

https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1725351,
CVE-2017-15908.
2017-10-26 15:29:03 +02:00
Lennart Poettering 35682fd4a1 Merge pull request #7127 from keszybz/sundry-tweaks
Various unrelated small patches
2017-10-26 10:57:00 +02:00
Lennart Poettering af163d70ae Merge pull request #7142 from sourcejedi/systemd-shutdown
systemd-shutdown: avoid confusingly redundant messages
2017-10-26 10:56:44 +02:00
martingh 5e38eb931f Adding timer_event to wakeup as suggested by MHD_get_timeout (#7152) 2017-10-26 10:54:30 +02:00
Zbigniew Jędrzejewski-Szmek 9f939335a0 resolved: fix loop on packets with pseudo dns types
Reported by Karim Hossen & Thomas Imbert from Sogeti ESEC R&D.

https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1725351
2017-10-25 11:47:04 +02:00
Lauri Tirkkonen 4f13e53428 nspawn: EROFS for chowning mount points is not fatal (#7122)
This fixes --read-only with --private-users. mkdir_userns_p may return
-EROFS if either mkdir or lchown fails; lchown failing is fine as the
mount point will just be overmounted, and if mkdir fails then the
following mount() will also fail (with ENOENT).
2017-10-24 19:40:50 +02:00
Alan Jenkins 116e6d9643 core: systemd-shutdown: avoid confusingly redundant messages
After previous output from systemd-shutdown indicated a bug, my attention
was drawn to redundant output lines.  Did they indicate an anomaly?

It turns out to be an expected, harmless result of the current code.  But
we don't have much justification to run such redundant operations.  Let's
remove the confusing redundant message.

We can stop trying to remount a directory read-only once its mount entry
has successfully been changed to "ro".  We can simply let the kernel keep
track of this for us.  I don't bother to try and avoid re-parsing the
mountinfo.  I appreciate snappy shutdowns, but this code is already
intricate and buggy enough (see issue 7131).

(Disclaimer: At least for the moment, you can't _rely_ on always seeing
suspicious output from systemd-shutdown.  By default, you can expect the
kernel to truncate the log output of systemd-shutdown.  Ick ick ick!
Because /dev/kmsg is rate-limited by default.  Normally it prints a message
"X lines supressed", but we tend to shut down before the timer expires
in this case).

Before:

systemd-shutdown[1]: Remounting '/' read-only with options 'seclabel...
EXT4-fs (vda3): re-mounted. Opts: data=ordered
systemd-shutdown[1]: Remounting '/' read-only with options 'seclabel, ...
EXT4-fs (vda3): re-mounted. Opts: data=ordered

After:

systemd-shutdown[1]: Remounting '/' read-only with options 'seclabel, ...
EXT4-fs (vda3): re-mounted. Opts: data=ordered

I also tested with `systemctl reboot --force`, plus a loopback mount to
cause one of the umounts to fail initially.  In this case another 2 lines
of output are removed (out of a larger number of lines).
2017-10-24 15:54:30 +01:00
Dimitri John Ledkov e6b2d948f8 resolved: create private stub resolve file for /etc/resolv.conf integration (#7014)
This creates a second private resolve.conf file which lists the stub resolver
and the resolved acquired search domains.

This runtime file should be used as a symlink target for /etc/resolv.conf such
that non-nss based applications can resolve search domains.

Fixes: #7009
2017-10-24 15:28:41 +02:00
Lennart Poettering ceeb433c39 Merge pull request #7141 from yuwata/fix-7129
core: fix D-Bus API
2017-10-24 15:25:12 +02:00
Zbigniew Jędrzejewski-Szmek 0c2826c60c core: in --user mode, report READY=1 as soon as basic.target is reached (#7102)
When a user logs in, systemd-pam will wait for the user manager instance to
report readiness. We don't need to wait for all the jobs to finish, it
is enough if the basic startup is done and the user manager is responsive.

systemd --user will now send out a READY=1 notification when either of two
conditions becomes true:
- basic.target/start job is gone,
- the initial transaction is done.

Also fixes #2863.
2017-10-24 14:48:54 +02:00
Lennart Poettering e0237035a0 Merge pull request #7123 from keszybz/date-formatting
Fix for time stamp formatting in timedatectl
2017-10-24 12:24:09 +02:00
Yu Watanabe 3f856a2813 core: fix D-Bus API
This fixes bugs introduced by cffaed83e8.

Closes #7129.
2017-10-24 17:21:27 +09:00
myrkr 1898e5f9a3 nspawn: Fix calculation of capabilities for configuration file (#7087)
The current code shifting an integer 1 failed for capabilities like
CAP_MAC_ADMIN (numerical value 33). This caused issues when specifying
them in the nspawn configuration file. Using an uint64_t 1 instead.

The similar code for processing the --capability command line option
was already correctly working.
2017-10-24 09:56:40 +02:00
Lennart Poettering b88d48c2ca Merge pull request #7148 from keszybz/dynamic-user-use-gid
Use gid for static dynamic users
2017-10-24 09:38:01 +02:00
Lennart Poettering d3aa0a1c42 Merge pull request #6948 from pfl/radv_emit_dns
Add EmitDNS= and EmitDomains= network file configuration options
2017-10-23 18:39:07 +02:00
Zbigniew Jędrzejewski-Szmek c2983a7fdd core/dynamic-user: use gid from pwnam if a static user was found
Fixes #7133.

v2:
- update based on review
2017-10-23 16:09:20 +02:00
Zbigniew Jędrzejewski-Szmek a2fa605a65 sd-boot: simplify the implementation of entry uniquification
There's a slight change in implementation: we first try to append the
version, then look for any non-unique pairs again. Before, we would only
mark as possibly unique those entries we changed. But if there are two
entries that e.g. have the same title and version, but only one has the
machine-id specified, we would treat one of them as still non-unique after
appending the machine-id to the other one. So the new algorithm is simpler
but more robust (not that it matters).
2017-10-23 13:40:54 +02:00
Zbigniew Jędrzejewski-Szmek 362d90b7f2 core/dynamic-user: use _cleanup_ in dynamic user locking
This makes the code a bit easier to read.
2017-10-20 13:39:07 +02:00
Patrik Flykt 6852c0f6b0 sd-radv: Allocate space also for DNSSL iov option (#7144)
The iov array needs to hold five entries in addition to the number
of prefixes.
2017-10-20 10:59:15 +02:00
Alan Jenkins 066b753dc5 core: systemd-shutdown: add missing check for umount_changed
The assumption was that nothing changes in the final attempt.  This
would be confusing if a filesystem with a process in uninterruptible
sleep suddenly became un-stuck for the final attempt, but we still give
up and don't try to e.g. unmount any parent mounts.

I don't know how possible that is.  But the code will be easier to read
without an assumption that it does not attempt to justify.
2017-10-19 15:00:57 +01:00
Zbigniew Jędrzejewski-Szmek 8cb8326606 logind: fix killing of scopes
scope_abandon() called unit_watch_all_pids() to check if there are any pids in
the cgroup, but unit_watch_all_pids() does nothing (and returns an empty set of
pids) when cg_unified_controller(SYSTEMD) returns true. On hybrid or unified,
cg_unified_controller(SYSTEMD) returns 1, so scope_abandon() thinks the scope
is empty, even though it's not, and marks the scope dead prematurely.

Example output after the scope is marked dead with processes still being present:

● session-24.scope - Session 24 of user guest
   Loaded: loaded (/run/systemd/transient/session-24.scope; transient; vendor preset: disabled)
Transient: yes
   Active: inactive (dead) since Sat 2017-10-14 15:36:22 CEST; 5min ago
    Tasks: 1
   CGroup: /user.slice/user-1001.slice/session-24.scope
           └─17309 sleep infinity

Subsequent calls to stop the scope unit do nothing, because systemd thinks the
scope is already dead.

https://bugzilla.redhat.com/show_bug.cgi?id=1486859

This is easily reproducible on both F26 and F27:

> ssh guest@localhost
$ pulseaudio & sleep infinity & disown; exit
$ systemctl status $$
> systemctl status session-NN.scope

Tested with unified, hybrid, and legacy layouts, seems to work.
2017-10-19 08:49:01 +02:00
Zbigniew Jędrzejewski-Szmek 7cd0f0f844 logind: allow two very close error messages to be distinguished
In https://bugzilla.redhat.com/show_bug.cgi?id=1486859 error messages appera:

Sep 06 19:09:07 ld92.e.math.uh.edu audit[21482]: AVC avc:  denied  { read } for  pid=21482 comm="systemd-logind" name="dbus-1" dev="tmpfs" ino=5548194 scontext=system_u:system_r:systemd_logind_t:s0 tcontext=unconfined_u:object_r:session_dbusd_tmp_t:s0 tclass=dir permissive=0
Sep 06 19:09:07 ld92.e.math.uh.edu systemd-logind[21482]: Failed to remove runtime directory /run/user/8664: Permission denied

But it's not clear which of the two rm_rf's is the source. Let's make
them different.
2017-10-19 08:49:01 +02:00