Commit graph

1591 commits

Author SHA1 Message Date
Lennart Poettering 3cc4411403 stat-util: unify code that checks whether something is a regular file
Let's add a common implementation for regular file checks, that are
careful to return the right error code (EISDIR/EISLNK/EBADFD) when we
are encountering a wrong file node.
2018-02-20 15:39:31 +01:00
Zbigniew Jędrzejewski-Szmek f95dbcc27b Some comment adjustments
Follow up for review of #8184.
2018-02-19 15:18:54 +01:00
Zbigniew Jędrzejewski-Szmek 9ecdba8cb7 Move config_parse_join_controllers to shared, add test
config_parse_join_controllers would free the destination argument on failure,
which is contrary to our normal style, where failed parsing has no effect.
Moving it to shared also allows a test to be added.
2018-02-19 15:02:13 +01:00
Zbigniew Jędrzejewski-Szmek af229d7a5b login,user-sessions: always warn when we fail to remove nologin file
This usually is very annoying to users who then cannot log in, so
make sure we always warn if that happens (selinux, or whatever other reason).

This reverts a790812cb3.
2018-02-16 10:44:22 +01:00
Zbigniew Jędrzejewski-Szmek 730f40eb57 Merge pull request #8184 from poettering/color-ask-pw
Trivial merge conflict resolved locally.
2018-02-15 17:14:59 +01:00
Zbigniew Jędrzejewski-Szmek 648461c07d Merge pull request #8125 from poettering/cgroups-migrate
Trivial merge conflict resolved locally.
2018-02-15 16:15:45 +01:00
Lennart Poettering 65ee8660df utf8: add utf8_n_codepoints() for counting complete utf8 codepoints in a string 2018-02-14 18:41:03 +01:00
Lennart Poettering 7b91264852 terminal-util: make resolve_dev_console() less weird
Let's normalize the behaviour: return a negative errno style error code,
and return the resolved string directly as argument.
2018-02-14 17:30:37 +01:00
Lennart Poettering bef41af233 terminal-util: modernize get_kernel_consoles() a bit
Also, make sure when we run in a container, we don't use the data from
/sys at all, but immediately fall back to /dev/console itself.
2018-02-14 14:56:17 +01:00
Lennart Poettering c2b3215941 tty-ask-password-agent: reenable color for boot-time password prompt
The password prompt used to be highlighted, and that was a good thing.
Let's fix things to make the prompt highlighted again.

Fixes: #3853
2018-02-14 14:30:30 +01:00
Lennart Poettering 0295642dda terminal-util: add some explanatory comments 2018-02-14 14:28:17 +01:00
Lennart Poettering e70f445306 process: shortcut getenv_for_pid() for our own process 2018-02-14 14:27:31 +01:00
Lennart Poettering 87964ec7d1 terminal-util: minor, trivial fixes and improvements 2018-02-13 23:53:34 +01:00
Lennart Poettering c6063244db terminal-util: when making /dev/null or the console stdio, forget cached terminal features
Let's forget all relevant terminal features we learnt when we make a
console or /dev/null stdin/stdout/stderr.

Also, while we are at it, let's drop the various _unlikely_ and
_likely_ annotiations around the terminal feature caches. In many cases
we call the relevant functions only once in which cases the annotations
are likely to do just harm and no good. After all we can't know if the
specific code will call us just once or many times...
2018-02-13 23:50:26 +01:00
Lennart Poettering 8854d79504 terminal-util: rework acquire_terminal()
This modernizes acquire_terminal() in a couple of ways:

1. The three boolean arguments are replaced by a flags parameter, that
   should be more descriptive in what it does.

2. We now properly handle inotify queue overruns

3. We use _cleanup_ for closing the fds now, to shorten the code quite a
   bit.

Behaviour should not be altered by this.
2018-02-13 21:24:37 +01:00
Lennart Poettering 7cb609115c user-util: also consider /bin/false and /bin/true as non-shell 2018-02-12 11:34:00 +01:00
Lennart Poettering 36b5119a0c process-util: be more careful in is_kernel_thread()
This reworks is_kernel_thread() a bit. Instead of checking whether
/proc/$pid/cmdline is entirely empty we now parse the 'flags' field from
/proc/$pid/stat and check the PF_KTHREAD flag, which directly encodes
whether something is a kernel thread.

Why all this? With current kernels userspace processes can set their
command line to empty too (through PR_SET_MM_ARG_START and friends), and
could potentially confuse us. Hence, let's use a more reliable way to
detect kernels like this.
2018-02-12 11:34:00 +01:00
Lennart Poettering e7279ce82d rm-rf: make flags fields easier to read 2018-02-12 11:27:11 +01:00
Lennart Poettering 43767d9d5e fs-util: add new unlinkat_deallocate() helper
This new helper not only removes a file from a directory but also
ensures its space on disk is deallocated, by either punching a hole over
the full file or truncating the file afterwards if the file's link
counter is 0. This is useful in "vacuuming" algorithms to ensure that
client's can't keep the disk space the vacuuming is supposed to recover
pinned simply by keeping an fd open to it.
2018-02-12 11:27:11 +01:00
Lennart Poettering 7b938dfb8d copy: wrap some unlink() calls in (void) casts 2018-02-12 11:07:55 +01:00
Lennart Poettering 548f69375e tree-wide: use path_hash_ops instead of string_hash_ops whenever we key by a path
Let's make use of our new hash_ops!
2018-02-12 11:07:55 +01:00
Lennart Poettering 46e16b347f hash-func: add generic hash_ops implementation for hashing paths
This is similar to string_hash_ops but operates one file system paths
specifically. It will ensure that "/foo//bar" and "///foo/bar" are
considered to be the same path for hashmap purposes.

This makes use of the existing path_compare() API, and adds a matching
hashing function for it.

Note that relative and absolute paths will hash to different values,
however whether the path is suffixed with a slash or not is not
detected. This matches the existing path_compare() behaviour, and
follows the logic that on Linux there can't be two different objects at
path /foo/bar and /foo/bar/ either.
2018-02-12 11:07:55 +01:00
Lennart Poettering 9bac7d423f hash-funcs: remove redundant definition of devt_hash_ops
We should assign a value only in the .c file, not in both the .c and .h
file.
2018-02-12 11:07:55 +01:00
Lennart Poettering 77f9fa3b8e journal: move code that checks for network fs to stat-util.[ch]
We have similar code in stat-util.[ch] and managing this at a central
place almost definitely is the better choice.
2018-02-12 11:07:55 +01:00
Yu Watanabe b8e2400586
Merge pull request #8143 from yuwata/drop-unused-func
Drop several unused functions
2018-02-10 12:47:12 +09:00
Yu Watanabe 92db49a0c2 socket-util: drop getnameinfo_pretty() 2018-02-10 11:10:07 +09:00
Zbigniew Jędrzejewski-Szmek cadc80b873 basic/socket-util: drop use of NI_IDN_USE_STD3_ASCII_RULES
The only use of socknameinfo_pretty() is in src/journal-remote/journal-remote.c,
to determine the output filename.

Replaces #8120.
2018-02-09 19:29:51 +01:00
Lennart Poettering 7fe2903c23 fd-util: move certain fds above fd #2 (#8129)
This adds some paranoia code that moves some of the fds we allocate for
longer periods of times to fds > 2 if they are allocated below this
boundary. This is a paranoid safety thing, in order to avoid that
external code might end up erroneously use our fds under the assumption
they were valid stdin/stdout/stderr. Think: some app closes
stdin/stdout/stderr and then invokes 'fprintf(stderr, …' which causes
writes on our fds.

This both adds the helper to do the moving as well as ports over a
number of users to this new logic. Since we don't want to litter all our
code with invocations of this I tried to strictly focus on fds we keep
open for long periods of times only and only in code that is frequently
loaded into foreign programs (under the assumptions that in our own
codebase we are smart enough to always keep stdin/stdout/stderr
allocated to avoid this pitfall). Specifically this means all code used
by NSS and our sd-xyz API:

1. our logging APIs
2. sd-event
3. sd-bus
4. sd-resolve
5. sd-netlink

This changed was inspired by this:

https://github.com/systemd/systemd/issues/8075#issuecomment-363689755

This shows that apparently IRL there are programs that do close
stdin/stdout/stderr, and we should accomodate for that.

Note that this won't fix any bugs, this just makes sure that buggy
programs are less likely to interfere with out own code.
2018-02-09 17:53:28 +01:00
Yu Watanabe 01e4793de6 fs-util: drop readlink_and_make_absolute_root() 2018-02-09 16:58:56 +09:00
Yu Watanabe 842e456e79 fs-util: drop readlink_and_canonicalize() 2018-02-09 16:49:54 +09:00
Shawn Landden 392cf1d05d sd-bus: cleanup ssh sessions (Closes: #8076)
we still invoke ssh unnecessarily when there in incompatible or erreneous input
The fallow-up to finish that would make the code a bit more verbose,
as it would require repeating this bit:
```
        r = bus_connect_transport(arg_transport, arg_host, false, &bus);
        if (r < 0) {
                log_error_errno(r, "Failed to create bus connection: %m");
                goto finish;
        }

        sd_bus_set_allow_interactive_authorization(bus, arg_ask_password);
```
in every verb, after parsing.

v2: add waitpid() to avoid a zombie process, switch to SIGTERM from SIGKILL
v3: refactor, wait in bus_start_address()
2018-02-08 10:14:48 -08:00
Lennart Poettering a166e13771
Merge pull request #8104 from keszybz/tmpfiles-allow-overrides
tmpfiles allow overrides
2018-02-07 12:12:52 +01:00
Lennart Poettering 996def17f9 process-util: use raw_getpid() in getpid_cache() internally (#8115)
We have the raw_getpid() definition in place anyway, and it's certainly
beneficial to expose the same semantics on pre glibc 2.24 and after it
too, hence always bypass glibc for this, and always cache things on our
side.

Fixes: #8113
2018-02-07 11:10:09 +09:00
Yu Watanabe 34cf6c4340 core/execute: make arguments constant if possible
Also make functions static if possible.
2018-02-06 16:00:50 +09:00
Lennart Poettering 960c7c2791
Merge pull request #8101 from keszybz/two-gcc-workarounds
Two gcc workarounds
2018-02-05 18:59:52 +01:00
Zbigniew Jędrzejewski-Szmek 1fe101747c basic/glob-util: add closedir wrapper to silence gcc
../src/test/test-glob-util.c: In function 'test_glob_no_dot':
../src/test/test-glob-util.c:61:32: warning: cast between incompatible function types from 'int (*)(DIR *)' {aka 'int (*)(struct __dirstream *)'} to 'void (*)(void *)' [-Wcast-function-type]
                 .gl_closedir = (void (*)(void *)) closedir,
                                ^
2018-02-05 15:20:46 +01:00
Zbigniew Jędrzejewski-Szmek a6d8474f39 tmpfiles: allow admin/runtime overrides to runtime config
This is very similar to d16a1c1bb6. For tmpfiles this is much less useful
compared to sysusers, but let's add this anyway for consistency.
2018-02-05 15:04:52 +01:00
Zbigniew Jędrzejewski-Szmek bd944e6e18 gcrypt-util: fix memleak 2018-02-05 09:55:03 +01:00
Yu Watanabe 24c2c5689d
Merge pull request #8058 from keszybz/sysusers-inline
Extend sysusers for package installation scripts
2018-02-05 16:50:51 +09:00
MilhouseVH ec79af69a1 kernel 3.10 compat: RTAX_QUICKACK not added until 3.11.0 (#8094) 2018-02-05 14:26:57 +09:00
Yu Watanabe cf6e1e6333
Merge pull request #8073 from keszybz/two-fixes
Two fixes
2018-02-03 20:11:17 +09:00
Vito Caputo 75f4077960 socket-util: fix getpeergroups() assert(fd) (#8080)
Don't assert on zero-value fds.

Fixes #8075.
2018-02-03 20:09:08 +09:00
Zbigniew Jędrzejewski-Szmek afbbc0682e basic/hashmap: tweak code to avoid pointless gcc warning
gcc says:
[196/1142] Compiling C object 'src/basic/basic@sta/hashmap.c.o'.
../src/basic/hashmap.c: In function ‘cachemem_maintain’:
../src/basic/hashmap.c:1913:17: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
                 mem->active = r = true;
                 ^~~

which conflates two things: the first is transitive assignent a = b = c = d;
the second is assignment of the value of an expression, which happens to be a
an assignment expression here, and boolean. While the second _should_ be
parenthesized, the first should _not_, and it's more natural to understand
our code as the first, and gcc should treat this as an exception and not emit
the warning. But since it's a while until this will be fixed, let's update
our code too.
2018-02-02 14:34:00 +01:00
Zbigniew Jędrzejewski-Szmek d16a1c1bb6 sysusers: allow admin/runtime overrides to command-line config
When used in a package installation script, we want to invoke systemd-sysusers
before that package is installed (so it can contain files owned by the newly
created user), so the configuration to use is specified on the command
line. This should be a copy of the configuration that will be installed as
/usr/lib/sysusers.d/package.conf. We still want to obey any overrides in
/etc/sysusers.d or /run/sysusers.d in the usual fashion. Otherwise, we'd get a
different result when systemd-sysusers is run with a copy of the new config on
the command line and when systemd-sysusers is run at boot after package
instalation. In the second case any files in /etc or /run have higher priority,
so the same should happen when the configuration is given on the command line.
More generally, we want the behaviour in this special case to be as close to
the case where the file is finally on disk as possible, so we have to read all
configuration files, since they all might contain overrides and additional
configuration that matters. Even files that have lower priority might specify
additional groups for the user we are creating. Thus, we need to read all
configuration, but insert our new configuration somewhere with the right
priority.

If --target=/path/to/file.conf is given on the command line, we gather the list
of files, and pretend that the command-line config is read from
/path/to/file.conf (doesn't matter if the file on disk actually exists or
not). All package scripts should use this option to obtain consistent and
idempotent behaviour.

The corner case when --target= is specified and there are no positional
arguments is disallowed.

v1:
- version with --config-name=
v2:
- disallow --config-name= and no positional args
v3:
- remove --config-name=
v4:
- add --target= and rework the code completely
v5:
- fix argcounting bug and add example in man page
v6:
- rename --target to --replace
2018-02-02 10:40:22 +01:00
Zbigniew Jędrzejewski-Szmek 6e888894fc basic/strv: add function to insert items at position 2018-02-02 10:35:30 +01:00
Zbigniew Jędrzejewski-Szmek 7b1aaf6633 sysusers: allow the shell to be specified
This is necessary for some system users where the "login shell" is
set to a specific binary.
2018-02-02 10:35:30 +01:00
Zbigniew Jędrzejewski-Szmek d1e4b8fd96 sysusers: emit a bit more info at debug level when locking fails
This is the first error message when running unprivileged, and the message is
unspecific, so let's at least add some logging at debug level to make this less
confusing.
2018-02-02 09:09:24 +01:00
Lennart Poettering 52dca0de99
Merge pull request #7042 from vcaputo/iteratedcache
RFC: Optionally cache hashmap iterated results
2018-02-01 18:08:50 +01:00
Yu Watanabe e7b2ea7c97 strv: drop strv_join_quoted() (#8057)
The function `strv_join_quoted()` is now not used, and has a bug
in the buffer size calculation when the strings needs to escaped,
as reported in #8056.
So, let's remove the function.

Closes #8056.
2018-02-01 10:11:02 +01:00
Lennart Poettering 7755083256
Merge pull request #7881 from keszybz/pcre
Add new --grep option to journalctl
2018-01-28 15:29:10 +01:00