diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-05-04 18:40:02 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-05-05 15:08:48 +0200 |
commit | 73ce91a05a63f44367b48a7ef3ca1ce4e85205b3 (patch) | |
tree | 0a15417b3a1d5dde5ac03644c2ca8a77c380f144 | |
parent | Merge pull request #19505 from jwrdegoede/hwdb-2-accel-quirks (diff) | |
download | systemd-73ce91a05a63f44367b48a7ef3ca1ce4e85205b3.tar.xz systemd-73ce91a05a63f44367b48a7ef3ca1ce4e85205b3.zip |
Make unit_name_to_instance() return UnitNameFlags
The function returns non-negative UnitNameFlags on success, and negative
errno on error. In the past we kept the return type as int because of those
negative return values. But nowadays _UNIT_NAME_INVALID == -EINVAL. And if
we tried to actually return something that doesn't fit in the return type,
the compiler would throw an error. By changing to the "real" return type,
we allow the debugger to use symbolic representation for the variables.
-rw-r--r-- | src/basic/unit-file.c | 2 | ||||
-rw-r--r-- | src/basic/unit-name.c | 2 | ||||
-rw-r--r-- | src/basic/unit-name.h | 4 | ||||
-rw-r--r-- | src/shared/install.c | 14 | ||||
-rw-r--r-- | src/test/test-unit-name.c | 2 |
5 files changed, 12 insertions, 12 deletions
diff --git a/src/basic/unit-file.c b/src/basic/unit-file.c index ff8aa02d10..fab63b6dce 100644 --- a/src/basic/unit-file.c +++ b/src/basic/unit-file.c @@ -72,7 +72,7 @@ int unit_validate_alias_symlink_and_warn(const char *filename, const char *targe const char *src, *dst; _cleanup_free_ char *src_instance = NULL, *dst_instance = NULL; UnitType src_unit_type, dst_unit_type; - int src_name_type, dst_name_type; + UnitNameFlags src_name_type, dst_name_type; /* Check if the *alias* symlink is valid. This applies to symlinks like * /etc/systemd/system/dbus.service → dbus-broker.service, but not to .wants or .requires symlinks diff --git a/src/basic/unit-name.c b/src/basic/unit-name.c index 532f8fa048..dbc9f5baa2 100644 --- a/src/basic/unit-name.c +++ b/src/basic/unit-name.c @@ -139,7 +139,7 @@ int unit_name_to_prefix(const char *n, char **ret) { return 0; } -int unit_name_to_instance(const char *n, char **ret) { +UnitNameFlags unit_name_to_instance(const char *n, char **ret) { const char *p, *d; assert(n); diff --git a/src/basic/unit-name.h b/src/basic/unit-name.h index 19d70abea8..f6af01c9bd 100644 --- a/src/basic/unit-name.h +++ b/src/basic/unit-name.h @@ -22,8 +22,8 @@ bool unit_instance_is_valid(const char *i) _pure_; bool unit_suffix_is_valid(const char *s) _pure_; int unit_name_to_prefix(const char *n, char **ret); -int unit_name_to_instance(const char *n, char **ret); -static inline int unit_name_classify(const char *n) { +UnitNameFlags unit_name_to_instance(const char *n, char **ret); +static inline UnitNameFlags unit_name_classify(const char *n) { return unit_name_to_instance(n, NULL); } int unit_name_to_prefix_and_instance(const char *n, char **ret); diff --git a/src/shared/install.c b/src/shared/install.c index a8091cd071..3e9f6a3df3 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -1754,12 +1754,12 @@ int unit_file_verify_alias(const UnitFileInstallInfo *i, const char *dst, char * "Invalid path \"%s\" in alias.", dir); *p = '\0'; /* dir should now be a unit name */ - r = unit_name_classify(dir); - if (r < 0) + UnitNameFlags type = unit_name_classify(dir); + if (type < 0) return log_warning_errno(SYNTHETIC_ERRNO(EXDEV), "Invalid unit name component \"%s\" in alias.", dir); - const bool instance_propagation = r == UNIT_NAME_TEMPLATE; + const bool instance_propagation = type == UNIT_NAME_TEMPLATE; /* That's the name we want to use for verification. */ r = unit_symlink_name_compatible(path_alias, i->name, instance_propagation); @@ -1776,11 +1776,11 @@ int unit_file_verify_alias(const UnitFileInstallInfo *i, const char *dst, char * if (unit_name_is_valid(dst, UNIT_NAME_TEMPLATE)) { _cleanup_free_ char *inst = NULL; - r = unit_name_to_instance(i->name, &inst); - if (r < 0) - return log_error_errno(r, "Failed to extract instance name from %s: %m", i->name); + UnitNameFlags type = unit_name_to_instance(i->name, &inst); + if (type < 0) + return log_error_errno(type, "Failed to extract instance name from %s: %m", i->name); - if (r == UNIT_NAME_INSTANCE) { + if (type == UNIT_NAME_INSTANCE) { r = unit_name_replace_instance(dst, inst, &dst_updated); if (r < 0) return log_error_errno(r, "Failed to build unit name from %s+%s: %m", diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c index ece78aa548..dc4dc7529d 100644 --- a/src/test/test-unit-name.c +++ b/src/test/test-unit-name.c @@ -471,8 +471,8 @@ static void test_build_parent_slice(void) { } static void test_unit_name_to_instance(void) { + UnitNameFlags r; char *instance; - int r; log_info("/* %s */", __func__); |