summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAge
...
* sd-bus: synthesize a description for user/system bus if otherwise unsetLennart Poettering2018-05-30
| | | | | Let's make debugging easier, by synthesizing a name when we have some indication what kind of bus this is.
* user-util: also consider /bin/false and /bin/true as non-shellLennart Poettering2018-05-30
|
* process-util: be more careful in is_kernel_thread()Lennart Poettering2018-05-30
| | | | | | | | | | | | 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.
* cgroup: add a new "can_delegate" flag to the unit vtable, and set it for ↵Lennart Poettering2018-05-30
| | | | | | | | | | | | | | | | scope and service units only Currently we allowed delegation for alluntis with cgroup backing except for slices. Let's make this a bit more strict for now, and only allow this in service and scope units. Let's also add a generic accessor unit_cgroup_delegate() for checking whether a unit has delegation turned on that checks the new bool first. Also, when doing transient units, let's explcitly refuse turning on delegation for unit types that don#t support it. This is mostly cosmetical as we wouldn't act on the delegation request anyway, but certainly helpful for debugging.
* meson: factor out daemon/event/id128 sources into variables (#8170)Davide Cavalca2018-05-30
|
* rm-rf: make flags fields easier to readLennart Poettering2018-05-30
|
* fs-util: add new unlinkat_deallocate() helperLennart Poettering2018-05-30
| | | | | | | | | 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.
* copy: wrap some unlink() calls in (void) castsLennart Poettering2018-05-30
|
* tree-wide: use path_hash_ops instead of string_hash_ops whenever we key by a ↵Lennart Poettering2018-05-30
| | | | | | path Let's make use of our new hash_ops!
* hash-func: add generic hash_ops implementation for hashing pathsLennart Poettering2018-05-30
| | | | | | | | | | | | | | | 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.
* hash-funcs: remove redundant definition of devt_hash_opsLennart Poettering2018-05-30
| | | | | We should assign a value only in the .c file, not in both the .c and .h file.
* journal: move code that checks for network fs to stat-util.[ch]Lennart Poettering2018-05-30
| | | | | We have similar code in stat-util.[ch] and managing this at a central place almost definitely is the better choice.
* socket-util: drop getnameinfo_pretty()Yu Watanabe2018-05-30
|
* fs-util: drop readlink_and_make_absolute_root()Yu Watanabe2018-05-30
|
* fs-util: drop readlink_and_canonicalize()Yu Watanabe2018-05-30
|
* basic/socket-util: drop use of NI_IDN_USE_STD3_ASCII_RULESZbigniew Jędrzejewski-Szmek2018-05-30
| | | | | | | The only use of socknameinfo_pretty() is in src/journal-remote/journal-remote.c, to determine the output filename. Replaces #8120.
* fd-util: move certain fds above fd #2 (#8129)Lennart Poettering2018-05-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Suspend on lid close based on power status. (#8016)Simon Fowler2018-05-30
| | | | | | | | This change adds support for controlling the suspend-on-lid-close behaviour based on the power status as well as whether the machine is docked or has an external monitor. For backwards compatibility the new configuration file variable is ignored completely by default, and must be set explicitly before being considered in any decisions.
* sd-bus: cleanup ssh sessions (Closes: #8076)Shawn Landden2018-05-30
| | | | | | | | | | | | | | | | | | | 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()
* sd-bus: explicitly convert int to boolYu Watanabe2018-05-30
|
* sd-bus: use free_and_replace()Yu Watanabe2018-05-30
|
* sd-bus: avoid potential memory leaksYu Watanabe2018-05-30
|
* tmpfiles: allow admin/runtime overrides to runtime configZbigniew Jędrzejewski-Szmek2018-05-30
| | | | | This is very similar to d16a1c1bb6. For tmpfiles this is much less useful compared to sysusers, but let's add this anyway for consistency.
* process-util: use raw_getpid() in getpid_cache() internally (#8115)Lennart Poettering2018-05-30
| | | | | | | | | 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
* core/execute: make arguments constant if possibleYu Watanabe2018-05-30
| | | | Also make functions static if possible.
* sysusers: allow admin/runtime overrides to command-line configZbigniew Jędrzejewski-Szmek2018-05-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* basic/strv: add function to insert items at positionZbigniew Jędrzejewski-Szmek2018-05-30
|
* sysusers: allow the shell to be specifiedZbigniew Jędrzejewski-Szmek2018-05-30
| | | | | This is necessary for some system users where the "login shell" is set to a specific binary.
* sysusers: emit a bit more info at debug level when locking failsZbigniew Jędrzejewski-Szmek2018-05-30
| | | | | | 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.
* kernel 3.10 compat: RTAX_QUICKACK not added until 3.11.0 (#8094)MilhouseVH2018-05-30
|
* basic/hashmap: tweak code to avoid pointless gcc warningZbigniew Jędrzejewski-Szmek2018-05-30
| | | | | | | | | | | | | | | | | 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.
* test-hashmap: test IteratedCacheVito Caputo2018-05-30
| | | | Add some rudimentary testing of the new IteratedCache
* basic: implement the IteratedCacheVito Caputo2018-05-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Adds the basics of the IteratedCache and constructor support for the Hashmap and OrderedHashmap types. iterated_cache_get() is responsible for synchronizing the cache with the associated Hashmap and making it available to the caller at the supplied result pointers. Since iterated_cache_get() may need to allocate memory, it may fail, so callers must check the return value. On success, pointer arrays containing pointers to the associated Hashmap's keys and values, in as-iterated order, are returned in res_keys and res_values, respectively. Either may be supplied as NULL to inhibit caching of the keys or values, respectively. Note that if the cached Hashmap hasn't changed since the previous call to iterated_cache_get(), and it's not a call activating caching of the values or keys, the cost is effectively zero as the resulting pointers will simply refer to the previously returned arrays as-is. A cleanup function has also been added, iterated_cache_free(). This only frees the IteratedCache container and related arrays. The associated Hashmap, its keys, and values are not affected. Also note that the associated Hashmap does not automatically free its associated IteratedCache when freed. One could, in theory, safely access the arrays returned by a successful iterated_cache_get() call after its associated Hashmap has been freed, including the referenced values and keys. Provided the iterated_cache_get() was performed prior to the hashmap free, and that the type of hashmap free performed didn't free keys and/or values as well.
* basic: track dirty state in HashmapBaseVito Caputo2018-05-30
| | | | | | | This only adds marking the HashmapBase as dirty, no clearing of the dirty state happens yet. No functional changes.
* strv: drop strv_join_quoted() (#8057)Yu Watanabe2018-05-30
| | | | | | | | | 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.
* missing_syscall: when adding syscall replacements, use different names (#8229)Zbigniew Jędrzejewski-Szmek2018-05-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In meson.build we check that functions are available using: meson.get_compiler('c').has_function('foo') which checks the following: - if __stub_foo or __stub___foo are defined, return false - if foo is declared (a pointer to the function can be taken), return true - otherwise check for __builtin_memfd_create _stub is documented by glibc as It defines a symbol '__stub_FUNCTION' for each function in the C library which is a stub, meaning it will fail every time called, usually setting errno to ENOSYS. So if __stub is defined, we know we don't want to use the glibc version, but this doesn't tell us if the name itself is defined or not. If it _is_ defined, and we define our replacement as an inline static function, we get an error: In file included from ../src/basic/missing.h:1358:0, from ../src/basic/util.h:47, from ../src/basic/calendarspec.h:29, from ../src/basic/calendarspec.c:34: ../src/basic/missing_syscall.h:65:19: error: static declaration of 'memfd_create' follows non-static declaration static inline int memfd_create(const char *name, unsigned int flags) { ^~~~~~~~~~~~ .../usr/include/bits/mman-shared.h:46:5: note: previous declaration of 'memfd_create' was here int memfd_create (const char *__name, unsigned int __flags) __THROW; ^~~~~~~~~~~~ To avoid this problem, call our inline functions different than glibc, and use a #define to map the official name to our replacement. Fixes #8099. v2: - use "missing_" as the prefix instead of "_" v3: - rebase and update for statx() Unfortunately "statx" is also present in "struct statx", so the define causes issues. Work around this by using a typedef. I checked that systemd compiles with current glibc (glibc-devel-2.26-24.fc27.x86_64) if HAVE_MEMFD_CREATE, HAVE_GETTID, HAVE_PIVOT_ROOT, HAVE_SETNS, HAVE_RENAMEAT2, HAVE_KCMP, HAVE_KEYCTL, HAVE_COPY_FILE_RANGE, HAVE_BPF, HAVE_STATX are forced to 0. Setting HAVE_NAME_TO_HANDLE_AT to 0 causes an issue, but it's not because of the define, but because of struct file_handle. (cherry picked from commit 5187dd2c403caf92d09f3491e41f1ceb3f10491f)
* test-user-util: skip most tests for nobody if synthentization is offZbigniew Jędrzejewski-Szmek2018-05-30
| | | | | | | | | | | | | | When synthetisation is turned off, there's just too many ways those tests can go wrong. We are not interested in verifying that the db on disk is correct, let's just skip all checks. In the first version of this patch, I recorded if we detected a mismatch during configuration and only skipped tests in that case, but actually it is possible to change the host configuration between our configuration phase and running of the tests. It's just more robust to skip always. (This is particularly true if tests are installed.) (cherry picked from commit 7559b2da10b1513849f22312d09a2381569b4f06)
* test-user-util: print function delimitersZbigniew Jędrzejewski-Szmek2018-05-30
| | | | | | | | This makes it easier to see what is going on. Crashes may happen in a nested test_{uid,gid}_to_name_one() function, and the default backtrace doesn't show the actual string being tested. (cherry picked from commit 52c6e6a8a0221530659c65090f18b16c45a9fc04)
* fs-util: add new unlinkat_deallocate() helperLennart Poettering2018-05-30
| | | | | | | | | | | This new helper not only removes a file from a directory but also ensures its space on disk is deallocated, by either punching a hole over the full file or truncating the file afterwards if the file's link counter is 0. This is useful in "vacuuming" algorithms to ensure that client's can't keep the disk space the vacuuming is supposed to recover pinned simply by keeping an fd open to it. (cherry picked from commit 43767d9d5e0ce8923828aebf9154da7af83916f7)
* hash-func: add generic hash_ops implementation for hashing pathsLennart Poettering2018-05-30
| | | | | | | | | | | | | | | | | This is similar to string_hash_ops but operates one file system paths specifically. It will ensure that "/foo//bar" and "///foo/bar" are considered to be the same path for hashmap purposes. This makes use of the existing path_compare() API, and adds a matching hashing function for it. Note that relative and absolute paths will hash to different values, however whether the path is suffixed with a slash or not is not detected. This matches the existing path_compare() behaviour, and follows the logic that on Linux there can't be two different objects at path /foo/bar and /foo/bar/ either. (cherry picked from commit 46e16b347f83d809ed3d34f26286f580dfd086ce)
* hash-funcs: remove redundant definition of devt_hash_opsLennart Poettering2018-05-30
| | | | | | | We should assign a value only in the .c file, not in both the .c and .h file. (cherry picked from commit 9bac7d423f1d39737e2b7bc35c484ed0d79de73d)
* journal: move code that checks for network fs to stat-util.[ch]Lennart Poettering2018-05-30
| | | | | | | We have similar code in stat-util.[ch] and managing this at a central place almost definitely is the better choice. (cherry picked from commit 77f9fa3b8ea46c27e5a5e9270f71bf1b4000c3e0)
* sd-bus: cleanup ssh sessions (Closes: #8076)Shawn Landden2018-05-30
| | | | | | | | | | | | | | | | | | | | we still invoke ssh unnecessarily when there in incompatible or erreneous input The fallow-up to finish that would make the code a bit more verbose, as it would require repeating this bit: ``` r = bus_connect_transport(arg_transport, arg_host, false, &bus); if (r < 0) { log_error_errno(r, "Failed to create bus connection: %m"); goto finish; } sd_bus_set_allow_interactive_authorization(bus, arg_ask_password); ``` in every verb, after parsing. v2: add waitpid() to avoid a zombie process, switch to SIGTERM from SIGKILL v3: refactor, wait in bus_start_address() (cherry picked from commit 392cf1d05dbfa1395f6d99102e5ea41debb58fec)
* sd-bus: avoid potential memory leaksYu Watanabe2018-05-30
| | | | (cherry picked from commit b4ca3f45dc5742ad76e8feebd363c490f92b804f)
* process-util: use raw_getpid() in getpid_cache() internally (#8115)Lennart Poettering2018-05-30
| | | | | | | | | | We have the raw_getpid() definition in place anyway, and it's certainly beneficial to expose the same semantics on pre glibc 2.24 and after it too, hence always bypass glibc for this, and always cache things on our side. Fixes: #8113 (cherry picked from commit 996def17f99bb3f41f82032860dfcb98ff19c3ae)
* test: add a simple smoke test for string_hashsum()Zbigniew Jędrzejewski-Szmek2018-05-30
| | | | | | This is enough to show memory leakages pointed out by Stef Bon <stefbon@gmail.com>. (cherry picked from commit bd181f27d4d0c16c500c9f49394213d1fbad1f09)
* kernel 3.10 compat: RTAX_QUICKACK not added until 3.11.0 (#8094)MilhouseVH2018-05-30
| | | | (cherry picked from commit ec79af69a1d159a43deb68c9ec1c31fe89743b6f)
* socket-util: fix getpeergroups() assert(fd) (#8080)Vito Caputo2018-05-30
| | | | | | | | Don't assert on zero-value fds. Fixes #8075. (cherry picked from commit 75f40779607ea79f20441c7fb46744d04ee2c7ae)
* journalctl: add highlighting for matched substringZbigniew Jędrzejewski-Szmek2018-05-30
| | | | | | | | | Red is used for highligting, the same as grep does. Except when the line is highlighted red already, because it has high priority, in which case plain ansi highlight is used for the matched substring. Coloring is implemented for short and cat outputs, and not for other types. I guess we could also add it for verbose output in the future.
* journalctl: make matching optionally case sensitiveZbigniew Jędrzejewski-Szmek2018-05-30
| | | | | | | | | | | | | Case sensitive or case insensitive matching can be requested using --case-sensitive[=yes|no]. Unless specified, matching is case sensitive if the pattern contains any uppercase letters, and case insensitive otherwise. This matches what forward-search does in emacs, and recently also --ignore-case in less. This works surprisingly well, because usually when one is wants to do case-sensitive matching, the pattern is usually camel-cased. In the less frequent case when case-sensitive matching is required with an all-lowercase pattern, --case-sensitive can be used to override the automatic logic.