Merge pull request #27202 from yuwata/os-release-tiny-cleanups
os-util: tiny cleanups
This commit is contained in:
+11
-18
@@ -14,11 +14,21 @@
|
||||
#include "parse-util.h"
|
||||
#include "path-util.h"
|
||||
#include "stat-util.h"
|
||||
#include "string-table.h"
|
||||
#include "string-util.h"
|
||||
#include "strv.h"
|
||||
#include "utf8.h"
|
||||
#include "xattr-util.h"
|
||||
|
||||
static const char* const image_class_table[_IMAGE_CLASS_MAX] = {
|
||||
[IMAGE_MACHINE] = "machine",
|
||||
[IMAGE_PORTABLE] = "portable",
|
||||
[IMAGE_SYSEXT] = "extension",
|
||||
[IMAGE_CONFEXT] = "confext",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(image_class, ImageClass);
|
||||
|
||||
/* Helper struct for naming simplicity and reusability */
|
||||
static const struct {
|
||||
const char *release_file_directory;
|
||||
@@ -55,8 +65,6 @@ int path_is_extension_tree(ImageClass image_class, const char *path, const char
|
||||
int r;
|
||||
|
||||
assert(path);
|
||||
assert(image_class >= 0);
|
||||
assert(image_class < _IMAGE_CLASS_MAX);
|
||||
|
||||
/* Does the path exist at all? If not, generate an error immediately. This is useful so that a missing root dir
|
||||
* always results in -ENOENT, and we can properly distinguish the case where the whole root doesn't exist from
|
||||
@@ -295,24 +303,12 @@ int _parse_os_release(const char *root, ...) {
|
||||
int r;
|
||||
|
||||
va_start(ap, root);
|
||||
r = parse_release_internal(root, -1, /* relax_extension_release_check= */ false, NULL, ap);
|
||||
r = parse_release_internal(root, _IMAGE_CLASS_INVALID, /* relax_extension_release_check= */ false, NULL, ap);
|
||||
va_end(ap);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int load_os_release_pairs(const char *root, char ***ret) {
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
_cleanup_free_ char *p = NULL;
|
||||
int r;
|
||||
|
||||
r = fopen_os_release(root, &p, &f);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return load_env_file_pairs(f, p, ret);
|
||||
}
|
||||
|
||||
int load_os_release_pairs_with_prefix(const char *root, const char *prefix, char ***ret) {
|
||||
_cleanup_strv_free_ char **os_release_pairs = NULL, **os_release_pairs_prefixed = NULL;
|
||||
int r;
|
||||
@@ -347,9 +343,6 @@ int load_extension_release_pairs(const char *root, ImageClass image_class, const
|
||||
_cleanup_free_ char *p = NULL;
|
||||
int r;
|
||||
|
||||
assert(image_class >= 0);
|
||||
assert(image_class < _IMAGE_CLASS_MAX);
|
||||
|
||||
r = fopen_extension_release(root, image_class, extension, relax_extension_release_check, &p, &f);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
+7
-4
@@ -5,6 +5,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "time-util.h"
|
||||
|
||||
typedef enum ImageClass {
|
||||
IMAGE_MACHINE,
|
||||
IMAGE_PORTABLE,
|
||||
@@ -24,17 +25,17 @@ bool image_name_is_valid(const char *s) _pure_;
|
||||
|
||||
int path_is_extension_tree(ImageClass image_class, const char *path, const char *extension, bool relax_extension_release_check);
|
||||
static inline int path_is_os_tree(const char *path) {
|
||||
return path_is_extension_tree(IMAGE_SYSEXT, path, NULL, false);
|
||||
return path_is_extension_tree(_IMAGE_CLASS_INVALID, path, NULL, false);
|
||||
}
|
||||
|
||||
int open_extension_release(const char *root, ImageClass image_class, const char *extension, bool relax_extension_release_check, char **ret_path, int *ret_fd);
|
||||
static inline int open_os_release(const char *root, char **ret_path, int *ret_fd) {
|
||||
return open_extension_release(root, IMAGE_SYSEXT, NULL, false, ret_path, ret_fd);
|
||||
return open_extension_release(root, _IMAGE_CLASS_INVALID, NULL, false, ret_path, ret_fd);
|
||||
}
|
||||
|
||||
int fopen_extension_release(const char *root, ImageClass image_class, const char *extension, bool relax_extension_release_check, char **ret_path, FILE **ret_file);
|
||||
static inline int fopen_os_release(const char *root, char **ret_path, FILE **ret_file) {
|
||||
return fopen_extension_release(root, IMAGE_SYSEXT, NULL, false, ret_path, ret_file);
|
||||
return fopen_extension_release(root, _IMAGE_CLASS_INVALID, NULL, false, ret_path, ret_file);
|
||||
}
|
||||
|
||||
int _parse_extension_release(const char *root, ImageClass image_class, bool relax_extension_release_check, const char *extension, ...) _sentinel_;
|
||||
@@ -43,7 +44,9 @@ int _parse_os_release(const char *root, ...) _sentinel_;
|
||||
#define parse_os_release(root, ...) _parse_os_release(root, __VA_ARGS__, NULL)
|
||||
|
||||
int load_extension_release_pairs(const char *root, ImageClass image_class, const char *extension, bool relax_extension_release_check, char ***ret);
|
||||
int load_os_release_pairs(const char *root, char ***ret);
|
||||
static inline int load_os_release_pairs(const char *root, char ***ret) {
|
||||
return load_extension_release_pairs(root, _IMAGE_CLASS_INVALID, NULL, false, ret);
|
||||
}
|
||||
int load_os_release_pairs_with_prefix(const char *root, const char *prefix, char ***ret);
|
||||
|
||||
int os_release_support_ended(const char *support_end, bool quiet, usec_t *ret_eol);
|
||||
|
||||
@@ -1326,12 +1326,3 @@ static const char* const image_type_table[_IMAGE_TYPE_MAX] = {
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(image_type, ImageType);
|
||||
|
||||
static const char* const image_class_table[_IMAGE_CLASS_MAX] = {
|
||||
[IMAGE_MACHINE] = "machine",
|
||||
[IMAGE_PORTABLE] = "portable",
|
||||
[IMAGE_SYSEXT] = "extension",
|
||||
[IMAGE_CONFEXT] = "confext"
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(image_class, ImageClass);
|
||||
|
||||
Reference in New Issue
Block a user