1
0
mirror of https://github.com/systemd/systemd synced 2026-03-14 17:14:49 +01:00

Compare commits

...

25 Commits

Author SHA1 Message Date
Alyssa Ross
f8eb41003d udev: make /dev/vfio/vfio 0666
Quoting Documentation/driver-api/vfio.rst in Linux:

> note that /dev/vfio/vfio provides no capabilities on its own and is therefore
> expected to be set to mode 0666 by the system
2021-05-05 17:22:00 +02:00
Luca Boccassi
73e799387f
Merge pull request #19505 from jwrdegoede/hwdb-2-accel-quirks
hwdb: Add 2 new accel quirks
2021-05-05 11:38:28 +01:00
Zbigniew Jędrzejewski-Szmek
b086a89695
Merge pull request #19453 from keszybz/consider-instance-aliases
Consider instance aliases
2021-05-05 11:23:42 +02:00
Zbigniew Jędrzejewski-Szmek
4c4c250563
Merge pull request #19454 from keszybz/assorted-cleanups
Assorted cleanups
2021-05-05 11:06:33 +02:00
Zbigniew Jędrzejewski-Szmek
ea0d33e2af tests: use "H" as the hostname
"systemd-testsuite" gets in the way when grepping for "testsuite-*.sh".
Also, the name doesn't matter for anything, so let's just use something
very short to save space.
2021-05-05 11:04:59 +02:00
Zbigniew Jędrzejewski-Szmek
41b2d7ac1d TEST-15: add test for template aliases 2021-05-04 17:59:34 +02:00
Zbigniew Jędrzejewski-Szmek
fd22838734 basic/unit-file: fix detection of instance aliases
We had the following scenario:
under /etc/systemd/system/
- foo@.service
- bar@tty12.servicefoo@tty12.service
- multi-user.target.wants/foo@tty12.service

Existing code did not "know" that foo@tty12.service has alias bar@tty12.service:
$ systemctl show -P Names foo@tty12.service
foo@tty12.service

Since multi-user.target is always loaded, we would load foo@tty12.service.
When trying to load bar@tty12.service, it would (correctly) detect that
bar@tty12.service is an alias for foo@tty12.service, and try to merge the
bar@tty12.service unit into the foo@tty12.service. This would fail, because
foo@tty12.service was already loaded, and only about-to-be-loaded units can
be merged.

With the patch we consider bar@tty12.service an alias of foo@tty12.service
immediately, so the issue does not occur:
$ systemctl show -P Names foo@tty12.service
foo@tty12.service bar@tty12.service

Fixes #19409.

This turned in a bigger rewrite. The logic add "the main name and all aliases"
was implemented twice, slightly different in both cases. I split that part out
to a new function. The result about the same length, but hopefully a bit easier
to read.

Logging output is also improved a bit. Some left-over debug logs have been
removed or cleaned up.

This is a fairly big change, but (with the addition in the following commit),
we have pretty good coverage of this logic.
2021-05-04 17:59:34 +02:00
Hans de Goede
bda6bfa5c1 hwdb: Add accel orientation quirk for the Toshiba WT8-B tablet
Add a quirk to fix the accelerometer orientation on the Toshiba WT8-B
tablet.
2021-05-04 17:38:33 +02:00
Hans de Goede
e0883f5350 hwdb: Add accel orientation quirk for the Glavey TM800A550L tablet
Add a quirk to fix the accelerometer orientation on the Glavey TM800A550L
tablet.
2021-05-04 17:36:52 +02:00
Zbigniew Jędrzejewski-Szmek
edb83bceec core/automount: drop unecessary cast 2021-05-04 14:57:49 +02:00
Zbigniew Jędrzejewski-Szmek
4c1f9343b2 core/cgroup: remove some unnecessary variables 2021-05-04 14:57:49 +02:00
Zbigniew Jędrzejewski-Szmek
905a0abd22 basic/log: directly initialize iovec arrays
It doesn't change much, but removes a bunch of explicit size and index handling
and unnecessary initializations.
2021-05-04 14:57:49 +02:00
Zbigniew Jędrzejewski-Szmek
2f9d1da95a basic/io-util: move iterator variable declarations into loop headers 2021-05-04 14:57:49 +02:00
Zbigniew Jędrzejewski-Szmek
cf1e6e6260 resolved: directly initialize iovec array 2021-05-04 14:57:49 +02:00
Zbigniew Jędrzejewski-Szmek
32f65484d7 basic/io-util: invert return value from IOVEC_INCREMENT()
We would try to return a value that could be nonzero only if the kernel
reported writing more bytes than we gave to it, hopefully a rare occurence.
Instead, assert that this doesn't happen.

Instead, return true if we got to the end of the iovec array. The caller
can use this information to know that the whole iovec array was written.
This allows one loop to be dropped in write_to_syslog().

Also drop _unlikely_: this function is called with very short arrays, and
it *is* likely that we trigger this condition. Let's just let the compiler
generate normal code without giving it a potentially false hint.
2021-05-04 14:57:49 +02:00
Zbigniew Jędrzejewski-Szmek
0f6bb1ed05 core: remove spurious % in dump string 2021-05-04 14:22:58 +02:00
Zbigniew Jędrzejewski-Szmek
806a93623c core/cgroup: use assert_se() more 2021-05-04 14:22:58 +02:00
Zbigniew Jędrzejewski-Szmek
431733b866 core: minor simplification 2021-05-04 14:22:58 +02:00
Zbigniew Jędrzejewski-Szmek
7e92ab4eb8 meson: make one check shorter 2021-05-04 14:22:58 +02:00
Zbigniew Jędrzejewski-Szmek
32464e18b4 test-unit-file: enable colors
There's quite a lot of output and it's much easier to grok this way.
2021-05-04 13:36:05 +02:00
Zbigniew Jędrzejewski-Szmek
6aac02ff1a TEST-15: add forgotten file cleanup 2021-05-04 13:36:05 +02:00
Zbigniew Jędrzejewski-Szmek
998df7ce0d manager: emit a message when we fail to create manager because /run is not set up
$ SYSTEMD_LOG_LEVEL=debug build/systemd --test --user
...
Failed to lookup RuntimeDirectory path: No such device or address   <---- this line is new
Failed to allocate manager object: No such device or address

We would fail and only say "Failed to allocate manager object: ENODEV" which is
not entirely self-explanatory. Let's add a better log message.
2021-05-04 13:36:05 +02:00
Zbigniew Jędrzejewski-Szmek
5169595ec3 TEST-15: use ${:?} and shorten things a bit 2021-05-04 13:36:05 +02:00
Zbigniew Jędrzejewski-Szmek
c0d4409219 test: properly catch tests error with no /testok or empty /failed
When editing this function in 7bf20e48bd7d641a39a14a7feb749b7e8, I couldn't
decide whether to initialize ret at the top and only reset it on success, or
whether to assign a value in each branch. In the end I did neither ;( So if the
test finished without creating any of the result files, we would echo a
message, but return "success".

But there was bigger confusion with /failed: some tests create it empty, some
don't. I think we may want to do away pre-creation of /failed completely, and
assume the test failed unless /testok is found. But I'm leaving that for later
rework. For now let's just make sure we report return success only if /testok
or /skipped is found.
2021-05-04 13:36:05 +02:00
Zbigniew Jędrzejewski-Szmek
3796bdc55d basic/unit-file: ignore any hidden files immediately
Hidden and backup files cannot be valid unit name (we reject anything
starting with a dot, and we require type suffixes). So let's not iterate
over those at all.
2021-04-28 17:12:32 +02:00
15 changed files with 243 additions and 165 deletions

View File

@ -344,6 +344,14 @@ sensor:modalias:acpi:KIOX000A*:dmi:*:svnEVE*:pnEveV:*
sensor:modalias:acpi:KIOX010A*:dmi:*:svnGEO*:pnGeoFlex*:*
ACCEL_MOUNT_MATRIX=-1, 0, 0; 0, -1, 0; 0, 0, 1
#########################################
# Glavey
#########################################
# Glavey TM800A550L
sensor:modalias:acpi:KXCJ9000*:dmi:*:bvrZY-8-BI-PX4S70VTR400-X423B-005-D:*:rvnAMICorporation:rnAptioCRB:*
ACCEL_MOUNT_MATRIX=-1, 0, 0; 0, 1, 0; 0, 0, 1
#########################################
# Google Chromebooks
#########################################
@ -778,6 +786,10 @@ sensor:modalias:acpi:BMA250E*:dmi:bvnAmericanMegatrendsInc.:bvr5.6.5:bd04/15/201
# Toshiba
#########################################
# Toshiba Encore WT8-B tablet
sensor:modalias:acpi:INVN6500*:dmi:*:svnTOSHIBA:pnTOSHIBAENCORE2WT8-B:*
ACCEL_MOUNT_MATRIX=0, -1, 0; -1, 0, 0; 0, 0, 1
# Toshiba Encore WT10A tablet
sensor:modalias:acpi:INVN6500*:dmi:*:svnTOSHIBA:pnTOSHIBAWT10-A-103:*
ACCEL_MOUNT_MATRIX=0, -1, 0; -1, 0, 0; 0, 0, 1

View File

@ -96,6 +96,8 @@ KERNEL=="fuse", MODE="0666", OPTIONS+="static_node=fuse"
# The static_node is required on s390x and ppc (they are using MODULE_ALIAS)
KERNEL=="kvm", GROUP="kvm", MODE="@DEV_KVM_MODE@", OPTIONS+="static_node=kvm"
KERNEL=="vfio", MODE="0666", OPTIONS+="static_node=vfio/vfio"
KERNEL=="vsock", MODE="0666"
KERNEL=="vhost-vsock", GROUP="kvm", MODE="@DEV_KVM_MODE@", OPTIONS+="static_node=vhost-vsock"

View File

@ -25,22 +25,25 @@ int fd_wait_for_event(int fd, int event, usec_t timeout);
ssize_t sparse_write(int fd, const void *p, size_t sz, size_t run_length);
static inline size_t IOVEC_TOTAL_SIZE(const struct iovec *i, size_t n) {
size_t j, r = 0;
size_t r = 0;
for (j = 0; j < n; j++)
for (size_t j = 0; j < n; j++)
r += i[j].iov_len;
return r;
}
static inline size_t IOVEC_INCREMENT(struct iovec *i, size_t n, size_t k) {
size_t j;
static inline bool IOVEC_INCREMENT(struct iovec *i, size_t n, size_t k) {
/* Returns true if there is nothing else to send (bytes written cover all of the iovec),
* false if there's still work to do. */
for (j = 0; j < n; j++) {
for (size_t j = 0; j < n; j++) {
size_t sub;
if (_unlikely_(k <= 0))
break;
if (i[j].iov_len == 0)
continue;
if (k == 0)
return false;
sub = MIN(i[j].iov_len, k);
i[j].iov_len -= sub;
@ -48,7 +51,9 @@ static inline size_t IOVEC_INCREMENT(struct iovec *i, size_t n, size_t k) {
k -= sub;
}
return k;
assert(k == 0); /* Anything else would mean that we wrote more bytes than available,
* or the kernel reported writing more bytes than sent. */
return true;
}
static inline bool FILE_SIZE_VALID(uint64_t l) {

View File

@ -452,11 +452,6 @@ static int write_to_syslog(
char header_priority[2 + DECIMAL_STR_MAX(int) + 1],
header_time[64],
header_pid[4 + DECIMAL_STR_MAX(pid_t) + 1];
struct iovec iovec[5] = {};
struct msghdr msghdr = {
.msg_iov = iovec,
.msg_iovlen = ELEMENTSOF(iovec),
};
time_t t;
struct tm tm;
@ -474,15 +469,21 @@ static int write_to_syslog(
xsprintf(header_pid, "["PID_FMT"]: ", getpid_cached());
iovec[0] = IOVEC_MAKE_STRING(header_priority);
iovec[1] = IOVEC_MAKE_STRING(header_time);
iovec[2] = IOVEC_MAKE_STRING(program_invocation_short_name);
iovec[3] = IOVEC_MAKE_STRING(header_pid);
iovec[4] = IOVEC_MAKE_STRING(buffer);
struct iovec iovec[] = {
IOVEC_MAKE_STRING(header_priority),
IOVEC_MAKE_STRING(header_time),
IOVEC_MAKE_STRING(program_invocation_short_name),
IOVEC_MAKE_STRING(header_pid),
IOVEC_MAKE_STRING(buffer),
};
struct msghdr msghdr = {
.msg_iov = iovec,
.msg_iovlen = ELEMENTSOF(iovec),
};
/* When using syslog via SOCK_STREAM separate the messages by NUL chars */
if (syslog_is_stream)
iovec[4].iov_len++;
iovec[ELEMENTSOF(iovec) - 1].iov_len++;
for (;;) {
ssize_t n;
@ -491,11 +492,11 @@ static int write_to_syslog(
if (n < 0)
return -errno;
if (!syslog_is_stream ||
(size_t) n >= IOVEC_TOTAL_SIZE(iovec, ELEMENTSOF(iovec)))
if (!syslog_is_stream)
break;
IOVEC_INCREMENT(iovec, ELEMENTSOF(iovec), n);
if (IOVEC_INCREMENT(iovec, ELEMENTSOF(iovec), n))
break;
}
return 1;
@ -520,7 +521,6 @@ static int write_to_kmsg(
char header_priority[2 + DECIMAL_STR_MAX(int) + 1],
header_pid[4 + DECIMAL_STR_MAX(pid_t) + 1];
struct iovec iovec[5] = {};
if (kmsg_fd < 0)
return 0;
@ -531,11 +531,13 @@ static int write_to_kmsg(
xsprintf(header_priority, "<%i>", level);
xsprintf(header_pid, "["PID_FMT"]: ", getpid_cached());
iovec[0] = IOVEC_MAKE_STRING(header_priority);
iovec[1] = IOVEC_MAKE_STRING(program_invocation_short_name);
iovec[2] = IOVEC_MAKE_STRING(header_pid);
iovec[3] = IOVEC_MAKE_STRING(buffer);
iovec[4] = IOVEC_MAKE_STRING("\n");
const struct iovec iovec[] = {
IOVEC_MAKE_STRING(header_priority),
IOVEC_MAKE_STRING(program_invocation_short_name),
IOVEC_MAKE_STRING(header_pid),
IOVEC_MAKE_STRING(buffer),
IOVEC_MAKE_STRING("\n"),
};
if (writev(kmsg_fd, iovec, ELEMENTSOF(iovec)) < 0)
return -errno;
@ -959,7 +961,7 @@ int log_struct_internal(
if (journal_fd >= 0) {
char header[LINE_MAX];
struct iovec iovec[17] = {};
size_t n = 0, i;
size_t n = 0;
int r;
struct msghdr mh = {
.msg_iov = iovec,
@ -981,7 +983,7 @@ int log_struct_internal(
}
va_end(ap);
for (i = 1; i < n; i += 2)
for (size_t i = 1; i < n; i += 2)
free(iovec[i].iov_base);
if (!fallback) {

View File

@ -284,7 +284,7 @@ int unit_file_build_name_map(
continue;
}
FOREACH_DIRENT_ALL(de, d, log_warning_errno(errno, "Failed to read \"%s\", ignoring: %m", *dir)) {
FOREACH_DIRENT(de, d, log_warning_errno(errno, "Failed to read \"%s\", ignoring: %m", *dir)) {
char *filename;
_cleanup_free_ char *_filename_free = NULL, *simplified = NULL;
const char *suffix, *dst = NULL;
@ -403,6 +403,7 @@ int unit_file_build_name_map(
/* Let's also put the names in the reverse db. */
const char *dummy, *src;
HASHMAP_FOREACH_KEY(dummy, src, ids) {
_cleanup_free_ char *inst = NULL, *dst_inst = NULL;
const char *dst;
r = unit_ids_map_get(ids, src, &dst);
@ -412,15 +413,31 @@ int unit_file_build_name_map(
if (null_or_empty_path(dst) != 0)
continue;
/* Do not treat instance symlinks that point to the template as aliases */
if (unit_name_is_valid(basename(dst), UNIT_NAME_TEMPLATE) &&
unit_name_is_valid(src, UNIT_NAME_INSTANCE))
continue;
dst = basename(dst);
r = string_strv_hashmap_put(&names, basename(dst), src);
/* If we have an symlink from an instance name to a template name, it is an alias just for
* this specific instance, foo@id.service template@id.service. */
if (unit_name_is_valid(dst, UNIT_NAME_TEMPLATE)) {
UnitNameFlags t = unit_name_to_instance(src, &inst);
if (t < 0)
return log_error_errno(t, "Failed to extract instance part from %s: %m", src);
if (t == UNIT_NAME_INSTANCE) {
r = unit_name_replace_instance(dst, inst, &dst_inst);
if (r < 0) {
/* This might happen e.g. if the combined length is too large.
* Let's not make too much of a fuss. */
log_debug_errno(r, "Failed to build alias name (%s + %s), ignoring: %m",
dst, inst);
continue;
}
dst = dst_inst;
}
}
r = string_strv_hashmap_put(&names, dst, src);
if (r < 0)
return log_warning_errno(r, "Failed to add entry to hashmap (%s→%s): %m",
basename(dst), src);
return log_warning_errno(r, "Failed to add entry to hashmap (%s→%s): %m", dst, src);
}
if (cache_timestamp_hash)
@ -434,6 +451,88 @@ int unit_file_build_name_map(
return 1;
}
static int add_name(
const char *unit_name,
Set **names,
const char *name) {
int r;
assert(names);
assert(name);
r = set_put_strdup(names, name);
if (r < 0)
return r;
if (r > 0 && !streq(unit_name, name))
log_debug("Unit %s has alias %s.", unit_name, name);
return r;
}
static int add_names(
Hashmap *unit_ids_map,
Hashmap *unit_name_map,
const char *unit_name,
const char *fragment_basename, /* Only set when adding additional names based on fragment path */
UnitNameFlags name_type,
const char *instance,
Set **names,
const char *name) {
char **aliases, **alias;
int r;
assert(name_type == UNIT_NAME_PLAIN || instance);
/* The unit has its own name if it's not a template. If we're looking at a fragment, the fragment
* name (possibly with instance inserted), is also always one of the unit names. */
if (name_type != UNIT_NAME_TEMPLATE) {
r = add_name(unit_name, names, name);
if (r < 0)
return r;
}
/* Add any aliases of the name to the set of names.
*
* We don't even need to know which fragment we will use. The unit_name_map should return the same
* set of names for any of the aliases. */
aliases = hashmap_get(unit_name_map, name);
STRV_FOREACH(alias, aliases) {
if (name_type == UNIT_NAME_INSTANCE && unit_name_is_valid(*alias, UNIT_NAME_TEMPLATE)) {
_cleanup_free_ char *inst = NULL;
const char *inst_fragment = NULL;
r = unit_name_replace_instance(*alias, instance, &inst);
if (r < 0)
return log_debug_errno(r, "Cannot build instance name %s + %s: %m",
*alias, instance);
/* Exclude any aliases that point in some other direction.
*
* See https://github.com/systemd/systemd/pull/13119#discussion_r308145418. */
r = unit_ids_map_get(unit_ids_map, inst, &inst_fragment);
if (r < 0 && !IN_SET(r, -ENOENT, -ENXIO))
return log_debug_errno(r, "Cannot find instance fragment %s: %m", inst);
if (inst_fragment &&
!streq(basename(inst_fragment), fragment_basename)) {
log_debug("Instance %s has fragment %s and is not an alias of %s.",
inst, inst_fragment, unit_name);
continue;
}
r = set_consume(*names, TAKE_PTR(inst));
if (r > 0)
log_debug("Unit %s has alias %s.", unit_name, inst);
} else
r = add_name(unit_name, names, *alias);
if (r < 0)
return r;
}
return 0;
}
int unit_file_find_fragment(
Hashmap *unit_ids_map,
Hashmap *unit_name_map,
@ -443,9 +542,8 @@ int unit_file_find_fragment(
const char *fragment = NULL;
_cleanup_free_ char *template = NULL, *instance = NULL;
_cleanup_set_free_free_ Set *names = NULL;
char **t, **nnn;
int r, name_type;
_cleanup_set_free_ Set *names = NULL;
int r;
/* Finds a fragment path, and returns the set of names:
* if we have /foo.service and /foo-alias.servicefoo.service,
@ -461,53 +559,19 @@ int unit_file_find_fragment(
* foo-alias@inst.service /foo@inst.service, {foo@inst.service, foo-alias@inst.service}.
*/
name_type = unit_name_to_instance(unit_name, &instance);
UnitNameFlags name_type = unit_name_to_instance(unit_name, &instance);
if (name_type < 0)
return name_type;
names = set_new(&string_hash_ops);
if (!names)
return -ENOMEM;
/* The unit always has its own name if it's not a template. */
if (IN_SET(name_type, UNIT_NAME_PLAIN, UNIT_NAME_INSTANCE)) {
r = set_put_strdup(&names, unit_name);
r = add_names(unit_ids_map, unit_name_map, unit_name, NULL, name_type, instance, &names, unit_name);
if (r < 0)
return r;
}
/* First try to load fragment under the original name */
r = unit_ids_map_get(unit_ids_map, unit_name, &fragment);
if (r < 0 && !IN_SET(r, -ENOENT, -ENXIO))
return log_debug_errno(r, "Cannot load unit %s: %m", unit_name);
if (fragment) {
/* Add any aliases of the original name to the set of names */
nnn = hashmap_get(unit_name_map, basename(fragment));
STRV_FOREACH(t, nnn) {
if (name_type == UNIT_NAME_INSTANCE && unit_name_is_valid(*t, UNIT_NAME_TEMPLATE)) {
char *inst;
r = unit_name_replace_instance(*t, instance, &inst);
if (r < 0)
return log_debug_errno(r, "Cannot build instance name %s+%s: %m", *t, instance);
if (!streq(unit_name, inst))
log_debug("%s: %s has alias %s", __func__, unit_name, inst);
log_info("%s: %s+%s → %s", __func__, *t, instance, inst);
r = set_consume(names, inst);
} else {
if (!streq(unit_name, *t))
log_debug("%s: %s has alias %s", __func__, unit_name, *t);
r = set_put_strdup(&names, *t);
}
if (r < 0)
return r;
}
}
if (!fragment && name_type == UNIT_NAME_INSTANCE) {
/* Look for a fragment under the template name */
@ -518,43 +582,22 @@ int unit_file_find_fragment(
r = unit_ids_map_get(unit_ids_map, template, &fragment);
if (r < 0 && !IN_SET(r, -ENOENT, -ENXIO))
return log_debug_errno(r, "Cannot load template %s: %m", template);
}
if (fragment) {
/* Add any aliases of the original name to the set of names */
nnn = hashmap_get(unit_name_map, basename(fragment));
STRV_FOREACH(t, nnn) {
_cleanup_free_ char *inst = NULL;
const char *inst_fragment = NULL;
const char *fragment_basename = basename(fragment);
r = unit_name_replace_instance(*t, instance, &inst);
if (r < 0)
return log_debug_errno(r, "Cannot build instance name %s+%s: %m", template, instance);
/* Exclude any aliases that point in some other direction. */
r = unit_ids_map_get(unit_ids_map, inst, &inst_fragment);
if (r < 0 && !IN_SET(r, -ENOENT, -ENXIO))
return log_debug_errno(r, "Cannot find instance fragment %s: %m", inst);
if (inst_fragment &&
!streq(basename(inst_fragment), basename(fragment))) {
log_debug("Instance %s has fragment %s and is not an alias of %s.",
inst, inst_fragment, unit_name);
continue;
}
if (!streq(unit_name, inst))
log_debug("%s: %s has alias %s", __func__, unit_name, inst);
r = set_consume(names, TAKE_PTR(inst));
if (!streq(fragment_basename, unit_name)) {
/* Add names based on the fragment name to the set of names */
r = add_names(unit_ids_map, unit_name_map, unit_name, fragment_basename, name_type, instance, &names, fragment_basename);
if (r < 0)
return r;
}
}
}
*ret_fragment_path = fragment;
*ret_names = TAKE_PTR(names);
// FIXME: if instance, consider any unit names with different template name
return 0;
}

View File

@ -190,7 +190,7 @@ if have_gnu_efi
'-znocombreloc',
'-L', efi_libdir,
efi_crt0]
if efi_arch == 'aarch64' or efi_arch == 'arm' or efi_arch == 'riscv64'
if ['aarch64', 'arm', 'riscv64'].contains(efi_arch)
# Aarch64, ARM32 and 64bit RISC-V don't have an EFI capable objcopy.
# Use 'binary' instead, and add required symbols manually.
efi_ldflags += ['--defsym=EFI_SUBSYSTEM=0xa']

View File

@ -651,7 +651,7 @@ fail:
static void *expire_thread(void *p) {
struct autofs_dev_ioctl param;
_cleanup_(expire_data_freep) struct expire_data *data = (struct expire_data*)p;
_cleanup_(expire_data_freep) struct expire_data *data = p;
int r;
assert(data->dev_autofs_fd >= 0);

View File

@ -305,8 +305,7 @@ static int unit_compare_memory_limit(Unit *u, const char *property_name, uint64_
if (!FLAGS_SET(m, CGROUP_MASK_MEMORY))
return -ENODATA;
c = unit_get_cgroup_context(u);
assert(c);
assert_se(c = unit_get_cgroup_context(u));
if (streq(property_name, "MemoryLow")) {
unit_value = unit_get_ancestor_memory_low(u);
@ -407,8 +406,7 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
assert(u);
assert(f);
c = unit_get_cgroup_context(u);
assert(c);
assert_se(c = unit_get_cgroup_context(u));
prefix = strempty(prefix);
@ -451,7 +449,7 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
"%sManagedOOMSwap: %s\n"
"%sManagedOOMMemoryPressure: %s\n"
"%sManagedOOMMemoryPressureLimit: " PERMYRIAD_AS_PERCENT_FORMAT_STR "\n"
"%sManagedOOMPreference: %s%%\n",
"%sManagedOOMPreference: %s\n",
prefix, yes_no(c->cpu_accounting),
prefix, yes_no(c->io_accounting),
prefix, yes_no(c->blockio_accounting),
@ -1028,17 +1026,14 @@ static void cgroup_apply_io_device_latency(Unit *u, const char *dev_path, usec_t
}
static void cgroup_apply_io_device_limit(Unit *u, const char *dev_path, uint64_t *limits) {
char limit_bufs[_CGROUP_IO_LIMIT_TYPE_MAX][DECIMAL_STR_MAX(uint64_t)];
char buf[DECIMAL_STR_MAX(dev_t)*2+2+(6+DECIMAL_STR_MAX(uint64_t)+1)*4];
CGroupIOLimitType type;
char limit_bufs[_CGROUP_IO_LIMIT_TYPE_MAX][DECIMAL_STR_MAX(uint64_t)],
buf[DECIMAL_STR_MAX(dev_t)*2+2+(6+DECIMAL_STR_MAX(uint64_t)+1)*4];
dev_t dev;
int r;
r = lookup_block_device(dev_path, &dev);
if (r < 0)
if (lookup_block_device(dev_path, &dev) < 0)
return;
for (type = 0; type < _CGROUP_IO_LIMIT_TYPE_MAX; type++)
for (CGroupIOLimitType type = 0; type < _CGROUP_IO_LIMIT_TYPE_MAX; type++)
if (limits[type] != cgroup_io_limit_defaults[type])
xsprintf(limit_bufs[type], "%" PRIu64, limits[type]);
else
@ -1053,10 +1048,8 @@ static void cgroup_apply_io_device_limit(Unit *u, const char *dev_path, uint64_t
static void cgroup_apply_blkio_device_limit(Unit *u, const char *dev_path, uint64_t rbps, uint64_t wbps) {
char buf[DECIMAL_STR_MAX(dev_t)*2+2+DECIMAL_STR_MAX(uint64_t)+1];
dev_t dev;
int r;
r = lookup_block_device(dev_path, &dev);
if (r < 0)
if (lookup_block_device(dev_path, &dev) < 0)
return;
sprintf(buf, "%u:%u %" PRIu64 "\n", major(dev), minor(dev), rbps);
@ -1071,8 +1064,7 @@ static bool unit_has_unified_memory_config(Unit *u) {
assert(u);
c = unit_get_cgroup_context(u);
assert(c);
assert_se(c = unit_get_cgroup_context(u));
return unit_get_ancestor_memory_min(u) > 0 || unit_get_ancestor_memory_low(u) > 0 ||
c->memory_high != CGROUP_LIMIT_MAX || c->memory_max != CGROUP_LIMIT_MAX ||
@ -1597,9 +1589,7 @@ static CGroupMask unit_get_cgroup_mask(Unit *u) {
assert(u);
c = unit_get_cgroup_context(u);
assert(c);
assert_se(c = unit_get_cgroup_context(u));
/* Figure out which controllers we need, based on the cgroup context object */

View File

@ -2549,18 +2549,16 @@ static void setup_console_terminal(bool skip_setup) {
static bool early_skip_setup_check(int argc, char *argv[]) {
bool found_deserialize = false;
int i;
/* Determine if this is a reexecution or normal bootup. We do the full command line parsing much later, so
* let's just have a quick peek here. Note that if we have switched root, do all the special setup things
* anyway, even if in that case we also do deserialization. */
for (i = 1; i < argc; i++) {
for (int i = 1; i < argc; i++)
if (streq(argv[i], "--switched-root"))
return false; /* If we switched root, don't skip the setup. */
else if (streq(argv[i], "--deserialize"))
found_deserialize = true;
}
return found_deserialize; /* When we are deserializing, then we are reexecuting, hence avoid the extensive setup */
}

View File

@ -688,7 +688,8 @@ static int manager_setup_prefix(Manager *m) {
for (ExecDirectoryType i = 0; i < _EXEC_DIRECTORY_TYPE_MAX; i++) {
r = sd_path_lookup(p[i].type, p[i].suffix, &m->prefix[i]);
if (r < 0)
return r;
return log_warning_errno(r, "Failed to lookup %s path: %m",
exec_directory_type_to_string(i));
}
return 0;

View File

@ -315,15 +315,14 @@ static int on_stream_io(sd_event_source *es, int fd, uint32_t revents, void *use
s->write_packet &&
s->n_written < sizeof(s->write_size) + s->write_packet->size) {
struct iovec iov[2];
ssize_t ss;
struct iovec iov[] = {
IOVEC_MAKE(&s->write_size, sizeof(s->write_size)),
IOVEC_MAKE(DNS_PACKET_DATA(s->write_packet), s->write_packet->size),
};
iov[0] = IOVEC_MAKE(&s->write_size, sizeof(s->write_size));
iov[1] = IOVEC_MAKE(DNS_PACKET_DATA(s->write_packet), s->write_packet->size);
IOVEC_INCREMENT(iov, ELEMENTSOF(iov), s->n_written);
IOVEC_INCREMENT(iov, 2, s->n_written);
ss = dns_stream_writev(s, iov, 2, 0);
ssize_t ss = dns_stream_writev(s, iov, ELEMENTSOF(iov), 0);
if (ss < 0) {
if (!IN_SET(-ss, EINTR, EAGAIN))
return dns_stream_complete(s, -ss);

View File

@ -92,6 +92,7 @@ static void test_runlevel_to_target(void) {
}
int main(int argc, char **argv) {
log_show_color(true);
test_setup_logging(LOG_DEBUG);
test_unit_validate_alias_symlink_and_warn();

View File

@ -1134,8 +1134,7 @@ check_result_common() {
local ret
if [ -s "$workspace/failed" ]; then
# …/failed only counts if non-empty
ls -l "$workspace/failed"
# Non-empty …/failed has highest priority
cp -a "$workspace/failed" "${TESTDIR:?}/"
ret=1
elif [ -e "$workspace/testok" ]; then
@ -1147,24 +1146,28 @@ check_result_common() {
cat "$workspace/skipped"
ret=0
elif [ -n "$TIMED_OUT" ]; then
echo "${TESTNAME:?} timed out!"
echo "(timeout)" >"${TESTDIR:?}/failed"
ret=2
else
echo "${TESTNAME:?} did not report a result!"
echo "(failed; see logs)" >"${TESTDIR:?}/failed"
ret=3
fi
save_journal "$workspace/var/log/journal"
check_asan_reports "$workspace" || ret=3
check_asan_reports "$workspace" || ret=4
if [ -d "${ARTIFACT_DIRECTORY}" ] && [ -f "$workspace/strace.out" ]; then
cp "$workspace/strace.out" "${ARTIFACT_DIRECTORY}/"
fi
[ -f "$TESTDIR/failed" ] && cat "$TESTDIR/failed"
if [ ${ret:?} != 0 ] && [ -f "$TESTDIR/failed" ]; then
echo -n "${TESTNAME:?}: "
cat "$TESTDIR/failed"
fi
echo "${JOURNAL_LIST:-"No journals were saved"}"
return $ret
return ${ret:?}
}
check_result_nspawn() {
@ -1309,7 +1312,7 @@ install_config_files() {
: >"$initdir/etc/resolv.conf"
# set the hostname
echo systemd-testsuite >"$initdir/etc/hostname"
echo 'H' >"$initdir/etc/hostname"
# let's set up just one image with the traditional verbose output
if [ "${IMAGE_NAME:?}" != "basic" ]; then

View File

@ -32,12 +32,9 @@ create_service () {
Description=$SERVICE_NAME unit
[Service]
ExecStart=/bin/sleep 100000
ExecStart=sleep 100000
EOF
mkdir -p /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service.d
mkdir -p /etc/systemd/system/"$SERVICE_NAME".service.{wants,requires}
mkdir -p /run/systemd/system/"$SERVICE_NAME".service.{wants,requires}
mkdir -p /usr/lib/systemd/system/"$SERVICE_NAME".service.{wants,requires}
mkdir -p /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service.{d,wants,requires}
}
create_services () {
@ -47,11 +44,9 @@ create_services () {
}
check_ok () {
[ $# -eq 3 ] || return
x="$(systemctl show --value -p "$2" "$1")"
x="$(systemctl show --value -p "${2:?}" "${1:?}")"
case "$x" in
*$3*) return 0 ;;
*${3:?}*) return 0 ;;
*) return 1 ;;
esac
}
@ -123,7 +118,7 @@ EOF
check_ok test15-b ExecCondition "/bin/echo test15-b"
rm -rf /usr/lib/systemd/system/service.d
clear_services test15-a test15-b test15-c
clear_services test15-a test15-b test15-c test15-c1
}
test_linked_units () {
@ -153,6 +148,32 @@ test_linked_units () {
clear_services test15-a test15-b
}
test_template_alias() {
echo "Testing instance alias..."
echo "*** forward"
create_service test15-a@
ln -s test15-a@inst.service /etc/systemd/system/test15-b@inst.service # alias
check_ok test15-a@inst Names test15-a@inst.service
check_ok test15-a@inst Names test15-b@inst.service
check_ok test15-a@other Names test15-a@other.service
check_ko test15-a@other Names test15-b@other.service
echo "*** reverse"
systemctl daemon-reload
check_ok test15-b@inst Names test15-a@inst.service
check_ok test15-b@inst Names test15-b@inst.service
check_ko test15-b@other Names test15-a@other.service
check_ok test15-b@other Names test15-b@other.service
clear_services test15-a@ test15-b@
}
test_hierarchical_dropins () {
echo "Testing hierarchical dropins..."
echo "*** test service.d/ top level drop-in"
@ -495,6 +516,7 @@ test_invalid_dropins () {
test_basic_dropins
test_linked_units
test_template_alias
test_hierarchical_dropins
test_template_dropins
test_alias_dropins

View File

@ -16,11 +16,11 @@ systemctl start testservice-48.target
# granularity of one second, which means the manager's unit cache won't be
# marked as dirty when writing the unit file, unless we wait at least a full
# second after the previous daemon-reload.
# May 07 23:12:20 systemd-testsuite testsuite-48.sh[30]: + cat
# May 07 23:12:20 systemd-testsuite testsuite-48.sh[30]: + ls -l --full-time /etc/systemd/system/testservice-48.service
# May 07 23:12:20 systemd-testsuite testsuite-48.sh[52]: -rw-r--r-- 1 root root 50 2020-05-07 23:12:20.000000000 +0100 /
# May 07 23:12:20 systemd-testsuite testsuite-48.sh[30]: + stat -f --format=%t /etc/systemd/system/testservice-48.servic
# May 07 23:12:20 systemd-testsuite testsuite-48.sh[53]: ef53
# May 07 23:12:20 H testsuite-48.sh[30]: + cat
# May 07 23:12:20 H testsuite-48.sh[30]: + ls -l --full-time /etc/systemd/system/testservice-48.service
# May 07 23:12:20 H testsuite-48.sh[52]: -rw-r--r-- 1 root root 50 2020-05-07 23:12:20.000000000 +0100 /
# May 07 23:12:20 H testsuite-48.sh[30]: + stat -f --format=%t /etc/systemd/system/testservice-48.servic
# May 07 23:12:20 H testsuite-48.sh[53]: ef53
sleep 3.1
cat >/run/systemd/system/testservice-48.service <<EOF