chiark / gitweb /
elogind.git
6 years agobasic/virt: fix userns check on CONFIG_USER_NS=n kernel (#4651)
Zbigniew Jędrzejewski-Szmek [Fri, 11 Nov 2016 15:54:54 +0000 (10:54 -0500)]
basic/virt: fix userns check on CONFIG_USER_NS=n kernel (#4651)

ENOENT should be treated as "false", but because of the broken errno check it
was treated as an error. So ConditionVirtualization=user-namespaces probably
returned the correct answer, but only by accident.

Fixes #4608.

6 years agocore: don't use the unified hierarchy for the elogind cgroup yet (#4628)
Martin Pitt [Thu, 10 Nov 2016 04:33:13 +0000 (05:33 +0100)]
core: don't use the unified hierarchy for the elogind cgroup yet (#4628)

Too many things don't get along with the unified hierarchy yet:

 * https://github.com/opencontainers/runc/issues/1175
 * https://github.com/docker/docker/issues/28109
 * https://github.com/lxc/lxc/issues/1280

So revert the default to the legacy hierarchy for now. Developers of the above
software can opt into the unified hierarchy with
"elogind.legacy_elogind_cgroup_controller=0".

6 years agoman/sd_watchdog_enabled: correct minor typos (#4632)
Jonathan Boulle [Wed, 9 Nov 2016 16:30:10 +0000 (17:30 +0100)]
man/sd_watchdog_enabled: correct minor typos (#4632)

6 years agoAdjust pkgconfig files to point at rootlibdir (#4584)
Mike Gilbert [Tue, 8 Nov 2016 08:36:41 +0000 (03:36 -0500)]
Adjust pkgconfig files to point at rootlibdir (#4584)

The .so symlinks got moved to rootlibdir in 082210c7.

6 years agotree-wide: drop (llu) casts for kernel's __u64
Zbigniew Jędrzejewski-Szmek [Mon, 7 Nov 2016 16:49:51 +0000 (11:49 -0500)]
tree-wide: drop (llu) casts for kernel's __u64

According to comments in <asm/types.h>, __u64 is always defined as unsigned
long long. Those casts should be superfluous.

6 years agotree-wide: add PRI_[NU]SEC, and use time format strings more
Zbigniew Jędrzejewski-Szmek [Mon, 7 Nov 2016 16:49:25 +0000 (11:49 -0500)]
tree-wide: add PRI_[NU]SEC, and use time format strings more

6 years agocore: reprint the question every 2 sec in ask_char()
Franck Bui [Mon, 7 Nov 2016 16:14:59 +0000 (17:14 +0100)]
core: reprint the question every 2 sec in ask_char()

ask_char() now reprints the question every 2sec automatically.

It prefixes its output with '\r' to to bring the cursor to the
beginning of the terminal line, and then print the message, redoing it
every 2sec.

As long as nothing interferes with out output this logic will have no
visible effect as we constantly overprint the visible text with the
exact same text.

However, if something is dumped in the middle, then our question won't
get lost, as we'll ask soon again.

This is useful if the question is asked to a terminal that is also
used to dump some other status messages/logs. For example when
confirmation messages are enabled during the boot
(elogind.confirm_spawn=1), the question can easily be lost if the
kernel logs are also enabled and both use the same console.

Idea suggested by Lennart Poettering.

6 years agoRename formats-util.h to format-util.h
Zbigniew Jędrzejewski-Szmek [Mon, 7 Nov 2016 15:14:59 +0000 (10:14 -0500)]
Rename formats-util.h to format-util.h

We don't have plural in the name of any other -util files and this
inconsistency trips me up every time I try to type this file name
from memory. "formats-util" is even hard to pronounce.

6 years agotree-wide: add SD_ID128_MAKE_STR, remove LOG_MESSAGE_ID
Zbigniew Jędrzejewski-Szmek [Sun, 6 Nov 2016 17:48:23 +0000 (12:48 -0500)]
tree-wide: add SD_ID128_MAKE_STR, remove LOG_MESSAGE_ID

Embedding sd_id128_t's in constant strings was rather cumbersome. We had
SD_ID128_CONST_STR which returned a const char[], but it had two problems:
- it wasn't possible to statically concatanate this array with a normal string
- gcc wasn't really able to optimize this, and generated code to perform the
  "conversion" at runtime.
Because of this, even our own code in coredumpctl wasn't using
SD_ID128_CONST_STR.

Add a new macro to generate a constant string: SD_ID128_MAKE_STR.
It is not as elegant as SD_ID128_CONST_STR, because it requires a repetition
of the numbers, but in practice it is more convenient to use, and allows gcc
to generate smarter code:

$ size .libs/elogind{,-logind,-journald}{.old,}
   text    data     bss     dec     hex filename
1265204  149564    4808 1419576  15a938 .libs/elogind.old
1260268  149564    4808 1414640  1595f0 .libs/elogind
 246805   13852     209  260866   3fb02 .libs/elogind-logind.old
 240973   13852     209  255034   3e43a .libs/elogind-logind
 146839    4984      34  151857   25131 .libs/elogind-journald.old
 146391    4984      34  151409   24f71 .libs/elogind-journald

It is also much easier to check if a certain binary uses a certain MESSAGE_ID:

$ strings .libs/elogind.old|grep MESSAGE_ID
MESSAGE_ID=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x
MESSAGE_ID=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x
MESSAGE_ID=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x
MESSAGE_ID=%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x

$ strings .libs/elogind|grep MESSAGE_ID
MESSAGE_ID=c7a787079b354eaaa9e77b371893cd27
MESSAGE_ID=b07a249cd024414a82dd00cd181378ff
MESSAGE_ID=641257651c1b4ec9a8624d7a40a9e1e7
MESSAGE_ID=de5b426a63be47a7b6ac3eaac82e2f6f
MESSAGE_ID=d34d037fff1847e6ae669a370e694725
MESSAGE_ID=7d4958e842da4a758f6c1cdc7b36dcc5
MESSAGE_ID=1dee0369c7fc4736b7099b38ecb46ee7
MESSAGE_ID=39f53479d3a045ac8e11786248231fbf
MESSAGE_ID=be02cf6855d2428ba40df7e9d022f03d
MESSAGE_ID=7b05ebc668384222baa8881179cfda54
MESSAGE_ID=9d1aaa27d60140bd96365438aad20286

6 years agoLink: port to new ethtool ETHTOOL_xLINKSETTINGS
Susant Sahani [Fri, 4 Nov 2016 09:55:07 +0000 (15:25 +0530)]
Link: port to new ethtool ETHTOOL_xLINKSETTINGS

Link: port to new ethtool ETHTOOL_xLINKSETTINGS
This patch defines a new ETHTOOL_GLINKSETTINGS/SLINKSETTINGS API,
handled by the new get_link_ksettings/set_link_ksettings .

This is a WIP version based on this [kernel
patch](https://patchwork.kernel.org/patch/8411401/).

commit 0527f1c

http://github.com/torvalds/linux/commit/3f1ac7a700d039c61d8d8b99f28d605d489a60cfommit
35afb33

6 years agoacl-util: fix memleak
Evgeny Vereshchagin [Thu, 3 Nov 2016 22:04:40 +0000 (22:04 +0000)]
acl-util: fix memleak

Fixes:
$ ./libtool --mode execute valgrind --leak-check=full ./journalctl >/dev/null
==22309== Memcheck, a memory error detector
==22309== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==22309== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==22309== Command: /home/vagrant/elogind/.libs/lt-journalctl
==22309==
Hint: You are currently not seeing messages from other users and the system.
      Users in groups 'adm', 'elogind-journal', 'wheel' can see all messages.
      Pass -q to turn off this notice.
==22309==
==22309== HEAP SUMMARY:
==22309==     in use at exit: 8,680 bytes in 4 blocks
==22309==   total heap usage: 5,543 allocs, 5,539 frees, 9,045,618 bytes allocated
==22309==
==22309== 488 (56 direct, 432 indirect) bytes in 1 blocks are definitely lost in loss record 2 of 4
==22309==    at 0x4C2BBAD: malloc (vg_replace_malloc.c:299)
==22309==    by 0x6F37A0A: __new_var_obj_p (__libobj.c:36)
==22309==    by 0x6F362F7: __acl_init_obj (acl_init.c:28)
==22309==    by 0x6F37731: __acl_from_xattr (__acl_from_xattr.c:54)
==22309==    by 0x6F36087: acl_get_file (acl_get_file.c:69)
==22309==    by 0x4F15752: acl_search_groups (acl-util.c:172)
==22309==    by 0x113A1E: access_check_var_log_journal (journalctl.c:1836)
==22309==    by 0x113D8D: access_check (journalctl.c:1889)
==22309==    by 0x115681: main (journalctl.c:2236)
==22309==
==22309== LEAK SUMMARY:
==22309==    definitely lost: 56 bytes in 1 blocks
==22309==    indirectly lost: 432 bytes in 1 blocks
==22309==      possibly lost: 0 bytes in 0 blocks
==22309==    still reachable: 8,192 bytes in 2 blocks
==22309==         suppressed: 0 bytes in 0 blocks

6 years agoRevert "sd-bus: use PRIu64 instead of casting" (#4556)
Zbigniew Jędrzejewski-Szmek [Thu, 3 Nov 2016 17:16:42 +0000 (13:16 -0400)]
Revert "sd-bus: use PRIu64 instead of casting" (#4556)

This reverts commit 75ead2b753cb9586f3f208326446081baab70da1.

Follow up for #4546:
> @@ -848,8 +848,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
         if (k->src_id == KDBUS_SRC_ID_KERNEL)
                 bus_message_set_sender_driver(bus, m);
         else {
-                xsprintf(m->sender_buffer, ":1.%llu",
-                         (unsigned long long)k->src_id);
+                xsprintf(m->sender_buffer, ":1.%"PRIu64, k->src_id);

This produces:

src/libelogind/sd-bus/bus-kernel.c: In function ‘bus_kernel_make_message’:
src/libelogind/sd-bus/bus-kernel.c:851:44: warning: format ‘%lu’ expects argument of type ‘long
unsigned int’, but argument 4 has type ‘__u64 {aka long long unsigned int}’ [-Wformat=]
                 xsprintf(m->sender_buffer, ":1.%"PRIu64, k->src_id);
                                            ^

6 years agocore: monitor the inotify file descriptor not the console one in acquire_terminal()
Franck Bui [Wed, 2 Nov 2016 15:24:57 +0000 (16:24 +0100)]
core: monitor the inotify file descriptor not the console one in acquire_terminal()

When waiting for the terminal to be release in acquire_terminal(), we
were monitoring the terminal fd instead of the inotify descriptor.

Therefore any write accesses would wake up the waiting process instead
of being wake up when the tty is closed only.

6 years agoDrop FOREACH_WORD_QUOTED
Zbigniew Jędrzejewski-Szmek [Fri, 28 Oct 2016 02:44:50 +0000 (22:44 -0400)]
Drop FOREACH_WORD_QUOTED

6 years agotree-wide: drop unneded WHITESPACE param to extract_first_word
Zbigniew Jędrzejewski-Szmek [Fri, 28 Oct 2016 00:06:44 +0000 (20:06 -0400)]
tree-wide: drop unneded WHITESPACE param to extract_first_word

It's the default, and NULL is shorter.

6 years agotree-wide: drop NULL sentinel from strjoin
Zbigniew Jędrzejewski-Szmek [Sun, 23 Oct 2016 15:43:27 +0000 (11:43 -0400)]
tree-wide: drop NULL sentinel from strjoin

This makes strjoin and strjoina more similar and avoids the useless final
argument.

spatch -I . -I ./src -I ./src/basic -I ./src/basic -I ./src/shared -I ./src/shared -I ./src/network -I ./src/locale -I ./src/login -I ./src/journal -I ./src/journal -I ./src/timedate -I ./src/timesync -I ./src/nspawn -I ./src/resolve -I ./src/resolve -I ./src/elogind -I ./src/core -I ./src/core -I ./src/libudev -I ./src/udev -I ./src/udev/net -I ./src/udev -I ./src/libelogind/sd-bus -I ./src/libelogind/sd-event -I ./src/libelogind/sd-login -I ./src/libelogind/sd-netlink -I ./src/libelogind/sd-network -I ./src/libelogind/sd-hwdb -I ./src/libelogind/sd-device -I ./src/libelogind/sd-id128 -I ./src/libelogind-network --sp-file coccinelle/strjoin.cocci --in-place $(git ls-files src/*.c)

git grep -e '\bstrjoin\b.*NULL' -l|xargs sed -i -r 's/strjoin\((.*), NULL\)/strjoin(\1)/'

This might have missed a few cases (spatch has a really hard time dealing
with _cleanup_ macros), but that's no big issue, they can always be fixed
later.

6 years agotree-wide: use startswith return value to avoid hardcoded offset
Zbigniew Jędrzejewski-Szmek [Sat, 22 Oct 2016 20:11:41 +0000 (16:11 -0400)]
tree-wide: use startswith return value to avoid hardcoded offset

I think it's an antipattern to have to count the number of bytes in
the prefix by hand. We should do this automatically to avoid wasting
programmer time, and possible errors. I didn't any offsets that were
wrong, so this change is mostly to make future development easier.

6 years agobasic: support default and alternate values for env expansion
Ray Strode [Tue, 9 Aug 2016 14:20:22 +0000 (10:20 -0400)]
basic: support default and alternate values for env expansion

Sometimes it's useful to provide a default value during an environment
expansion, if the environment variable isn't already set.

For instance $XDG_DATA_DIRS is suppose to default to:

/usr/local/share/:/usr/share/

if it's not yet set. That means callers wishing to augment
XDG_DATA_DIRS need to manually add those two values.

This commit changes replace_env to support the following shell
compatible default value syntax:

XDG_DATA_DIRS=/foo:${XDG_DATA_DIRS:-/usr/local/share/:/usr/share}

Likewise, it's useful to provide an alternate value during an
environment expansion, if the environment variable isn't already set.

For instance, $LD_LIBRARY_PATH will inadvertently search the current
working directory if it starts or ends with a colon, so the following
is usually wrong:

LD_LIBRARY_PATH=/foo/lib:${LD_LIBRARY_PATH}

To address that, this changes replace_env to support the following
shell compatible alternate value syntax:

LD_LIBRARY_PATH=/foo/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

[zj: gate the new syntax under REPLACE_ENV_ALLOW_EXTENDED switch, so
existing callers are not modified.]

6 years agobasic: add new merge_env_file function
Ray Strode [Thu, 4 Aug 2016 16:00:00 +0000 (12:00 -0400)]
basic: add new merge_env_file function

merge_env_file is a new function, that's like load_env_file, but takes a
pre-existing environment as an input argument. New environment entries are
merged. Variable expansion is performed.

Falling back to the process environment is supported (when a flag is set).
Alternatively this could be implemented as passing an additional fallback
environment array, but later on we're adding another flag to allow braceless
expansion, and the two flags can be combined in one arg, so there's less
stuff to pass around.

6 years agoMerge pull request #22 from elogind/dev_v232
Sven Eden [Fri, 7 Jul 2017 13:18:23 +0000 (15:18 +0200)]
Merge pull request #22 from elogind/dev_v232

Dev v232 merge to master

6 years agoVersion 232.2 (Pre) Release v232.2
Sven Eden [Fri, 7 Jul 2017 09:33:47 +0000 (11:33 +0200)]
Version 232.2 (Pre) Release

6 years agoPrep v232.2: Mask more unneeded functions
Sven Eden [Fri, 7 Jul 2017 09:33:14 +0000 (11:33 +0200)]
Prep v232.2: Mask more unneeded functions

6 years agoPrep v232.2: Remove src/mount - It is not needed.
Sven Eden [Fri, 7 Jul 2017 05:58:07 +0000 (07:58 +0200)]
Prep v232.2: Remove src/mount - It is not needed.

6 years agoPrep v232.2: cg_shift_path() : With other controllers, elogind might end up in name...
Sven Eden [Wed, 5 Jul 2017 12:53:38 +0000 (14:53 +0200)]
Prep v232.2: cg_shift_path() : With other controllers, elogind might end up in name=foo:/elogind, where cgroup and root are both /elogind.

6 years agoPrep v232.2: cg_update_unified() : Statically set 'unified_cache' to 'CGROUP_UNIFIED_...
Sven Eden [Wed, 5 Jul 2017 12:24:33 +0000 (14:24 +0200)]
Prep v232.2: cg_update_unified() : Statically set 'unified_cache' to 'CGROUP_UNIFIED_NONE'

6 years agoPrep v232.2: libelogind.sym: Rename LIBELOGIND back to LIBSYSTEMD.
Sven Eden [Wed, 5 Jul 2017 11:03:13 +0000 (13:03 +0200)]
Prep v232.2: libelogind.sym: Rename LIBELOGIND back to LIBSYSTEMD.

6 years agoPrep v232.2: Unmask sd_id128_get_invocation(), it is part of the API installed by...
Sven Eden [Wed, 5 Jul 2017 08:30:23 +0000 (10:30 +0200)]
Prep v232.2: Unmask sd_id128_get_invocation(), it is part of the API installed by elogind, and therefore must not be masked.

6 years agoVersion 232.1 Release
Sven Eden [Wed, 5 Jul 2017 06:57:32 +0000 (08:57 +0200)]
Version 232.1 Release

6 years agoPrep v232: Add libelogind.sym entries for version 232.
Sven Eden [Tue, 4 Jul 2017 16:26:15 +0000 (18:26 +0200)]
Prep v232: Add libelogind.sym entries for version 232.

6 years agoPrep v232: Do not listen to SYSTEMD_* environment variables to override things.
Sven Eden [Tue, 4 Jul 2017 16:10:40 +0000 (18:10 +0200)]
Prep v232: Do not listen to SYSTEMD_* environment variables to override things.

6 years agoPrep v232: Mask new functions that are unneeded by elogind
Sven Eden [Tue, 4 Jul 2017 15:09:23 +0000 (17:09 +0200)]
Prep v232: Mask new functions that are unneeded by elogind

6 years agoPrep v232: Add missing includes
Sven Eden [Tue, 4 Jul 2017 15:08:57 +0000 (17:08 +0200)]
Prep v232: Add missing includes

6 years agoPrep v232: Apply missing updates from upstream
Sven Eden [Tue, 4 Jul 2017 14:59:46 +0000 (16:59 +0200)]
Prep v232: Apply missing updates from upstream

6 years agoPrep v232: Update root and build files to upstream v232 tag.
Sven Eden [Fri, 30 Jun 2017 06:13:06 +0000 (08:13 +0200)]
Prep v232: Update root and build files to upstream v232 tag.

6 years agoRevert "sd-bus: use PRIu64 instead of casting" (#4556)
Zbigniew Jędrzejewski-Szmek [Thu, 3 Nov 2016 17:16:42 +0000 (13:16 -0400)]
Revert "sd-bus: use PRIu64 instead of casting" (#4556)

This reverts commit 75ead2b753cb9586f3f208326446081baab70da1.

Follow up for #4546:
> @@ -848,8 +848,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
         if (k->src_id == KDBUS_SRC_ID_KERNEL)
                 bus_message_set_sender_driver(bus, m);
         else {
-                xsprintf(m->sender_buffer, ":1.%llu",
-                         (unsigned long long)k->src_id);
+                xsprintf(m->sender_buffer, ":1.%"PRIu64, k->src_id);

This produces:

src/libelogind/sd-bus/bus-kernel.c: In function ‘bus_kernel_make_message’:
src/libelogind/sd-bus/bus-kernel.c:851:44: warning: format ‘%lu’ expects argument of type ‘long
unsigned int’, but argument 4 has type ‘__u64 {aka long long unsigned int}’ [-Wformat=]
                 xsprintf(m->sender_buffer, ":1.%"PRIu64, k->src_id);
                                            ^

6 years agosd-bus: use PRIu64 instead of casting
Zbigniew Jędrzejewski-Szmek [Thu, 3 Nov 2016 02:03:27 +0000 (22:03 -0400)]
sd-bus: use PRIu64 instead of casting

6 years agoRevert some uses of xsprintf
Zbigniew Jędrzejewski-Szmek [Thu, 3 Nov 2016 02:02:46 +0000 (22:02 -0400)]
Revert some uses of xsprintf

This reverts some changes introduced in d054f0a4d4.
xsprintf should be used in cases where we calculated the right buffer
size by hand (using DECIMAL_STRING_MAX and such), and never in cases where
we are printing externally specified strings of arbitrary length.

Fixes #4534.

6 years agoRecognise Lustre as a remote file system (#4530)
Brian J. Murrell [Tue, 1 Nov 2016 03:48:00 +0000 (23:48 -0400)]
Recognise Lustre as a remote file system (#4530)

Lustre is also a remote file system that wants the network to be up before it is mounted.

6 years agotests: clarify test_path_startswith return value (#4508)
Zbigniew Jędrzejewski-Szmek [Sun, 30 Oct 2016 14:21:29 +0000 (10:21 -0400)]
tests: clarify test_path_startswith return value (#4508)

A pendant for #4481.

6 years agoman: Fix event source priority enum names in synopsis (#4478)
Martin Ejdestig [Mon, 24 Oct 2016 22:30:26 +0000 (00:30 +0200)]
man: Fix event source priority enum names in synopsis (#4478)

6 years agoman: add a note that FDSTORE=1 requires epoll-compatible fds
Zbigniew Jędrzejewski-Szmek [Sun, 23 Oct 2016 00:32:59 +0000 (20:32 -0400)]
man: add a note that FDSTORE=1 requires epoll-compatible fds

Let's say that this was not obvious from our man page.

6 years agotree-wide: make parse_proc_cmdline() strip "rd." prefix automatically
Zbigniew Jędrzejewski-Szmek [Sat, 22 Oct 2016 19:31:14 +0000 (15:31 -0400)]
tree-wide: make parse_proc_cmdline() strip "rd." prefix automatically

This stripping is contolled by a new boolean parameter. When the parameter
is true, it means that the caller does not care about the distinction between
initrd and real root, and wants to act on both rd-dot-prefixed and unprefixed
parameters in the initramfs, and only on the unprefixed parameters in real
root. If the parameter is false, behaviour is the same as before.

Changes by caller:
log.c (elogind.log_*):      changed to accept rd-dot-prefix params
pid1:                       no change, custom logic
cryptsetup-generator:       no change, still accepts rd-dot-prefix params
debug-generator:            no change, does not accept rd-dot-prefix params
fsck:                       changed to accept rd-dot-prefix params
fstab-generator:            no change, custom logic
gpt-auto-generator:         no change, custom logic
hibernate-resume-generator: no change, does not accept rd-dot-prefix params
journald:                   changed to accept rd-dot-prefix params
modules-load:               no change, still accepts rd-dot-prefix params
quote-check:                no change, does not accept rd-dot-prefix params
udevd:                      no change, still accepts rd-dot-prefix params

I added support for "rd." params in the three cases where I think it's
useful: logging, fsck options, journald forwarding options.

6 years agotree-wide: allow state to be passed through to parse_proc_cmdline_item
Zbigniew Jędrzejewski-Szmek [Sat, 22 Oct 2016 18:24:52 +0000 (14:24 -0400)]
tree-wide: allow state to be passed through to parse_proc_cmdline_item

No functional change.

6 years agodetect-virt: add --private-users switch to check if a userns is active
Zbigniew Jędrzejewski-Szmek [Fri, 21 Oct 2016 03:41:21 +0000 (23:41 -0400)]
detect-virt: add --private-users switch to check if a userns is active

Various things don't work when we're running in a user namespace, but it's
pretty hard to reliably detect if that is true.

A function is added which looks at /proc/self/uid_map and returns false
if the default "0 0 UINT32_MAX" is found, and true if it finds anything else.
This misses the case where an 1:1 mapping with the full range was used, but
I don't know how to distinguish this case.

'elogind-detect-virt --private-users' is very similar to
'elogind-detect-virt --chroot', but we check for a user namespace instead.

6 years agoupdate-utmp: let's use STR_IN_SET() where it is pretty
Lennart Poettering [Thu, 20 Oct 2016 17:20:22 +0000 (19:20 +0200)]
update-utmp: let's use STR_IN_SET() where it is pretty

6 years agologind: don't hit assert when we try to free NULL manager object
Lennart Poettering [Thu, 20 Oct 2016 17:19:46 +0000 (19:19 +0200)]
logind: don't hit assert when we try to free NULL manager object

Fixes: #4431
6 years agobasic: fallback to the fstat if we don't have access to the /proc/self/fdinfo
Evgeny Vereshchagin [Thu, 20 Oct 2016 09:01:45 +0000 (09:01 +0000)]
basic: fallback to the fstat if we don't have access to the /proc/self/fdinfo

https://github.com/elogind/elogind/pull/4372#discussion_r83354107:
I get `open("/proc/self/fdinfo/13", O_RDONLY|O_CLOEXEC) = -1 EACCES (Permission denied)`

327   mkdir("/proc", 0755 <unfinished ...>
327   <... mkdir resumed> )             = -1 EEXIST (File exists)
327   stat("/proc",  <unfinished ...>
327   <... stat resumed> {st_dev=makedev(8, 1), st_ino=28585, st_mode=S_IFDIR|0755, st_nlink=2, st_uid=0, st_gid=0, st_blksize=1024, st_blocks=4, st_size=1024, st_atime=2016/10/14-02:55:32, st_mtime=2016/
327   mount("proc", "/proc", "proc", MS_NOSUID|MS_NODEV|MS_NOEXEC, NULL <unfinished ...>
327   <... mount resumed> )             = 0
327   lstat("/proc",  <unfinished ...>
327   <... lstat resumed> {st_dev=makedev(0, 34), st_ino=1, st_mode=S_IFDIR|0555, st_nlink=75, st_uid=65534, st_gid=65534, st_blksize=1024, st_blocks=0, st_size=0, st_atime=2016/10/14-03:13:35.971031263,
327   lstat("/proc/sys", {st_dev=makedev(0, 34), st_ino=4026531855, st_mode=S_IFDIR|0555, st_nlink=1, st_uid=65534, st_gid=65534, st_blksize=1024, st_blocks=0, st_size=0, st_atime=2016/10/14-03:13:39.1630
327   openat(AT_FDCWD, "/proc", O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_PATH) = 11</proc>
327   name_to_handle_at(11</proc>, "sys", {handle_bytes=128}, 0x7ffe3a238604, AT_SYMLINK_FOLLOW) = -1 EOPNOTSUPP (Operation not supported)
327   name_to_handle_at(11</proc>, "", {handle_bytes=128}, 0x7ffe3a238608, AT_EMPTY_PATH) = -1 EOPNOTSUPP (Operation not supported)
327   openat(11</proc>, "sys", O_RDONLY|O_CLOEXEC|O_PATH) = 13</proc/sys>
327   open("/proc/self/fdinfo/13", O_RDONLY|O_CLOEXEC) = -1 EACCES (Permission denied)
327   close(13</proc/sys> <unfinished ...>
327   <... close resumed> )             = 0
327   close(11</proc> <unfinished ...>
327   <... close resumed> )             = 0

-bash-4.3# ls -ld /proc/
dr-xr-xr-x 76 65534 65534 0 Oct 14 02:57 /proc/

-bash-4.3# ls -ld /proc/1
dr-xr-xr-x 9 root root 0 Oct 14 02:57 /proc/1

-bash-4.3# ls -ld /proc/1/fdinfo
dr-x------ 2 65534 65534 0 Oct 14 03:00 /proc/1/fdinfo

6 years agoterminal-util: helper macro for highlighting functions
Zbigniew Jędrzejewski-Szmek [Mon, 17 Oct 2016 15:48:12 +0000 (11:48 -0400)]
terminal-util: helper macro for highlighting functions

6 years agosystemctl: use underlines to seperate unit types in listing
Zbigniew Jędrzejewski-Szmek [Mon, 17 Oct 2016 15:37:41 +0000 (11:37 -0400)]
systemctl: use underlines to seperate unit types in listing

(printf("%.*s", -1, "…") is the same as not specifying the precision at all.)

v2: also underline highlighted (failing) units

Fixes #4137.

6 years agotree-wide: introduce free_and_replace helper
Zbigniew Jędrzejewski-Szmek [Sun, 16 Oct 2016 23:23:35 +0000 (19:23 -0400)]
tree-wide: introduce free_and_replace helper

It's a common pattern, so add a helper for it. A macro is necessary
because a function that takes a pointer to a pointer would be type specific,
similarly to cleanup functions. Seems better to use a macro.

6 years agotree-wide: use mfree more
Zbigniew Jędrzejewski-Szmek [Sun, 16 Oct 2016 22:28:30 +0000 (18:28 -0400)]
tree-wide: use mfree more

6 years agologinctl: report tty in session listings
Zbigniew Jędrzejewski-Szmek [Sun, 16 Oct 2016 19:13:03 +0000 (15:13 -0400)]
loginctl: report tty in session listings

Without the tty it's really hard to tell which session is which.

New output:
$ ./loginctl
   SESSION        UID USER             SEAT             TTY
        13       1002 zbyszek          seat0            tty3
        c1         42 gdm              seat0            /dev/tty1
        11       1002 zbyszek          seat0            tty4
         3       1002 zbyszek          seat0            /dev/tty2
        17       1002 zbyszek          seat0            tty5
        18       1002 zbyszek          seat0            tty6
6 sessions listed.

6 years agologinctl: drop casts in printf
Zbigniew Jędrzejewski-Szmek [Sun, 16 Oct 2016 18:19:06 +0000 (14:19 -0400)]
loginctl: drop casts in printf

6 years agovirt: add possibility to skip the check for chroot (#4374)
Lukáš Nykrýn [Sat, 15 Oct 2016 17:54:58 +0000 (19:54 +0200)]
virt: add possibility to skip the check for chroot (#4374)

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

6 years agocore: make settings for unified cgroup hierarchy supersede the ones for legacy hierar...
Tejun Heo [Sat, 15 Oct 2016 01:07:16 +0000 (21:07 -0400)]
core: make settings for unified cgroup hierarchy supersede the ones for legacy hierarchy (#4269)

There are overlapping control group resource settings for the unified and
legacy hierarchies.  To help transition, the settings are translated back and
forth.  When both versions of a given setting are present, the one matching the
cgroup hierarchy type in use is used.  Unfortunately, this is more confusing to
use and document than necessary because there is no clear static precedence.

Update the translation logic so that the settings for the unified hierarchy are
always preferred.  elogind.resource-control man page is updated to reflect the
change and reorganized so that the deprecated settings are at the end in its
own section.

6 years agonspawn: cleanup and chown the synced cgroup hierarchy (#4223)
Evgeny Vereshchagin [Thu, 13 Oct 2016 13:50:46 +0000 (16:50 +0300)]
nspawn: cleanup and chown the synced cgroup hierarchy (#4223)

Fixes: #4181
6 years agoman: typo fixes
Thomas Hindoe Paaboel Andersen [Wed, 12 Oct 2016 21:02:44 +0000 (23:02 +0200)]
man: typo fixes

A mix of fixes for typos and UK english

6 years agobasic: use for() loop instead of while()
Stefan Schweter [Wed, 12 Oct 2016 20:48:41 +0000 (22:48 +0200)]
basic: use for() loop instead of while()

6 years agoelogind-user: add pam_unix account module
Felipe Sateler [Wed, 12 Oct 2016 14:20:46 +0000 (11:20 -0300)]
elogind-user: add pam_unix account module

Otherwise elogind-user@ fails because elogind validates the account

Fixes: #4342
6 years agoAllow block and char classes in DeviceAllow bus properties (#4353)
Zbigniew Jędrzejewski-Szmek [Wed, 12 Oct 2016 09:12:11 +0000 (05:12 -0400)]
Allow block and char classes in DeviceAllow bus properties (#4353)

Allowed paths are unified betwen the configuration file parses and the bus
property checker. The biggest change is that the bus code now allows "block-"
and "char-" classes. In addition, path_startswith("/dev") was used in the bus
code, and startswith("/dev") was used in the config file code. It seems
reasonable to use path_startswith() which allows a slightly broader class of
strings.

Fixes #3935.

6 years agomissing: add a bunch of mount flags
Zbigniew Jędrzejewski-Szmek [Tue, 11 Oct 2016 21:24:03 +0000 (17:24 -0400)]
missing: add a bunch of mount flags

6 years agopager: tiny beautification
Lennart Poettering [Tue, 11 Oct 2016 15:46:59 +0000 (17:46 +0200)]
pager: tiny beautification

6 years agoman: expand the documentation of $SYSTEMD_PAGER and related environment variables
Lennart Poettering [Tue, 11 Oct 2016 15:45:49 +0000 (17:45 +0200)]
man: expand the documentation of $SYSTEMD_PAGER and related environment variables

Document the default pagers used, as well as $SYSTEMD_LESSCHARSET.

Fixes: #4143
6 years agonspawn,mount-util: add [u]mount_verbose and use it in nspawn
Zbigniew Jędrzejewski-Szmek [Mon, 10 Oct 2016 19:55:20 +0000 (15:55 -0400)]
nspawn,mount-util: add [u]mount_verbose and use it in nspawn

This makes it easier to debug failed nspawn invocations:

Mounting sysfs on /var/lib/machines/fedora-rawhide/sys (MS_RDONLY|MS_NOSUID|MS_NOEXEC|MS_NODEV "")...
Mounting tmpfs on /var/lib/machines/fedora-rawhide/dev (MS_NOSUID|MS_STRICTATIME "mode=755,uid=1450901504,gid=1450901504")...
Mounting tmpfs on /var/lib/machines/fedora-rawhide/dev/shm (MS_NOSUID|MS_NODEV|MS_STRICTATIME "mode=1777,uid=1450901504,gid=1450901504")...
Mounting tmpfs on /var/lib/machines/fedora-rawhide/run (MS_NOSUID|MS_NODEV|MS_STRICTATIME "mode=755,uid=1450901504,gid=1450901504")...
Bind-mounting /sys/fs/selinux on /var/lib/machines/fedora-rawhide/sys/fs/selinux (MS_BIND "")...
Remounting /var/lib/machines/fedora-rawhide/sys/fs/selinux (MS_RDONLY|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_BIND|MS_REMOUNT "")...
Mounting proc on /proc (MS_NOSUID|MS_NOEXEC|MS_NODEV "")...
Bind-mounting /proc/sys on /proc/sys (MS_BIND "")...
Remounting /proc/sys (MS_RDONLY|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_BIND|MS_REMOUNT "")...
Bind-mounting /proc/sysrq-trigger on /proc/sysrq-trigger (MS_BIND "")...
Remounting /proc/sysrq-trigger (MS_RDONLY|MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_BIND|MS_REMOUNT "")...
Mounting tmpfs on /tmp (MS_STRICTATIME "mode=1777,uid=0,gid=0")...
Mounting tmpfs on /sys/fs/cgroup (MS_NOSUID|MS_NOEXEC|MS_NODEV|MS_STRICTATIME "mode=755,uid=0,gid=0")...
Mounting cgroup on /sys/fs/cgroup/elogind (MS_NOSUID|MS_NOEXEC|MS_NODEV "none,name=elogind,xattr")...
Failed to mount cgroup on /sys/fs/cgroup/elogind (MS_NOSUID|MS_NOEXEC|MS_NODEV "none,name=elogind,xattr"): No such file or directory

6 years agologin: drop fedora-specific PAM config, add note to DISTRO_PORTING (#4314)
Felipe Sateler [Mon, 10 Oct 2016 13:40:05 +0000 (10:40 -0300)]
login: drop fedora-specific PAM config, add note to DISTRO_PORTING (#4314)

It is impossible to ship a fully generic PAM configuration upstream.
Therefore, ship a minimal configuration with the elogind --user requirements,
and add a note to DISTRO_PORTING documenting this.

Fixes #4284

6 years agonetworkd: address add support to configure flags (#4201)
Susant Sahani [Sat, 8 Oct 2016 11:05:41 +0000 (16:35 +0530)]
networkd: address add support to configure flags (#4201)

This patch enables to configure

IFA_F_HOMEADDRESS
IFA_F_NODAD
IFA_F_MANAGETEMPADDR
IFA_F_NOPREFIXROUTE
IFA_F_MCAUTOJOIN

6 years agouser-util: rework maybe_setgroups() a bit
Lennart Poettering [Thu, 6 Oct 2016 15:54:12 +0000 (17:54 +0200)]
user-util: rework maybe_setgroups() a bit

Let's drop the caching of the setgroups /proc field for now. While there's a
strict regime in place when it changes states, let's better not cache it since
we cannot really be sure we follow that regime correctly.

More importantly however, this is not in performance sensitive code, and
there's no indication the cache is really beneficial, hence let's drop the
caching and make things a bit simpler.

Also, while we are at it, rework the error handling a bit, and always return
negative errno-style error codes, following our usual coding style. This has
the benefit that we can sensible hanld read_one_line_file() errors, without
having to updat errno explicitly.

6 years agosd-bus: add DNS errors to the errno translation table
Lennart Poettering [Thu, 6 Oct 2016 14:01:44 +0000 (16:01 +0200)]
sd-bus: add DNS errors to the errno translation table

We generate these, hence we should also add errno translations for them.

6 years agosd-bus: add a few missing entries to the error translation tables
Lennart Poettering [Thu, 6 Oct 2016 13:50:30 +0000 (15:50 +0200)]
sd-bus: add a few missing entries to the error translation tables

These were forgotten, let's add some useful mappings for all errors we define.

6 years agosd-device/networkd: unify code to get a socket for issuing netdev ioctls on
Lennart Poettering [Thu, 6 Oct 2016 13:48:15 +0000 (15:48 +0200)]
sd-device/networkd: unify code to get a socket for issuing netdev ioctls on

As suggested here:

https://github.com/elogind/elogind/pull/4296#issuecomment-251911349

Let's try AF_INET first as socket, but let's fall back to AF_NETLINK, so that
we can use a protocol-independent socket here if possible. This has the benefit
that our code will still work even if AF_INET/AF_INET6 is made unavailable (for
exmple via seccomp), at least on current kernels.

6 years agolist: LIST_INSERT_BEFORE: update head if necessary (#4261)
Michael Olbrich [Tue, 4 Oct 2016 14:15:37 +0000 (16:15 +0200)]
list: LIST_INSERT_BEFORE: update head if necessary (#4261)

If the new item is inserted before the first item in the list, then the
head must be updated as well.
Add a test to the list unit test to check for this.

6 years agotree-wide: remove consecutive duplicate words in comments
Stefan Schweter [Sun, 2 Oct 2016 17:37:21 +0000 (19:37 +0200)]
tree-wide: remove consecutive duplicate words in comments

6 years agopath-util: add a function to peek into a container and guess elogind version
Zbigniew Jędrzejewski-Szmek [Sun, 2 Oct 2016 13:51:27 +0000 (15:51 +0200)]
path-util: add a function to peek into a container and guess elogind version

This is a bit crude and only works for new elogind versions which
have libelogind-shared.

6 years agocore: do not fail in a container if we can't use setgroups
Giuseppe Scrivano [Wed, 28 Sep 2016 16:37:39 +0000 (18:37 +0200)]
core: do not fail in a container if we can't use setgroups

It might be blocked through /proc/PID/setgroups

6 years agoaudit: disable if cannot create NETLINK_AUDIT socket
Giuseppe Scrivano [Wed, 28 Sep 2016 16:26:25 +0000 (18:26 +0200)]
audit: disable if cannot create NETLINK_AUDIT socket

6 years agobasic: fix for IPv6 status (#4224)
Susant Sahani [Tue, 27 Sep 2016 13:55:13 +0000 (19:25 +0530)]
basic: fix for IPv6 status (#4224)

Even if
```
   cat /proc/sys/net/ipv6/conf/all/disable_ipv6
1
```

is disabled

cat /proc/net/sockstat6

```
TCP6: inuse 2
UDP6: inuse 1
UDPLITE6: inuse 0
RAW6: inuse 0
FRAG6: inuse 0 memory 0
 ```

Looking for /proc/net/if_inet6 is the right choice.

6 years agonamespace: rework how ReadWritePaths= is applied
Lennart Poettering [Sun, 25 Sep 2016 08:40:51 +0000 (10:40 +0200)]
namespace: rework how ReadWritePaths= is applied

Previously, if ReadWritePaths= was nested inside a ReadOnlyPaths=
specification, then we'd first recursively apply the ReadOnlyPaths= paths, and
make everything below read-only, only in order to then flip the read-only bit
again for the subdirs listed in ReadWritePaths= below it.

This is not only ugly (as for the dirs in question we first turn on the RO bit,
only to turn it off again immediately after), but also problematic in
containers, where a container manager might have marked a set of dirs read-only
and this code will undo this is ReadWritePaths= is set for any.

With this patch behaviour in this regard is altered: ReadOnlyPaths= will not be
applied to the children listed in ReadWritePaths= in the first place, so that
we do not need to turn off the RO bit for those after all.

This means that ReadWritePaths=/ReadOnlyPaths= may only be used to turn on the
RO bit, but never to turn it off again. Or to say this differently: if some
dirs are marked read-only via some external tool, then ReadWritePaths= will not
undo it.

This is not only the safer option, but also more in-line with what the man page
currently claims:

        "Entries (files or directories) listed in ReadWritePaths= are
        accessible from within the namespace with the same access rights as
        from outside."

To implement this change bind_remount_recursive() gained a new "blacklist"
string list parameter, which when passed may contain subdirs that shall be
excluded from the read-only mounting.

A number of functions are updated to add more debug logging to make this more
digestable.

6 years agobasic/strv: add STRPTR_IN_SET
Zbigniew Jędrzejewski-Szmek [Sun, 25 Sep 2016 00:13:28 +0000 (20:13 -0400)]
basic/strv: add STRPTR_IN_SET

Also some trivial tests for STR_IN_SET and STRPTR_IN_SET.

6 years agonamespace: chase symlinks for mounts to set up in userspace
Lennart Poettering [Sat, 24 Sep 2016 10:41:30 +0000 (12:41 +0200)]
namespace: chase symlinks for mounts to set up in userspace

This adds logic to chase symlinks for all mount points that shall be created in
a namespace environment in userspace, instead of leaving this to the kernel.
This has the advantage that we can correctly handle absolute symlinks that
shall be taken relative to a specific root directory. Moreover, we can properly
handle mounts created on symlinked files or directories as we can merge their
mounts as necessary.

(This also drops the "done" flag in the namespace logic, which was never
actually working, but was supposed to permit a partial rollback of the
namespace logic, which however is only mildly useful as it wasn't clear in
which case it would or would not be able to roll back.)

Fixes: #3867
6 years agologind: fix /run/user/$UID creation in apparmor-confined containers (#4154)
Tomáš Janoušek [Thu, 15 Sep 2016 23:26:31 +0000 (01:26 +0200)]
logind: fix /run/user/$UID creation in apparmor-confined containers (#4154)

When a docker container is confined with AppArmor [1] and happens to run
on top of a kernel that supports mount mediation [2], e.g. any Ubuntu
kernel, mount(2) returns EACCES instead of EPERM.  This then leads to:

    elogind-logind[33]: Failed to mount per-user tmpfs directory /run/user/1000: Permission denied
    login[42]: pam_elogind(login:session): Failed to create session: Access denied

and user sessions don't start.

This also applies to selinux that too returns EACCES on mount denial.

[1] https://github.com/docker/docker/blob/master/docs/security/apparmor.md#understand-the-policies
[2] http://bazaar.launchpad.net/~apparmor-dev/apparmor/master/view/head:/kernel-patches/4.7/0025-UBUNTU-SAUCE-apparmor-Add-the-ability-to-mediate-mou.patch

6 years agotime-util: export timespec_load_nsec()
Ivan Shapovalov [Thu, 15 Sep 2016 02:19:31 +0000 (05:19 +0300)]
time-util: export timespec_load_nsec()

6 years agofileio: simplify mkostemp_safe() (#4090)
Topi Miettinen [Tue, 13 Sep 2016 06:20:38 +0000 (06:20 +0000)]
fileio: simplify mkostemp_safe() (#4090)

According to its manual page, flags given to mkostemp(3) shouldn't include
O_RDWR, O_CREAT or O_EXCL flags as these are always included. Beyond
those, the only flag that all callers (except a few tests where it
probably doesn't matter) use is O_CLOEXEC, so set that unconditionally.

6 years agoAlways use unicode ellipsis when ellipsizing
Zbigniew Jędrzejewski-Szmek [Mon, 12 Sep 2016 19:09:36 +0000 (20:09 +0100)]
Always use unicode ellipsis when ellipsizing

We were already unconditionally using the unicode character when the
input string was not pure ASCII, leading to different behaviour in
depending on the input string.

elogind[1]: Starting printit.service.
python3[19962]: foooooooooooooooooooooooooooooooooooo…oooo
python3[19964]: fooąęoooooooooooooooooooooooooooooooo…oooo
python3[19966]: fooąęoooooooooooooooooooooooooooooooo…ąęąę
python3[19968]: fooąęoooooooooooooooooąęąęąęąęąęąęąęą…ąęąę
elogind[1]: Started printit.service.

6 years agoshared/conf-parser: add config_parse_many which takes strv with dirs
Zbigniew Jędrzejewski-Szmek [Sat, 10 Sep 2016 11:19:41 +0000 (12:19 +0100)]
shared/conf-parser: add config_parse_many which takes strv with dirs

This way we don't have to create a nulstr just to unpack it in a moment.

6 years agotree-wide: rename config_parse_many to …_nulstr
Zbigniew Jędrzejewski-Szmek [Sat, 10 Sep 2016 10:02:40 +0000 (11:02 +0100)]
tree-wide: rename config_parse_many to …_nulstr

In preparation for adding a version which takes a strv.

6 years agosd-bus: bump message queue size
Lennart Poettering [Wed, 31 Aug 2016 18:09:31 +0000 (20:09 +0200)]
sd-bus: bump message queue size

Let's bump it further, as this the current limit turns out to be problematic
IRL. Let's bump it to more than twice what we know of is needed.

Fixes: #4068
6 years agomachinectl: split OS field in two; print ip addresses (#4058)
Seraphime Kirkovski [Wed, 31 Aug 2016 18:06:57 +0000 (21:06 +0300)]
machinectl: split OS field in two; print ip addresses (#4058)

This splits the OS field in two : one for the distribution name
and one for the the version id.
Dashes are written for missing fields.
This also prints ip addresses of known machines. The `--max-addresses`
option specifies how much ip addresses we want to see. The default is 1.
When more than one address is written for a machine, a `,` follows it.
If there are more ips than `--max-addresses`, `...` follows the last
address.

6 years agonetworkd: add options to bridge (#4051)
Tobias Jungel [Wed, 31 Aug 2016 18:06:23 +0000 (20:06 +0200)]
networkd: add options to bridge (#4051)

This patch allows to configure AgeingTimeSec, Priority and DefaultPVID for
bridge interfaces.

6 years agocore: add "invocation ID" concept to service manager
Lennart Poettering [Tue, 30 Aug 2016 21:18:46 +0000 (23:18 +0200)]
core: add "invocation ID" concept to service manager

This adds a new invocation ID concept to the service manager. The invocation ID
identifies each runtime cycle of a unit uniquely. A new randomized 128bit ID is
generated each time a unit moves from and inactive to an activating or active
state.

The primary usecase for this concept is to connect the runtime data PID 1
maintains about a service with the offline data the journal stores about it.
Previously we'd use the unit name plus start/stop times, which however is
highly racy since the journal will generally process log data after the service
already ended.

The "invocation ID" kinda matches the "boot ID" concept of the Linux kernel,
except that it applies to an individual unit instead of the whole system.

The invocation ID is passed to the activated processes as environment variable.
It is additionally stored as extended attribute on the cgroup of the unit. The
latter is used by journald to automatically retrieve it for each log logged
message and attach it to the log entry. The environment variable is very easily
accessible, even for unprivileged services. OTOH the extended attribute is only
accessible to privileged processes (this is because cgroupfs only supports the
"trusted." xattr namespace, not "user."). The environment variable may be
altered by services, the extended attribute may not be, hence is the better
choice for the journal.

Note that reading the invocation ID off the extended attribute from journald is
racy, similar to the way reading the unit name for a logging process is.

This patch adds APIs to read the invocation ID to sd-id128:
sd_id128_get_invocation() may be used in a similar fashion to
sd_id128_get_boot().

PID1's own logging is updated to always include the invocation ID when it logs
information about a unit.

A new bus call GetUnitByInvocationID() is added that allows retrieving a bus
path to a unit by its invocation ID. The bus path is built using the invocation
ID, thus providing a path for referring to a unit that is valid only for the
current runtime cycleof it.

Outlook for the future: should the kernel eventually allow passing of cgroup
information along AF_UNIX/SOCK_DGRAM messages via a unique cgroup id, then we
can alter the invocation ID to be generated as hash from that rather than
entirely randomly. This way we can derive the invocation race-freely from the
messages.

6 years agoutil: use SPECIAL_ROOT_SLICE macro where appropriate
Lennart Poettering [Tue, 30 Aug 2016 19:49:26 +0000 (21:49 +0200)]
util: use SPECIAL_ROOT_SLICE macro where appropriate

6 years agolog: minor fixes
Lennart Poettering [Tue, 30 Aug 2016 19:02:36 +0000 (21:02 +0200)]
log: minor fixes

Most important is a fix to negate the error number if necessary, before we
first access it.

6 years agobasic/fileio: we always have O_TMPFILE now
Yann E. MORIN [Mon, 29 Aug 2016 10:34:50 +0000 (12:34 +0200)]
basic/fileio: we always have O_TMPFILE now

fileio makes use of O_TMPFILE when it is available.

We now always have O_TMPFILE, defined in missing.h if missing
from the toolchain headers.

Have fileio include missing.h and drop the guards around the
use of O_TMPFILE.

6 years agomissing.h: add missing definitions for __O_TMPFILE
Yann E. MORIN [Sun, 28 Aug 2016 15:26:42 +0000 (17:26 +0200)]
missing.h: add missing definitions for __O_TMPFILE

Currently, a missing __O_TMPFILE was only defined for i386 and x86_64,
leaving any other architectures with an "old" toolchain fail miserably
at build time:
    src/import/export-raw.c: In function 'reflink_snapshot':
    src/import/export-raw.c:271:26: error: 'O_TMPFILE' undeclared (first use in this function)
             new_fd = open(d, O_TMPFILE|O_CLOEXEC|O_NOCTTY|O_RDWR, 0600);
                              ^

__O_TMPFILE (and O_TMPFILE) are available since glibc 2.19. However, a
lot of existing toolchains are still using glibc-2.18, and some even
before that, and it is not really possible to update those toolchains.

Instead of defining it only for i386 and x86_64, define __O_TMPFILE
with the specific values for those archs where it is different from the
generic value. Use the values as found in the Linux kernel (v4.8-rc3,
current as of time of commit).

6 years agobus-util: generalize helper for ID128 prpoerties
Lennart Poettering [Fri, 26 Aug 2016 17:20:02 +0000 (19:20 +0200)]
bus-util: generalize helper for ID128 prpoerties

This way, we can make use of this in other code, too.

6 years agostrv: fix STRV_FOREACH_BACKWARDS() to be a single statement only
Lennart Poettering [Fri, 26 Aug 2016 17:18:15 +0000 (19:18 +0200)]
strv: fix STRV_FOREACH_BACKWARDS() to be a single statement only

Let's make sure people invoking STRV_FOREACH_BACKWARDS() as a single statement
of an if statement don't fall into a trap, and find the tail for the list via
strv_length().

6 years agoexecute: move suppression of HOME=/ and SHELL=/bin/nologin into user-util.c
Lennart Poettering [Thu, 25 Aug 2016 08:24:10 +0000 (10:24 +0200)]
execute: move suppression of HOME=/ and SHELL=/bin/nologin into user-util.c

This adds a new call get_user_creds_clean(), which is just like
get_user_creds() but returns NULL in the home/shell parameters if they contain
no useful information. This code previously lived in execute.c, but by
generalizing this we can reuse it in run.c.

6 years agobus-util: turn on exit-on-disconnect for all command line tools
Lennart Poettering [Mon, 22 Aug 2016 15:21:27 +0000 (17:21 +0200)]
bus-util: turn on exit-on-disconnect for all command line tools

bus_connect_transport() is exclusively used from our command line tools, hence
let's set exit-on-disconnect for all of them, making behaviour a bit nicer in
case dbus-daemon goes down.

6 years agosd-bus: optionally, exit process or event loop on disconnect
Lennart Poettering [Mon, 22 Aug 2016 15:19:12 +0000 (17:19 +0200)]
sd-bus: optionally, exit process or event loop on disconnect

Old libdbus has a feature that the process is terminated whenever the the bus
connection receives a disconnect. This is pretty useful on desktop apps (where
a disconnect indicates session termination), as well as on command line apps
(where we really shouldn't stay hanging in most cases if dbus daemon goes
down).

Add a similar feature to sd-bus, but make it opt-in rather than opt-out, like
it is on libdbus. Also, if the bus is attached to an event loop just exit the
event loop rather than the the whole process.

6 years agosd-bus: when the server-side disconnects, make sure to dispatch all tracking objects...
Lennart Poettering [Mon, 22 Aug 2016 14:11:54 +0000 (16:11 +0200)]
sd-bus: when the server-side disconnects, make sure to dispatch all tracking objects immediately

If the server side kicks us from the bus, from our view no names are on the bus
anymore, hence let's make sure to dispatch all tracking objects immediately.

6 years agosd-bus: ensure we don't dispatch track objects while we are adding names to them
Lennart Poettering [Mon, 22 Aug 2016 14:09:15 +0000 (16:09 +0200)]
sd-bus: ensure we don't dispatch track objects while we are adding names to them

In order to add a name to a bus tracking object we need to do some bus
operations: we need to check if the name already exists and add match for it.
Both are synchronous bus calls. While processing those we need to make sure
that the tracking object is not dispatched yet, as it might still be empty, but
is not going to be empty for very long.

hence, block dispatching by removing the object from the dispatch queue while
adding it, and readding it on error.