1
0
mirror of https://github.com/systemd/systemd synced 2026-03-17 10:34:46 +01:00

Compare commits

...

5 Commits

Author SHA1 Message Date
Luca Boccassi
357f5b07ae
Merge pull request #19779 from poettering/unit-name-length-tweak
improve logging when encountering mount points we cannot convert to unit names due to length
2021-06-02 11:32:52 +01:00
Yu Watanabe
7bbcaee307 cryptsetup: fix typo 2021-06-02 11:35:14 +02:00
Lennart Poettering
3ebc9b9b30 mount: be more descriptive when logging about overly long mount point paths
This is prompted by #17684: let's very explicitly say that the name is
too long for us, and that we'll ignore it.
2021-06-01 23:08:21 +02:00
Lennart Poettering
598a6a8491 core: when looping over mount/swap names, continue if we find one which doesn't translate to a valid unit name 2021-06-01 23:08:21 +02:00
Lennart Poettering
9d5acfab20 unit-name: generate a clear error code when converting an overly long fs path to a unit name 2021-06-01 23:08:13 +02:00
6 changed files with 26 additions and 9 deletions

View File

@ -528,6 +528,9 @@ int unit_name_from_path(const char *path, const char *suffix, char **ret) {
if (!s) if (!s)
return -ENOMEM; return -ENOMEM;
if (strlen(s) >= UNIT_NAME_MAX) /* Return a slightly more descriptive error for this specific condition */
return -ENAMETOOLONG;
/* Refuse this if this got too long or for some other reason didn't result in a valid name */ /* Refuse this if this got too long or for some other reason didn't result in a valid name */
if (!unit_name_is_valid(s, UNIT_NAME_PLAIN)) if (!unit_name_is_valid(s, UNIT_NAME_PLAIN))
return -EINVAL; return -EINVAL;
@ -559,6 +562,9 @@ int unit_name_from_path_instance(const char *prefix, const char *path, const cha
if (!s) if (!s)
return -ENOMEM; return -ENOMEM;
if (strlen(s) >= UNIT_NAME_MAX) /* Return a slightly more descriptive error for this specific condition */
return -ENAMETOOLONG;
/* Refuse this if this got too long or for some other reason didn't result in a valid name */ /* Refuse this if this got too long or for some other reason didn't result in a valid name */
if (!unit_name_is_valid(s, UNIT_NAME_INSTANCE)) if (!unit_name_is_valid(s, UNIT_NAME_INSTANCE))
return -EINVAL; return -EINVAL;

View File

@ -1713,11 +1713,18 @@ static int mount_setup_unit(
.burst = 1, .burst = 1,
}; };
if (r == -ENAMETOOLONG)
return log_struct_errno( return log_struct_errno(
ratelimit_below(&rate_limit) ? LOG_WARNING : LOG_DEBUG, r, ratelimit_below(&rate_limit) ? LOG_WARNING : LOG_DEBUG, r,
"MESSAGE_ID=" SD_MESSAGE_MOUNT_POINT_PATH_NOT_SUITABLE_STR, "MESSAGE_ID=" SD_MESSAGE_MOUNT_POINT_PATH_NOT_SUITABLE_STR,
"MOUNT_POINT=%s", where, "MOUNT_POINT=%s", where,
LOG_MESSAGE("Failed to generate valid unit name from path '%s', ignoring mount point: %m", where)); LOG_MESSAGE("Mount point path '%s' too long to fit into unit name, ignoring mount point.", where));
return log_struct_errno(
ratelimit_below(&rate_limit) ? LOG_WARNING : LOG_DEBUG, r,
"MESSAGE_ID=" SD_MESSAGE_MOUNT_POINT_PATH_NOT_SUITABLE_STR,
"MOUNT_POINT=%s", where,
LOG_MESSAGE("Failed to generate valid unit name from mount point path '%s', ignoring mount point: %m", where));
} }
u = manager_get_unit(m, e); u = manager_get_unit(m, e);

View File

@ -1448,6 +1448,9 @@ int swap_process_device_new(Manager *m, sd_device *dev) {
int q; int q;
q = unit_name_from_path(devlink, ".swap", &n); q = unit_name_from_path(devlink, ".swap", &n);
if (IN_SET(q, -EINVAL, -ENAMETOOLONG)) /* If name too long or otherwise not convertible to
* unit name, we can't manage it */
continue;
if (q < 0) if (q < 0)
return q; return q;

View File

@ -1473,16 +1473,17 @@ static int unit_add_mount_dependencies(Unit *u) {
Unit *m; Unit *m;
r = unit_name_from_path(prefix, ".mount", &p); r = unit_name_from_path(prefix, ".mount", &p);
if (IN_SET(r, -EINVAL, -ENAMETOOLONG))
continue; /* If the path cannot be converted to a mount unit name, then it's
* not managable as a unit by systemd, and hence we don't need a
* dependency on it. Let's thus silently ignore the issue. */
if (r < 0) if (r < 0)
return r; return r;
m = manager_get_unit(u->manager, p); m = manager_get_unit(u->manager, p);
if (!m) { if (!m) {
/* Make sure to load the mount unit if /* Make sure to load the mount unit if it exists. If so the dependencies on
* it exists. If so the dependencies * this unit will be added later during the loading of the mount unit. */
* on this unit will be added later
* during the loading of the mount
* unit. */
(void) manager_load_unit_prepare(u->manager, p, NULL, NULL, &m); (void) manager_load_unit_prepare(u->manager, p, NULL, NULL, &m);
continue; continue;
} }

View File

@ -146,7 +146,7 @@ static void cryptsetup_log_glue(int level, const char *msg, void *usrptr) {
} }
void cryptsetup_enable_logging(struct crypt_device *cd) { void cryptsetup_enable_logging(struct crypt_device *cd) {
/* It's OK to call this with a NULL parameter, in which case libcryptsetup will set the defaut log /* It's OK to call this with a NULL parameter, in which case libcryptsetup will set the default log
* function. * function.
* *
* Note that this is also called from dlopen_cryptsetup(), which we call here too. Sounds like an * Note that this is also called from dlopen_cryptsetup(), which we call here too. Sounds like an

View File

@ -130,7 +130,7 @@ static void test_unit_name_from_path(void) {
test_unit_name_from_path_one("///", ".mount", "-.mount", 0); test_unit_name_from_path_one("///", ".mount", "-.mount", 0);
test_unit_name_from_path_one("/foo/../bar", ".mount", NULL, -EINVAL); test_unit_name_from_path_one("/foo/../bar", ".mount", NULL, -EINVAL);
test_unit_name_from_path_one("/foo/./bar", ".mount", "foo-bar.mount", 0); test_unit_name_from_path_one("/foo/./bar", ".mount", "foo-bar.mount", 0);
test_unit_name_from_path_one("/waldoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", ".mount", NULL, -EINVAL); test_unit_name_from_path_one("/waldoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", ".mount", NULL, -ENAMETOOLONG);
} }
static void test_unit_name_from_path_instance_one(const char *pattern, const char *path, const char *suffix, const char *expected, int ret) { static void test_unit_name_from_path_instance_one(const char *pattern, const char *path, const char *suffix, const char *expected, int ret) {
@ -160,7 +160,7 @@ static void test_unit_name_from_path_instance(void) {
test_unit_name_from_path_instance_one("waldo", "..", ".mount", NULL, -EINVAL); test_unit_name_from_path_instance_one("waldo", "..", ".mount", NULL, -EINVAL);
test_unit_name_from_path_instance_one("waldo", "/foo", ".waldi", NULL, -EINVAL); test_unit_name_from_path_instance_one("waldo", "/foo", ".waldi", NULL, -EINVAL);
test_unit_name_from_path_instance_one("wa--ldo", "/--", ".mount", "wa--ldo@\\x2d\\x2d.mount", 0); test_unit_name_from_path_instance_one("wa--ldo", "/--", ".mount", "wa--ldo@\\x2d\\x2d.mount", 0);
test_unit_name_from_path_instance_one("waldoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "/waldo", ".mount", NULL, -EINVAL); test_unit_name_from_path_instance_one("waldoaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "/waldo", ".mount", NULL, -ENAMETOOLONG);
} }
static void test_unit_name_to_path_one(const char *unit, const char *path, int ret) { static void test_unit_name_to_path_one(const char *unit, const char *path, int ret) {