diff options
author | Luca Boccassi <bluca@debian.org> | 2024-04-19 20:34:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-19 20:34:16 +0200 |
commit | 565f6130b2490160f82be1f6c2e5b9e7577ac291 (patch) | |
tree | 9cf2f4a5d0c09a8d40686c8efdf4aa9c17f3c0cf /src/shared | |
parent | Merge pull request #32251 from CodethinkLabs/vmspawn/docs_improvements (diff) | |
parent | portable: support vpick (diff) | |
download | systemd-565f6130b2490160f82be1f6c2e5b9e7577ac291.tar.xz systemd-565f6130b2490160f82be1f6c2e5b9e7577ac291.zip |
Merge pull request #32142 from bluca/portable_vpick
portable: support vpick
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/discover-image.c | 4 | ||||
-rw-r--r-- | src/shared/vpick.c | 38 | ||||
-rw-r--r-- | src/shared/vpick.h | 3 |
3 files changed, 28 insertions, 17 deletions
diff --git a/src/shared/discover-image.c b/src/shared/discover-image.c index b7a97f2b63..4e7a2049cf 100644 --- a/src/shared/discover-image.c +++ b/src/shared/discover-image.c @@ -639,7 +639,7 @@ int image_find(ImageClass class, .type_mask = endswith(suffix, ".raw") ? (UINT32_C(1) << DT_REG) | (UINT32_C(1) << DT_BLK) : (UINT32_C(1) << DT_DIR), .basename = name, .architecture = _ARCHITECTURE_INVALID, - .suffix = suffix, + .suffix = STRV_MAKE(suffix), }; _cleanup_(pick_result_done) PickResult result = PICK_RESULT_NULL; @@ -807,7 +807,7 @@ int image_discover( .type_mask = endswith(suffix, ".raw") ? (UINT32_C(1) << DT_REG) | (UINT32_C(1) << DT_BLK) : (UINT32_C(1) << DT_DIR), .basename = pretty, .architecture = _ARCHITECTURE_INVALID, - .suffix = suffix, + .suffix = STRV_MAKE(suffix), }; _cleanup_(pick_result_done) PickResult result = PICK_RESULT_NULL; diff --git a/src/shared/vpick.c b/src/shared/vpick.c index 1870fb97ef..41bd7301a0 100644 --- a/src/shared/vpick.c +++ b/src/shared/vpick.c @@ -85,8 +85,13 @@ static int format_fname( return -ENOMEM; } - if (filter->suffix && !strextend(&fn, filter->suffix)) - return -ENOMEM; + if (!strv_isempty(filter->suffix)) { + if (strv_length(filter->suffix) > 1) + return -ENOEXEC; + + if (!strextend(&fn, filter->suffix[0])) + return -ENOMEM; + } if (!filename_is_valid(fn)) return -EINVAL; @@ -352,8 +357,8 @@ static int make_choice( } else e = dname; - if (!isempty(filter->suffix)) { - char *sfx = endswith(e, filter->suffix); + if (!strv_isempty(filter->suffix)) { + char *sfx = endswith_strv(e, filter->suffix); if (!sfx) continue; @@ -493,7 +498,8 @@ int path_pick( PickResult *ret) { _cleanup_free_ char *filter_bname = NULL, *dir = NULL, *parent = NULL, *fname = NULL; - const char *filter_suffix, *enumeration_path; + char * const *filter_suffix_strv = NULL; + const char *filter_suffix = NULL, *enumeration_path; uint32_t filter_type_mask; int r; @@ -549,14 +555,12 @@ int path_pick( if (!filter_bname) return -ENOMEM; - if (filter->suffix) { - /* Chop off suffix, if specified */ - char *f = endswith(filter_bname, filter->suffix); - if (f) - *f = 0; - } + /* Chop off suffix, if specified */ + char *f = endswith_strv(filter_bname, filter->suffix); + if (f) + *f = 0; - filter_suffix = filter->suffix; + filter_suffix_strv = filter->suffix; filter_type_mask = filter->type_mask; enumeration_path = path; @@ -616,7 +620,7 @@ int path_pick( .basename = filter_bname, .version = filter->version, .architecture = filter->architecture, - .suffix = filter_suffix, + .suffix = filter_suffix_strv ?: STRV_MAKE(filter_suffix), }, flags, ret); @@ -685,10 +689,16 @@ int path_pick_update_warn( const PickFilter pick_filter_image_raw = { .type_mask = (UINT32_C(1) << DT_REG) | (UINT32_C(1) << DT_BLK), .architecture = _ARCHITECTURE_INVALID, - .suffix = ".raw", + .suffix = STRV_MAKE(".raw"), }; const PickFilter pick_filter_image_dir = { .type_mask = UINT32_C(1) << DT_DIR, .architecture = _ARCHITECTURE_INVALID, }; + +const PickFilter pick_filter_image_any = { + .type_mask = (UINT32_C(1) << DT_REG) | (UINT32_C(1) << DT_BLK) | (UINT32_C(1) << DT_DIR), + .architecture = _ARCHITECTURE_INVALID, + .suffix = STRV_MAKE(".raw", ""), +}; diff --git a/src/shared/vpick.h b/src/shared/vpick.h index 21ce668404..38251c84e8 100644 --- a/src/shared/vpick.h +++ b/src/shared/vpick.h @@ -16,7 +16,7 @@ typedef struct PickFilter { const char *basename; /* Can be overridden by search pattern */ const char *version; Architecture architecture; - const char *suffix; /* Can be overridden by search pattern */ + char * const *suffix; /* Can be overridden by search pattern */ } PickFilter; typedef struct PickResult { @@ -58,3 +58,4 @@ int path_pick_update_warn( extern const PickFilter pick_filter_image_raw; extern const PickFilter pick_filter_image_dir; +extern const PickFilter pick_filter_image_any; |