Compare commits

..

7 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek 4b6bc95c01
Merge pull request #17009 from poettering/rootprefix-noslash
remove duplicate slashes in systemd-path output if rootprefixdir is "/"
2020-09-12 10:07:40 +02:00
Lennart Poettering ae0b700a85 hashmap: make sure to initialize shared hash key atomically
if we allocate a bunch of hash tables all at the same time, with none
earlier than the other, there's a good chance we'll initialize the
shared hash key multiple times, so that some threads will see a
different shared hash key than others.

Let's fix that, and make sure really everyone sees the same hash key.

Fixes: #17007
2020-09-12 09:33:33 +02:00
Lennart Poettering 35b4e3c1bc socket: downgrade log warnings about inability to set socket buffer sizes
In containers we might lack the privs to up the socket buffers. Let's
not complain so loudly about that. Let's hence downgrade this to debug
logging if it's a permission problem.

(This wasn't an issue before b92f350789
because back then the failures wouldn't be detected at all.)
2020-09-12 08:14:54 +02:00
Lennart Poettering e742ec6abc test-acl-util: skip test if /tmp doesn't do ACLs
Fixes: #17013
2020-09-12 08:12:36 +02:00
Lennart Poettering 95f7ab2fe6 mkosi: include libfido2 in fedora mkosi image
We want to build this image with as many deps turned on as we can make
happen, hence include libfido2 in the image.
2020-09-12 08:10:08 +02:00
Lennart Poettering 6e65df89c3 pkg-config: prefix is not really configurable, don't pretend it was
We generally don't support prefix being != /usr, and this is hardcoded
all over the place. In the systemd.pc file it wasn't so far. Let's
adjust this to match the rest of the codebase.
2020-09-11 13:09:06 +02:00
Lennart Poettering b612c26ceb sd-path: use ROOTPREFIX without suffixed slash
We already have rootprefix_noslash as meson variable, export it so that
we can also use it in C code.

Fixes: #16773
2020-09-11 13:08:30 +02:00
7 changed files with 37 additions and 30 deletions

View File

@ -38,6 +38,7 @@ BuildPackages=
libcap-devel libcap-devel
libcurl-devel libcurl-devel
libfdisk-devel libfdisk-devel
libfido2-devel
libgcrypt-devel libgcrypt-devel
libidn2-devel libidn2-devel
libmicrohttpd-devel libmicrohttpd-devel

View File

@ -230,6 +230,7 @@ conf.set_quoted('SYSTEMCTL_BINARY_PATH', join_paths(rootbin
conf.set_quoted('SYSTEMD_TTY_ASK_PASSWORD_AGENT_BINARY_PATH', join_paths(rootbindir, 'systemd-tty-ask-password-agent')) conf.set_quoted('SYSTEMD_TTY_ASK_PASSWORD_AGENT_BINARY_PATH', join_paths(rootbindir, 'systemd-tty-ask-password-agent'))
conf.set_quoted('SYSTEMD_STDIO_BRIDGE_BINARY_PATH', join_paths(bindir, 'systemd-stdio-bridge')) conf.set_quoted('SYSTEMD_STDIO_BRIDGE_BINARY_PATH', join_paths(bindir, 'systemd-stdio-bridge'))
conf.set_quoted('ROOTPREFIX', rootprefixdir) conf.set_quoted('ROOTPREFIX', rootprefixdir)
conf.set_quoted('ROOTPREFIX_NOSLASH', rootprefixdir_noslash)
conf.set_quoted('RANDOM_SEED_DIR', randomseeddir) conf.set_quoted('RANDOM_SEED_DIR', randomseeddir)
conf.set_quoted('RANDOM_SEED', join_paths(randomseeddir, 'random-seed')) conf.set_quoted('RANDOM_SEED', join_paths(randomseeddir, 'random-seed'))
conf.set_quoted('SYSTEMD_CRYPTSETUP_PATH', join_paths(rootlibexecdir, 'systemd-cryptsetup')) conf.set_quoted('SYSTEMD_CRYPTSETUP_PATH', join_paths(rootlibexecdir, 'systemd-cryptsetup'))

View File

@ -1,6 +1,7 @@
/* SPDX-License-Identifier: LGPL-2.1+ */ /* SPDX-License-Identifier: LGPL-2.1+ */
#include <errno.h> #include <errno.h>
#include <pthread.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
@ -19,7 +20,6 @@
#include "strv.h" #include "strv.h"
#if ENABLE_DEBUG_HASHMAP #if ENABLE_DEBUG_HASHMAP
#include <pthread.h>
#include "list.h" #include "list.h"
#endif #endif
@ -189,7 +189,6 @@ assert_cc(DIRECT_BUCKETS(struct set_entry) < (1 << 3));
* a handful of directly stored entries in a hashmap. When a hashmap * a handful of directly stored entries in a hashmap. When a hashmap
* outgrows direct storage, it gets its own key for indirect storage. */ * outgrows direct storage, it gets its own key for indirect storage. */
static uint8_t shared_hash_key[HASH_KEY_SIZE]; static uint8_t shared_hash_key[HASH_KEY_SIZE];
static bool shared_hash_key_initialized;
/* Fields that all hashmap/set types must have */ /* Fields that all hashmap/set types must have */
struct HashmapBase { struct HashmapBase {
@ -764,6 +763,10 @@ static void reset_direct_storage(HashmapBase *h) {
memset(p, DIB_RAW_INIT, sizeof(dib_raw_t) * hi->n_direct_buckets); memset(p, DIB_RAW_INIT, sizeof(dib_raw_t) * hi->n_direct_buckets);
} }
static void shared_hash_key_initialize(void) {
random_bytes(shared_hash_key, sizeof(shared_hash_key));
}
static struct HashmapBase* hashmap_base_new(const struct hash_ops *hash_ops, enum HashmapType type HASHMAP_DEBUG_PARAMS) { static struct HashmapBase* hashmap_base_new(const struct hash_ops *hash_ops, enum HashmapType type HASHMAP_DEBUG_PARAMS) {
HashmapBase *h; HashmapBase *h;
const struct hashmap_type_info *hi = &hashmap_type_info[type]; const struct hashmap_type_info *hi = &hashmap_type_info[type];
@ -786,10 +789,8 @@ static struct HashmapBase* hashmap_base_new(const struct hash_ops *hash_ops, enu
reset_direct_storage(h); reset_direct_storage(h);
if (!shared_hash_key_initialized) { static pthread_once_t once = PTHREAD_ONCE_INIT;
random_bytes(shared_hash_key, sizeof(shared_hash_key)); assert_se(pthread_once(&once, shared_hash_key_initialize) == 0);
shared_hash_key_initialized= true;
}
#if ENABLE_DEBUG_HASHMAP #if ENABLE_DEBUG_HASHMAP
h->debug.func = func; h->debug.func = func;

View File

@ -1061,13 +1061,15 @@ static void socket_apply_socket_options(Socket *s, SocketPort *p, int fd) {
if (s->receive_buffer > 0) { if (s->receive_buffer > 0) {
r = fd_set_rcvbuf(fd, s->receive_buffer, false); r = fd_set_rcvbuf(fd, s->receive_buffer, false);
if (r < 0) if (r < 0)
log_unit_warning_errno(UNIT(s), r, "SO_RCVBUF/SO_RCVBUFFORCE failed: %m"); log_unit_full_errno(UNIT(s), ERRNO_IS_PRIVILEGE(r) ? LOG_DEBUG : LOG_WARNING, r,
"SO_RCVBUF/SO_RCVBUFFORCE failed: %m");
} }
if (s->send_buffer > 0) { if (s->send_buffer > 0) {
r = fd_set_sndbuf(fd, s->send_buffer, false); r = fd_set_sndbuf(fd, s->send_buffer, false);
if (r < 0) if (r < 0)
log_unit_warning_errno(UNIT(s), r, "SO_SNDBUF/SO_SNDBUFFORCE failed: %m"); log_unit_full_errno(UNIT(s), ERRNO_IS_PRIVILEGE(r) ? LOG_DEBUG : LOG_WARNING, r,
"SO_SNDBUF/SO_SNDBUFFORCE failed: %m");
} }
if (s->mark >= 0) { if (s->mark >= 0) {

View File

@ -11,7 +11,7 @@
# considered deprecated (though there is no plan to remove them). New names # considered deprecated (though there is no plan to remove them). New names
# shall have underscores. # shall have underscores.
prefix=@prefix@ prefix=/usr
root_prefix=@rootprefix_noslash@ root_prefix=@rootprefix_noslash@
rootprefix=${root_prefix} rootprefix=${root_prefix}
sysconf_dir=@sysconfdir@ sysconf_dir=@sysconfdir@
@ -26,10 +26,10 @@ systemdsystemunitdir=${systemd_system_unit_dir}
systemd_system_preset_dir=${rootprefix}/lib/systemd/system-preset systemd_system_preset_dir=${rootprefix}/lib/systemd/system-preset
systemdsystempresetdir=${systemd_system_preset_dir} systemdsystempresetdir=${systemd_system_preset_dir}
systemd_user_unit_dir=${prefix}/lib/systemd/user systemd_user_unit_dir=/usr/lib/systemd/user
systemduserunitdir=${systemd_user_unit_dir} systemduserunitdir=${systemd_user_unit_dir}
systemd_user_preset_dir=${prefix}/lib/systemd/user-preset systemd_user_preset_dir=/usr/lib/systemd/user-preset
systemduserpresetdir=${systemd_user_preset_dir} systemduserpresetdir=${systemd_user_preset_dir}
systemd_system_conf_dir=${sysconfdir}/systemd/system systemd_system_conf_dir=${sysconfdir}/systemd/system
@ -47,7 +47,7 @@ systemduserunitpath=${systemd_user_unit_path}
systemd_system_generator_dir=${root_prefix}/lib/systemd/system-generators systemd_system_generator_dir=${root_prefix}/lib/systemd/system-generators
systemdsystemgeneratordir=${systemd_system_generator_dir} systemdsystemgeneratordir=${systemd_system_generator_dir}
systemd_user_generator_dir=${prefix}/lib/systemd/user-generators systemd_user_generator_dir=/usr/lib/systemd/user-generators
systemdusergeneratordir=${systemd_user_generator_dir} systemdusergeneratordir=${systemd_user_generator_dir}
systemd_system_generator_path=/run/systemd/system-generators:/etc/systemd/system-generators:/usr/local/lib/systemd/system-generators:${systemd_system_generator_dir} systemd_system_generator_path=/run/systemd/system-generators:/etc/systemd/system-generators:/usr/local/lib/systemd/system-generators:${systemd_system_generator_dir}
@ -62,7 +62,7 @@ systemdsleepdir=${systemd_sleep_dir}
systemd_shutdown_dir=${root_prefix}/lib/systemd/system-shutdown systemd_shutdown_dir=${root_prefix}/lib/systemd/system-shutdown
systemdshutdowndir=${systemd_shutdown_dir} systemdshutdowndir=${systemd_shutdown_dir}
tmpfiles_dir=${prefix}/lib/tmpfiles.d tmpfiles_dir=/usr/lib/tmpfiles.d
tmpfilesdir=${tmpfiles_dir} tmpfilesdir=${tmpfiles_dir}
sysusers_dir=${rootprefix}/lib/sysusers.d sysusers_dir=${rootprefix}/lib/sysusers.d
@ -77,7 +77,7 @@ binfmtdir=${binfmt_dir}
modules_load_dir=${rootprefix}/lib/modules-load.d modules_load_dir=${rootprefix}/lib/modules-load.d
modulesloaddir=${modules_load_dir} modulesloaddir=${modules_load_dir}
catalog_dir=${prefix}/lib/systemd/catalog catalog_dir=/usr/lib/systemd/catalog
catalogdir=${catalog_dir} catalogdir=${catalog_dir}
system_uid_max=@systemuidmax@ system_uid_max=@systemuidmax@

View File

@ -321,7 +321,7 @@ static int get_path(uint64_t type, char **buffer, const char **ret) {
return from_user_dir("XDG_DESKTOP_DIR", buffer, ret); return from_user_dir("XDG_DESKTOP_DIR", buffer, ret);
case SD_PATH_SYSTEMD_UTIL: case SD_PATH_SYSTEMD_UTIL:
*ret = ROOTPREFIX "/lib/systemd"; *ret = ROOTPREFIX_NOSLASH "/lib/systemd";
return 0; return 0;
case SD_PATH_SYSTEMD_SYSTEM_UNIT: case SD_PATH_SYSTEMD_SYSTEM_UNIT:
@ -329,7 +329,7 @@ static int get_path(uint64_t type, char **buffer, const char **ret) {
return 0; return 0;
case SD_PATH_SYSTEMD_SYSTEM_PRESET: case SD_PATH_SYSTEMD_SYSTEM_PRESET:
*ret = ROOTPREFIX "/lib/systemd/system-preset"; *ret = ROOTPREFIX_NOSLASH "/lib/systemd/system-preset";
return 0; return 0;
case SD_PATH_SYSTEMD_USER_UNIT: case SD_PATH_SYSTEMD_USER_UNIT:
@ -337,7 +337,7 @@ static int get_path(uint64_t type, char **buffer, const char **ret) {
return 0; return 0;
case SD_PATH_SYSTEMD_USER_PRESET: case SD_PATH_SYSTEMD_USER_PRESET:
*ret = ROOTPREFIX "/lib/systemd/user-preset"; *ret = ROOTPREFIX_NOSLASH "/lib/systemd/user-preset";
return 0; return 0;
case SD_PATH_SYSTEMD_SYSTEM_CONF: case SD_PATH_SYSTEMD_SYSTEM_CONF:
@ -357,33 +357,31 @@ static int get_path(uint64_t type, char **buffer, const char **ret) {
return 0; return 0;
case SD_PATH_SYSTEMD_SLEEP: case SD_PATH_SYSTEMD_SLEEP:
*ret = ROOTPREFIX "/lib/systemd/system-sleep"; *ret = ROOTPREFIX_NOSLASH "/lib/systemd/system-sleep";
return 0; return 0;
case SD_PATH_SYSTEMD_SHUTDOWN: case SD_PATH_SYSTEMD_SHUTDOWN:
*ret = ROOTPREFIX "/lib/systemd/system-shutdown"; *ret = ROOTPREFIX_NOSLASH "/lib/systemd/system-shutdown";
return 0; return 0;
/* FIXME: systemd.pc uses ${prefix}, but CONF_PATHS_NULSTR doesn't.
* Should ${prefix} use in systemd.pc be removed? */
case SD_PATH_TMPFILES: case SD_PATH_TMPFILES:
*ret = "/usr/lib/tmpfiles.d"; *ret = "/usr/lib/tmpfiles.d";
return 0; return 0;
case SD_PATH_SYSUSERS: case SD_PATH_SYSUSERS:
*ret = ROOTPREFIX "/lib/sysusers.d"; *ret = ROOTPREFIX_NOSLASH "/lib/sysusers.d";
return 0; return 0;
case SD_PATH_SYSCTL: case SD_PATH_SYSCTL:
*ret = ROOTPREFIX "/lib/sysctl.d"; *ret = ROOTPREFIX_NOSLASH "/lib/sysctl.d";
return 0; return 0;
case SD_PATH_BINFMT: case SD_PATH_BINFMT:
*ret = ROOTPREFIX "/lib/binfmt.d"; *ret = ROOTPREFIX_NOSLASH "/lib/binfmt.d";
return 0; return 0;
case SD_PATH_MODULES_LOAD: case SD_PATH_MODULES_LOAD:
*ret = ROOTPREFIX "/lib/modules-load.d"; *ret = ROOTPREFIX_NOSLASH "/lib/modules-load.d";
return 0; return 0;
case SD_PATH_CATALOG: case SD_PATH_CATALOG:

View File

@ -6,13 +6,15 @@
#include <unistd.h> #include <unistd.h>
#include "acl-util.h" #include "acl-util.h"
#include "errno-util.h"
#include "fd-util.h" #include "fd-util.h"
#include "format-util.h" #include "format-util.h"
#include "string-util.h" #include "string-util.h"
#include "tests.h"
#include "tmpfile-util.h" #include "tmpfile-util.h"
#include "user-util.h" #include "user-util.h"
static void test_add_acls_for_user(void) { static int test_add_acls_for_user(void) {
char fn[] = "/tmp/test-empty.XXXXXX"; char fn[] = "/tmp/test-empty.XXXXXX";
_cleanup_close_ int fd = -1; _cleanup_close_ int fd = -1;
char *cmd; char *cmd;
@ -42,6 +44,9 @@ static void test_add_acls_for_user(void) {
uid = getuid(); uid = getuid();
r = fd_add_uid_acl_permission(fd, uid, ACL_READ); r = fd_add_uid_acl_permission(fd, uid, ACL_READ);
if (ERRNO_IS_NOT_SUPPORTED(r))
return log_tests_skipped("no ACL support on /tmp");
log_info_errno(r, "fd_add_uid_acl_permission(%i, "UID_FMT", ACL_READ): %m", fd, uid); log_info_errno(r, "fd_add_uid_acl_permission(%i, "UID_FMT", ACL_READ): %m", fd, uid);
assert_se(r >= 0); assert_se(r >= 0);
@ -62,11 +67,10 @@ static void test_add_acls_for_user(void) {
cmd = strjoina("getfacl -p ", fn); cmd = strjoina("getfacl -p ", fn);
assert_se(system(cmd) == 0); assert_se(system(cmd) == 0);
unlink(fn); (void) unlink(fn);
return 0;
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
test_add_acls_for_user(); return test_add_acls_for_user();
return 0;
} }