Compare commits
14 Commits
9e9dd3e329
...
cee33a7ab3
Author | SHA1 | Date |
---|---|---|
Anita Zhang | cee33a7ab3 | |
Zbigniew Jędrzejewski-Szmek | d1be9a4380 | |
Zbigniew Jędrzejewski-Szmek | 637bc63a5c | |
Lennart Poettering | 462255c65b | |
Lennart Poettering | 91fc013fc4 | |
Franck Bui | 8246905af0 | |
Zbigniew Jędrzejewski-Szmek | 642f41a4ec | |
Zbigniew Jędrzejewski-Szmek | c86ebcf389 | |
Zbigniew Jędrzejewski-Szmek | e9f4f5667d | |
Zbigniew Jędrzejewski-Szmek | 827ca90986 | |
Zbigniew Jędrzejewski-Szmek | cbe8049474 | |
Yu Watanabe | b64b83d13e | |
Yu Watanabe | ffdc9c891f | |
Yu Watanabe | 4b613ec212 |
6
TODO
6
TODO
|
@ -30,6 +30,12 @@ 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
|
||||
|
|
42
meson.build
42
meson.build
|
@ -8,6 +8,7 @@ project('systemd', 'c',
|
|||
'prefix=/usr',
|
||||
'sysconfdir=/etc',
|
||||
'localstatedir=/var',
|
||||
'warning_level=2',
|
||||
],
|
||||
meson_version : '>= 0.46',
|
||||
)
|
||||
|
@ -302,7 +303,8 @@ install_tests = get_option('install-tests')
|
|||
|
||||
if add_languages('cpp', required : fuzzer_build)
|
||||
# Used only for tests
|
||||
cxx_cmd = ' '.join(meson.get_compiler('cpp').cmd_array())
|
||||
cxx = meson.get_compiler('cpp')
|
||||
cxx_cmd = ' '.join(cxx.cmd_array())
|
||||
else
|
||||
cxx_cmd = ''
|
||||
endif
|
||||
|
@ -322,8 +324,25 @@ 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',
|
||||
|
@ -353,10 +372,6 @@ 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
|
||||
|
||||
|
@ -401,16 +416,7 @@ if get_option('buildtype') != 'debug'
|
|||
possible_link_flags += '-Wl,--gc-sections'
|
||||
endif
|
||||
|
||||
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(basic_disabled_warnings), language : 'c')
|
||||
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')
|
||||
|
||||
|
@ -427,6 +433,10 @@ 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')
|
||||
|
|
|
@ -1239,23 +1239,27 @@ error:
|
|||
}
|
||||
|
||||
static void session_restore_vt(Session *s) {
|
||||
int r, vt, old_fd;
|
||||
int r;
|
||||
|
||||
/* 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);
|
||||
r = vt_restore(s->vtfd);
|
||||
if (r == -EIO) {
|
||||
int vt, old_fd;
|
||||
|
||||
vt = session_open_vt(s);
|
||||
safe_close(old_fd);
|
||||
/* 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. */
|
||||
|
||||
if (vt < 0)
|
||||
return;
|
||||
/* 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);
|
||||
}
|
||||
|
||||
r = vt_restore(vt);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to restore VT, ignoring: %m");
|
||||
|
||||
|
|
|
@ -265,20 +265,20 @@ shared_sources += shared_generated_gperf_headers
|
|||
libshared_name = 'systemd-shared-@0@'.format(meson.project_version())
|
||||
|
||||
libshared_deps = [threads,
|
||||
librt,
|
||||
libcap,
|
||||
libacl,
|
||||
libblkid,
|
||||
libcap,
|
||||
libcryptsetup,
|
||||
libgcrypt,
|
||||
libidn,
|
||||
libiptc,
|
||||
libkmod,
|
||||
liblz4,
|
||||
libmount,
|
||||
librt,
|
||||
libseccomp,
|
||||
libselinux,
|
||||
libidn,
|
||||
libxz,
|
||||
liblz4,
|
||||
libblkid]
|
||||
libxz]
|
||||
|
||||
libshared_sym_path = '@0@/libshared.sym'.format(meson.current_source_dir())
|
||||
|
||||
|
|
|
@ -11,12 +11,11 @@ test_hashmap_ordered_c = custom_target(
|
|||
|
||||
test_include_dir = include_directories('.')
|
||||
|
||||
path = run_command('sh', ['-c', 'echo "$PATH"']).stdout()
|
||||
path = run_command('sh', ['-c', 'echo "$PATH"']).stdout().strip()
|
||||
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', path)
|
||||
test_env.prepend('PATH', meson.build_root())
|
||||
test_env.set('PATH', '@0@:@1@'.format(meson.build_root(), path))
|
||||
|
||||
############################################################
|
||||
|
||||
|
|
|
@ -24,43 +24,61 @@
|
|||
#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) {
|
||||
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));
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
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.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@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.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@.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@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(".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("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("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));
|
||||
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);
|
||||
}
|
||||
|
||||
static void test_unit_name_replace_instance_one(const char *pattern, const char *repl, const char *expected, int ret) {
|
||||
|
@ -71,7 +89,8 @@ static void test_unit_name_replace_instance_one(const char *pattern, const char
|
|||
}
|
||||
|
||||
static void test_unit_name_replace_instance(void) {
|
||||
puts("-------------------------------------------------");
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
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);
|
||||
|
@ -98,7 +117,8 @@ static void test_unit_name_from_path_one(const char *path, const char *suffix, c
|
|||
}
|
||||
|
||||
static void test_unit_name_from_path(void) {
|
||||
puts("-------------------------------------------------");
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
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);
|
||||
|
@ -126,7 +146,7 @@ static void test_unit_name_from_path_instance_one(const char *pattern, const cha
|
|||
}
|
||||
|
||||
static void test_unit_name_from_path_instance(void) {
|
||||
puts("-------------------------------------------------");
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
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);
|
||||
|
@ -146,6 +166,8 @@ 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);
|
||||
|
@ -175,7 +197,8 @@ static void test_unit_name_mangle_one(bool allow_globs, const char *pattern, con
|
|||
}
|
||||
|
||||
static void test_unit_name_mangle(void) {
|
||||
puts("-------------------------------------------------");
|
||||
log_info("/* %s */", __func__);
|
||||
|
||||
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);
|
||||
|
@ -198,6 +221,8 @@ 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());
|
||||
|
@ -299,6 +324,8 @@ 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"));
|
||||
|
@ -312,6 +339,8 @@ 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"));
|
||||
|
@ -328,6 +357,8 @@ 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);
|
||||
|
@ -340,6 +371,8 @@ 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);
|
||||
|
@ -354,6 +387,8 @@ 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"));
|
||||
|
@ -386,6 +421,8 @@ 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);
|
||||
|
@ -408,6 +445,8 @@ 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);
|
||||
|
@ -430,6 +469,8 @@ 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"));
|
||||
|
@ -461,6 +502,8 @@ 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"));
|
||||
|
@ -475,6 +518,8 @@ 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);
|
||||
}
|
||||
|
@ -487,6 +532,7 @@ 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);
|
||||
|
@ -510,6 +556,8 @@ 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);
|
||||
|
@ -530,6 +578,8 @@ 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");
|
||||
|
|
|
@ -296,8 +296,11 @@ static int node_permissions_apply(sd_device *dev, bool apply_mac,
|
|||
else
|
||||
mode |= S_IFCHR;
|
||||
|
||||
if (lstat(devnode, &stats) < 0)
|
||||
if (lstat(devnode, &stats) < 0) {
|
||||
if (errno == ENOENT)
|
||||
return 0; /* this is necessarily racey, so ignore missing the device */
|
||||
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),
|
||||
|
@ -322,11 +325,13 @@ static int node_permissions_apply(sd_device *dev, bool apply_mac,
|
|||
|
||||
r = chmod_and_chown(devnode, mode, uid, gid);
|
||||
if (r < 0)
|
||||
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);
|
||||
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);
|
||||
} else
|
||||
log_device_debug(dev, "Preserve permissions of %s, uid=" UID_FMT ", gid=" GID_FMT ", mode=%#o",
|
||||
devnode,
|
||||
|
@ -343,7 +348,8 @@ static int node_permissions_apply(sd_device *dev, bool apply_mac,
|
|||
|
||||
q = mac_selinux_apply(devnode, label);
|
||||
if (q < 0)
|
||||
log_device_error_errno(dev, q, "SECLABEL: failed to set SELinux label '%s': %m", label);
|
||||
log_device_full(dev, q == -ENOENT ? LOG_DEBUG : LOG_ERR, q,
|
||||
"SECLABEL: failed to set SELinux label '%s': %m", label);
|
||||
else
|
||||
log_device_debug(dev, "SECLABEL: set SELinux label '%s'", label);
|
||||
|
||||
|
@ -352,7 +358,8 @@ 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_error_errno(dev, q, "SECLABEL: failed to set SMACK label '%s': %m", label);
|
||||
log_device_full(dev, q == -ENOENT ? LOG_DEBUG : LOG_ERR, q,
|
||||
"SECLABEL: failed to set SMACK label '%s': %m", label);
|
||||
else
|
||||
log_device_debug(dev, "SECLABEL: set SMACK label '%s'", label);
|
||||
|
||||
|
|
|
@ -2333,9 +2333,10 @@ 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(errno, "Failed to chown '%s' %u %u: %m",
|
||||
device_node, uid, gid);
|
||||
return log_error_errno(r, "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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue