parse-util: Add parse_capability_set()

Let's extract common capability parsing code into a generic function
parse_capability_set() with a comprehensive set of unit tests.

We also replace usages of UINT64_MAX with CAP_MASK_UNSET where
applicable and replace the default value of CapabilityBoundingSet
with CAP_MASK_ALL which more clearly identifies that it is initialized
to all capabilities.

AI (copilot) was used to extract the generic function and write the
unit tests, with manual review and fixing afterwards to make sure
everything was correct.
This commit is contained in:
Daan De Meyer
2025-11-02 04:47:21 +09:00
committed by Yu Watanabe
parent 1a3b3c57c6
commit 10e82fde7b
12 changed files with 197 additions and 67 deletions
+1 -1
View File
@@ -324,7 +324,7 @@ static int oci_capabilities(const char *name, sd_json_variant *v, sd_json_dispat
if (r < 0)
return r;
if (s->full_capabilities.bounding != UINT64_MAX) {
if (s->full_capabilities.bounding != CAP_MASK_UNSET) {
s->capability = s->full_capabilities.bounding;
s->drop_capability = ~s->full_capabilities.bounding;
}
+1 -1
View File
@@ -1694,7 +1694,7 @@ static int verify_arguments(void) {
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Cannot use --port= without private networking.");
if (arg_caps_ambient) {
if (arg_caps_ambient == UINT64_MAX)
if (arg_caps_ambient == CAP_MASK_UNSET)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "AmbientCapability= does not support the value all.");
if ((arg_caps_ambient & arg_caps_retain) != arg_caps_ambient)