1
0
mirror of https://github.com/systemd/systemd synced 2025-09-20 20:34:45 +02:00

Compare commits

..

No commits in common. "cee33a7ab33eb423c83dfb65e56788b6a06bffc9" and "9e9dd3e329a69a3aad5698552697b3257fdc3845" have entirely different histories.

8 changed files with 83 additions and 160 deletions

6
TODO
View File

@ -30,12 +30,6 @@ Before v244:
Features:
* localed: if UTC is selected but timezone file for it doesn't exist, delete
/etc/localtime instead of creating a symlink
* socket units: allow creating a udev monitor socket with ListenDevices= or so,
with matches, then actviate app thorugh that passing socket oveer
* coredump: maybe when coredumping read a new xattr from /proc/$PID/exe that
may be used to mark a whole binary as non-coredumpable. Would fix:
https://bugs.freedesktop.org/show_bug.cgi?id=69447

View File

@ -8,7 +8,6 @@ project('systemd', 'c',
'prefix=/usr',
'sysconfdir=/etc',
'localstatedir=/var',
'warning_level=2',
],
meson_version : '>= 0.46',
)
@ -303,8 +302,7 @@ install_tests = get_option('install-tests')
if add_languages('cpp', required : fuzzer_build)
# Used only for tests
cxx = meson.get_compiler('cpp')
cxx_cmd = ' '.join(cxx.cmd_array())
cxx_cmd = ' '.join(meson.get_compiler('cpp').cmd_array())
else
cxx_cmd = ''
endif
@ -324,25 +322,8 @@ elif want_fuzzbuzz
fuzzing_engine = meson.get_compiler('cpp').find_library(get_option('fuzzbuzz-engine'), dirs: get_option('fuzzbuzz-engine-dir'))
endif
# Those generate many false positives, and we do not want to change the code to
# avoid them.
basic_disabled_warnings = [
'-Wno-unused-parameter',
'-Wno-missing-field-initializers',
'-Wno-unused-result',
'-Wno-format-signedness',
]
if get_option('b_ndebug') == 'true'
# With asserts disabled with get a bunch of warnings about variables which
# are used only in the asserts. This is not useful at all, so let's just silence
# those warnings.
basic_disabled_warnings += [
'-Wno-unused-variable',
'-Wno-unused-but-set-variable',
]
endif
possible_cc_flags = [
'-Wextra',
'-Werror=undef',
'-Wlogical-op',
'-Wmissing-include-dirs',
@ -372,6 +353,10 @@ possible_cc_flags = [
'-Wnested-externs',
# negative arguments are correctly detected starting with meson 0.46.
'-Wno-unused-parameter',
'-Wno-missing-field-initializers',
'-Wno-unused-result',
'-Wno-format-signedness',
'-Wno-error=#warnings', # clang
'-Wno-string-plus-int', # clang
@ -416,7 +401,16 @@ if get_option('buildtype') != 'debug'
possible_link_flags += '-Wl,--gc-sections'
endif
add_project_arguments(cc.get_supported_arguments(basic_disabled_warnings), language : 'c')
if get_option('b_ndebug') == 'true'
# With asserts disabled with get a bunch of warnings about variables which
# are used only in the asserts. This is not useful at all, so let's just silence
# those warnings.
possible_cc_flags += [
'-Wno-unused-variable',
'-Wno-unused-but-set-variable',
]
endif
add_project_arguments(cc.get_supported_arguments(possible_cc_flags), language : 'c')
add_project_link_arguments(cc.get_supported_link_arguments(possible_link_flags), language : 'c')
@ -433,10 +427,6 @@ if cc.compiles('''
add_project_arguments('-Werror=shadow', language : 'c')
endif
if cxx_cmd != ''
add_project_arguments(cxx.get_supported_arguments(basic_disabled_warnings), language : 'cpp')
endif
cpp = ' '.join(cc.cmd_array()) + ' -E'
has_wstringop_truncation = cc.has_argument('-Wstringop-truncation')

View File

@ -1239,27 +1239,23 @@ error:
}
static void session_restore_vt(Session *s) {
int r;
int r, vt, old_fd;
r = vt_restore(s->vtfd);
if (r == -EIO) {
int vt, old_fd;
/* We need to get a fresh handle to the virtual terminal,
* since the old file-descriptor is potentially in a hung-up
* state after the controlling process exited; we do a
* little dance to avoid having the terminal be available
* for reuse before we've cleaned it up.
*/
old_fd = TAKE_FD(s->vtfd);
/* It might happen if the controlling process exited before or while we were
* restoring the VT as it would leave the old file-descriptor in a hung-up
* state. In this case let's retry with a fresh handle to the virtual terminal. */
vt = session_open_vt(s);
safe_close(old_fd);
/* We do a little dance to avoid having the terminal be available
* for reuse before we've cleaned it up. */
old_fd = TAKE_FD(s->vtfd);
vt = session_open_vt(s);
safe_close(old_fd);
if (vt >= 0)
r = vt_restore(vt);
}
if (vt < 0)
return;
r = vt_restore(vt);
if (r < 0)
log_warning_errno(r, "Failed to restore VT, ignoring: %m");

View File

@ -265,20 +265,20 @@ shared_sources += shared_generated_gperf_headers
libshared_name = 'systemd-shared-@0@'.format(meson.project_version())
libshared_deps = [threads,
libacl,
libblkid,
librt,
libcap,
libacl,
libcryptsetup,
libgcrypt,
libidn,
libiptc,
libkmod,
liblz4,
libmount,
librt,
libseccomp,
libselinux,
libxz]
libidn,
libxz,
liblz4,
libblkid]
libshared_sym_path = '@0@/libshared.sym'.format(meson.current_source_dir())

View File

@ -11,11 +11,12 @@ test_hashmap_ordered_c = custom_target(
test_include_dir = include_directories('.')
path = run_command('sh', ['-c', 'echo "$PATH"']).stdout().strip()
path = run_command('sh', ['-c', 'echo "$PATH"']).stdout()
test_env = environment()
test_env.set('SYSTEMD_KBD_MODEL_MAP', kbd_model_map)
test_env.set('SYSTEMD_LANGUAGE_FALLBACK_MAP', language_fallback_map)
test_env.set('PATH', '@0@:@1@'.format(meson.build_root(), path))
test_env.set('PATH', path)
test_env.prepend('PATH', meson.build_root())
############################################################

View File

@ -24,61 +24,43 @@
#include "user-util.h"
#include "util.h"
static void test_unit_name_is_valid_one(const char *name, UnitNameFlags flags, bool expected) {
log_info("%s ( %s%s%s ): %s",
name,
(flags & UNIT_NAME_PLAIN) ? "plain" : "",
(flags & UNIT_NAME_INSTANCE) ? " instance" : "",
(flags & UNIT_NAME_TEMPLATE) ? " template" : "",
yes_no(expected));
assert_se(unit_name_is_valid(name, flags) == expected);
}
static void test_unit_name_is_valid(void) {
log_info("/* %s */", __func__);
assert_se( unit_name_is_valid("foo.service", UNIT_NAME_ANY));
assert_se( unit_name_is_valid("foo.service", UNIT_NAME_PLAIN));
assert_se(!unit_name_is_valid("foo.service", UNIT_NAME_INSTANCE));
assert_se(!unit_name_is_valid("foo.service", UNIT_NAME_TEMPLATE));
assert_se(!unit_name_is_valid("foo.service", UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE));
test_unit_name_is_valid_one("foo.service", UNIT_NAME_ANY, true);
test_unit_name_is_valid_one("foo.service", UNIT_NAME_PLAIN, true);
test_unit_name_is_valid_one("foo.service", UNIT_NAME_INSTANCE, false);
test_unit_name_is_valid_one("foo.service", UNIT_NAME_TEMPLATE, false);
test_unit_name_is_valid_one("foo.service", UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE, false);
assert_se( unit_name_is_valid("foo@bar.service", UNIT_NAME_ANY));
assert_se(!unit_name_is_valid("foo@bar.service", UNIT_NAME_PLAIN));
assert_se( unit_name_is_valid("foo@bar.service", UNIT_NAME_INSTANCE));
assert_se(!unit_name_is_valid("foo@bar.service", UNIT_NAME_TEMPLATE));
assert_se( unit_name_is_valid("foo@bar.service", UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE));
test_unit_name_is_valid_one("foo@bar.service", UNIT_NAME_ANY, true);
test_unit_name_is_valid_one("foo@bar.service", UNIT_NAME_PLAIN, false);
test_unit_name_is_valid_one("foo@bar.service", UNIT_NAME_INSTANCE, true);
test_unit_name_is_valid_one("foo@bar.service", UNIT_NAME_TEMPLATE, false);
test_unit_name_is_valid_one("foo@bar.service", UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE, true);
assert_se( unit_name_is_valid("foo@bar@bar.service", UNIT_NAME_ANY));
assert_se(!unit_name_is_valid("foo@bar@bar.service", UNIT_NAME_PLAIN));
assert_se( unit_name_is_valid("foo@bar@bar.service", UNIT_NAME_INSTANCE));
assert_se(!unit_name_is_valid("foo@bar@bar.service", UNIT_NAME_TEMPLATE));
assert_se( unit_name_is_valid("foo@bar@bar.service", UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE));
test_unit_name_is_valid_one("foo@bar@bar.service", UNIT_NAME_ANY, true);
test_unit_name_is_valid_one("foo@bar@bar.service", UNIT_NAME_PLAIN, false);
test_unit_name_is_valid_one("foo@bar@bar.service", UNIT_NAME_INSTANCE, true);
test_unit_name_is_valid_one("foo@bar@bar.service", UNIT_NAME_TEMPLATE, false);
test_unit_name_is_valid_one("foo@bar@bar.service", UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE, true);
assert_se( unit_name_is_valid("foo@.service", UNIT_NAME_ANY));
assert_se(!unit_name_is_valid("foo@.service", UNIT_NAME_PLAIN));
assert_se(!unit_name_is_valid("foo@.service", UNIT_NAME_INSTANCE));
assert_se( unit_name_is_valid("foo@.service", UNIT_NAME_TEMPLATE));
assert_se( unit_name_is_valid("foo@.service", UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE));
assert_se( unit_name_is_valid(".test.service", UNIT_NAME_PLAIN));
assert_se( unit_name_is_valid(".test@.service", UNIT_NAME_TEMPLATE));
assert_se( unit_name_is_valid("_strange::::.service", UNIT_NAME_ANY));
test_unit_name_is_valid_one("foo@.service", UNIT_NAME_ANY, true);
test_unit_name_is_valid_one("foo@.service", UNIT_NAME_PLAIN, false);
test_unit_name_is_valid_one("foo@.service", UNIT_NAME_INSTANCE, false);
test_unit_name_is_valid_one("foo@.service", UNIT_NAME_TEMPLATE, true);
test_unit_name_is_valid_one("foo@.service", UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE, true);
test_unit_name_is_valid_one(".test.service", UNIT_NAME_PLAIN, true);
test_unit_name_is_valid_one(".test@.service", UNIT_NAME_TEMPLATE, true);
test_unit_name_is_valid_one("_strange::::.service", UNIT_NAME_ANY, true);
assert_se(!unit_name_is_valid(".service", UNIT_NAME_ANY));
assert_se(!unit_name_is_valid("", UNIT_NAME_ANY));
assert_se(!unit_name_is_valid("foo.waldo", UNIT_NAME_ANY));
assert_se(!unit_name_is_valid("@.service", UNIT_NAME_ANY));
assert_se(!unit_name_is_valid("@piep.service", UNIT_NAME_ANY));
test_unit_name_is_valid_one(".service", UNIT_NAME_ANY, false);
test_unit_name_is_valid_one("", UNIT_NAME_ANY, false);
test_unit_name_is_valid_one("foo.waldo", UNIT_NAME_ANY, false);
test_unit_name_is_valid_one("@.service", UNIT_NAME_ANY, false);
test_unit_name_is_valid_one("@piep.service", UNIT_NAME_ANY, false);
test_unit_name_is_valid_one("user@1000.slice", UNIT_NAME_ANY, true);
test_unit_name_is_valid_one("user@1000.slice", UNIT_NAME_INSTANCE, true);
test_unit_name_is_valid_one("user@1000.slice", UNIT_NAME_TEMPLATE, false);
test_unit_name_is_valid_one("foo@%i.service", UNIT_NAME_ANY, false);
test_unit_name_is_valid_one("foo@%i.service", UNIT_NAME_INSTANCE, false);
test_unit_name_is_valid_one("foo@%%i.service", UNIT_NAME_INSTANCE, false);
test_unit_name_is_valid_one("foo@%%i%f.service", UNIT_NAME_INSTANCE, false);
test_unit_name_is_valid_one("foo@%F.service", UNIT_NAME_INSTANCE, false);
assert_se( unit_name_is_valid("user@1000.slice", UNIT_NAME_ANY));
assert_se( unit_name_is_valid("user@1000.slice", UNIT_NAME_INSTANCE));
assert_se(!unit_name_is_valid("user@1000.slice", UNIT_NAME_TEMPLATE));
}
static void test_unit_name_replace_instance_one(const char *pattern, const char *repl, const char *expected, int ret) {
@ -89,8 +71,7 @@ static void test_unit_name_replace_instance_one(const char *pattern, const char
}
static void test_unit_name_replace_instance(void) {
log_info("/* %s */", __func__);
puts("-------------------------------------------------");
test_unit_name_replace_instance_one("foo@.service", "waldo", "foo@waldo.service", 0);
test_unit_name_replace_instance_one("foo@xyz.service", "waldo", "foo@waldo.service", 0);
test_unit_name_replace_instance_one("xyz", "waldo", NULL, -EINVAL);
@ -117,8 +98,7 @@ static void test_unit_name_from_path_one(const char *path, const char *suffix, c
}
static void test_unit_name_from_path(void) {
log_info("/* %s */", __func__);
puts("-------------------------------------------------");
test_unit_name_from_path_one("/waldo", ".mount", "waldo.mount", 0);
test_unit_name_from_path_one("/waldo/quuix", ".mount", "waldo-quuix.mount", 0);
test_unit_name_from_path_one("/waldo/quuix/", ".mount", "waldo-quuix.mount", 0);
@ -146,7 +126,7 @@ static void test_unit_name_from_path_instance_one(const char *pattern, const cha
}
static void test_unit_name_from_path_instance(void) {
log_info("/* %s */", __func__);
puts("-------------------------------------------------");
test_unit_name_from_path_instance_one("waldo", "/waldo", ".mount", "waldo@waldo.mount", 0);
test_unit_name_from_path_instance_one("waldo", "/waldo////quuix////", ".mount", "waldo@waldo-quuix.mount", 0);
@ -166,8 +146,6 @@ static void test_unit_name_to_path_one(const char *unit, const char *path, int r
}
static void test_unit_name_to_path(void) {
log_info("/* %s */", __func__);
test_unit_name_to_path_one("home.mount", "/home", 0);
test_unit_name_to_path_one("home-lennart.mount", "/home/lennart", 0);
test_unit_name_to_path_one("home-lennart-.mount", NULL, -EINVAL);
@ -197,8 +175,7 @@ static void test_unit_name_mangle_one(bool allow_globs, const char *pattern, con
}
static void test_unit_name_mangle(void) {
log_info("/* %s */", __func__);
puts("-------------------------------------------------");
test_unit_name_mangle_one(false, "foo.service", "foo.service", 0);
test_unit_name_mangle_one(false, "/home", "home.mount", 1);
test_unit_name_mangle_one(false, "/dev/sda", "dev-sda.device", 1);
@ -221,8 +198,6 @@ static int test_unit_printf(void) {
Unit *u;
int r;
log_info("/* %s */", __func__);
assert_se(specifier_machine_id('m', NULL, NULL, &mid) >= 0 && mid);
assert_se(specifier_boot_id('b', NULL, NULL, &bid) >= 0 && bid);
assert_se(host = gethostname_malloc());
@ -324,8 +299,6 @@ static int test_unit_printf(void) {
}
static void test_unit_instance_is_valid(void) {
log_info("/* %s */", __func__);
assert_se(unit_instance_is_valid("fooBar"));
assert_se(unit_instance_is_valid("foo-bar"));
assert_se(unit_instance_is_valid("foo.stUff"));
@ -339,8 +312,6 @@ static void test_unit_instance_is_valid(void) {
}
static void test_unit_prefix_is_valid(void) {
log_info("/* %s */", __func__);
assert_se(unit_prefix_is_valid("fooBar"));
assert_se(unit_prefix_is_valid("foo-bar"));
assert_se(unit_prefix_is_valid("foo.stUff"));
@ -357,8 +328,6 @@ static void test_unit_prefix_is_valid(void) {
static void test_unit_name_change_suffix(void) {
char *t;
log_info("/* %s */", __func__);
assert_se(unit_name_change_suffix("foo.mount", ".service", &t) == 0);
assert_se(streq(t, "foo.service"));
free(t);
@ -371,8 +340,6 @@ static void test_unit_name_change_suffix(void) {
static void test_unit_name_build(void) {
char *t;
log_info("/* %s */", __func__);
assert_se(unit_name_build("foo", "bar", ".service", &t) == 0);
assert_se(streq(t, "foo@bar.service"));
free(t);
@ -387,8 +354,6 @@ static void test_unit_name_build(void) {
}
static void test_slice_name_is_valid(void) {
log_info("/* %s */", __func__);
assert_se( slice_name_is_valid(SPECIAL_ROOT_SLICE));
assert_se( slice_name_is_valid("foo.slice"));
assert_se( slice_name_is_valid("foo-bar.slice"));
@ -421,8 +386,6 @@ static void test_build_subslice(void) {
char *a;
char *b;
log_info("/* %s */", __func__);
assert_se(slice_build_subslice(SPECIAL_ROOT_SLICE, "foo", &a) >= 0);
assert_se(slice_build_subslice(a, "bar", &b) >= 0);
free(a);
@ -445,8 +408,6 @@ static void test_build_parent_slice_one(const char *name, const char *expect, in
}
static void test_build_parent_slice(void) {
log_info("/* %s */", __func__);
test_build_parent_slice_one(SPECIAL_ROOT_SLICE, NULL, 0);
test_build_parent_slice_one("foo.slice", SPECIAL_ROOT_SLICE, 1);
test_build_parent_slice_one("foo-bar.slice", "foo.slice", 1);
@ -469,8 +430,6 @@ static void test_unit_name_to_instance(void) {
char *instance;
int r;
log_info("/* %s */", __func__);
r = unit_name_to_instance("foo@bar.service", &instance);
assert_se(r == UNIT_NAME_INSTANCE);
assert_se(streq(instance, "bar"));
@ -502,8 +461,6 @@ static void test_unit_name_to_instance(void) {
static void test_unit_name_escape(void) {
_cleanup_free_ char *r;
log_info("/* %s */", __func__);
r = unit_name_escape("ab+-c.a/bc@foo.service");
assert_se(r);
assert_se(streq(r, "ab\\x2b\\x2dc.a-bc\\x40foo.service"));
@ -518,8 +475,6 @@ static void test_u_n_t_one(const char *name, const char *expected, int ret) {
}
static void test_unit_name_template(void) {
log_info("/* %s */", __func__);
test_u_n_t_one("foo@bar.service", "foo@.service", 0);
test_u_n_t_one("foo.mount", NULL, -EINVAL);
}
@ -532,7 +487,6 @@ static void test_unit_name_path_unescape_one(const char *name, const char *path,
}
static void test_unit_name_path_unescape(void) {
log_info("/* %s */", __func__);
test_unit_name_path_unescape_one("foo", "/foo", 0);
test_unit_name_path_unescape_one("foo-bar", "/foo/bar", 0);
@ -556,8 +510,6 @@ static void test_unit_name_to_prefix_one(const char *input, int ret, const char
}
static void test_unit_name_to_prefix(void) {
log_info("/* %s */", __func__);
test_unit_name_to_prefix_one("foobar.service", 0, "foobar");
test_unit_name_to_prefix_one("", -EINVAL, NULL);
test_unit_name_to_prefix_one("foobar", -EINVAL, NULL);
@ -578,8 +530,6 @@ static void test_unit_name_from_dbus_path_one(const char *input, int ret, const
}
static void test_unit_name_from_dbus_path(void) {
log_info("/* %s */", __func__);
test_unit_name_from_dbus_path_one("/org/freedesktop/systemd1/unit/dbus_2esocket", 0, "dbus.socket");
test_unit_name_from_dbus_path_one("/org/freedesktop/systemd1/unit/_2d_2emount", 0, "-.mount");
test_unit_name_from_dbus_path_one("/org/freedesktop/systemd1/unit/_2d_2eslice", 0, "-.slice");

View File

@ -296,11 +296,8 @@ static int node_permissions_apply(sd_device *dev, bool apply_mac,
else
mode |= S_IFCHR;
if (lstat(devnode, &stats) < 0) {
if (errno == ENOENT)
return 0; /* this is necessarily racey, so ignore missing the device */
if (lstat(devnode, &stats) < 0)
return log_device_debug_errno(dev, errno, "cannot stat() node %s: %m", devnode);
}
if ((mode != MODE_INVALID && (stats.st_mode & S_IFMT) != (mode & S_IFMT)) || stats.st_rdev != devnum)
return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EEXIST),
@ -325,13 +322,11 @@ static int node_permissions_apply(sd_device *dev, bool apply_mac,
r = chmod_and_chown(devnode, mode, uid, gid);
if (r < 0)
log_device_full(dev, r == -ENOENT ? LOG_DEBUG : LOG_ERR, r,
"Failed to set owner/mode of %s to uid=" UID_FMT
", gid=" GID_FMT ", mode=%#o: %m",
devnode,
uid_is_valid(uid) ? uid : stats.st_uid,
gid_is_valid(gid) ? gid : stats.st_gid,
mode != MODE_INVALID ? mode & 0777 : stats.st_mode & 0777);
log_device_warning_errno(dev, r, "Failed to set owner/mode of %s to uid=" UID_FMT ", gid=" GID_FMT ", mode=%#o: %m",
devnode,
uid_is_valid(uid) ? uid : stats.st_uid,
gid_is_valid(gid) ? gid : stats.st_gid,
mode != MODE_INVALID ? mode & 0777 : stats.st_mode & 0777);
} else
log_device_debug(dev, "Preserve permissions of %s, uid=" UID_FMT ", gid=" GID_FMT ", mode=%#o",
devnode,
@ -348,8 +343,7 @@ static int node_permissions_apply(sd_device *dev, bool apply_mac,
q = mac_selinux_apply(devnode, label);
if (q < 0)
log_device_full(dev, q == -ENOENT ? LOG_DEBUG : LOG_ERR, q,
"SECLABEL: failed to set SELinux label '%s': %m", label);
log_device_error_errno(dev, q, "SECLABEL: failed to set SELinux label '%s': %m", label);
else
log_device_debug(dev, "SECLABEL: set SELinux label '%s'", label);
@ -358,8 +352,7 @@ static int node_permissions_apply(sd_device *dev, bool apply_mac,
q = mac_smack_apply(devnode, SMACK_ATTR_ACCESS, label);
if (q < 0)
log_device_full(dev, q == -ENOENT ? LOG_DEBUG : LOG_ERR, q,
"SECLABEL: failed to set SMACK label '%s': %m", label);
log_device_error_errno(dev, q, "SECLABEL: failed to set SMACK label '%s': %m", label);
else
log_device_debug(dev, "SECLABEL: set SMACK label '%s'", label);

View File

@ -2333,10 +2333,9 @@ static int apply_static_dev_perms(const char *devnode, uid_t uid, gid_t gid, mod
gid = 0;
r = chmod_and_chown(device_node, mode, uid, gid);
if (r == -ENOENT)
return 0;
if (r < 0)
return log_error_errno(r, "Failed to chown '%s' %u %u: %m", device_node, uid, gid);
return log_error_errno(errno, "Failed to chown '%s' %u %u: %m",
device_node, uid, gid);
else
log_debug("chown '%s' %u:%u with mode %#o", device_node, uid, gid, mode);