summaryrefslogtreecommitdiff
path: root/src/basic/cap-list.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-02-20 12:25:44 +0100
committerLennart Poettering <lennart@poettering.net>2023-02-20 16:13:49 +0100
commit3f444e94f5a7ccc8d4f16a331858b0a4e717b773 (patch)
tree2bf94bbec1086016585666352121f4407c453cce /src/basic/cap-list.c
parent8142d73574b4743081e096bf15bee65e8214b656 (diff)
downloadsystemd-3f444e94f5a7ccc8d4f16a331858b0a4e717b773.tar.gz
cap-list: modernize capability_set_from_string() a bit
Make return parameter optional. And return whether there were any caps we didn't recognize via 0/1 return value.
Diffstat (limited to 'src/basic/cap-list.c')
-rw-r--r--src/basic/cap-list.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/basic/cap-list.c b/src/basic/cap-list.c
index b764d23cca..0af37b94ee 100644
--- a/src/basic/cap-list.c
+++ b/src/basic/cap-list.c
@@ -92,29 +92,30 @@ int capability_set_to_string(uint64_t set, char **ret) {
return 0;
}
-int capability_set_from_string(const char *s, uint64_t *set) {
+int capability_set_from_string(const char *s, uint64_t *ret) {
uint64_t val = 0;
-
- assert(set);
+ bool good = true;
for (const char *p = s;;) {
_cleanup_free_ char *word = NULL;
int r;
- r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE);
- if (r == -ENOMEM)
+ r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE|EXTRACT_RELAX);
+ if (r < 0)
return r;
- if (r <= 0)
+ if (r == 0)
break;
r = capability_from_name(word);
- if (r < 0)
- continue;
-
- val |= ((uint64_t) UINT64_C(1)) << (uint64_t) r;
+ if (r < 0) {
+ log_debug_errno(r, "Failed to parse capability '%s', ignoring: %m", word);
+ good = false;
+ } else
+ val |= UINT64_C(1) << r;
}
- *set = val;
+ if (ret)
+ *ret = val;
- return 0;
+ return good;
}