#define parse_env_file(f, fname, ...) parse_env_file_sentinel(f, fname, __VA_ARGS__, NULL)
int parse_env_file_fd_sentinel(int fd, const char *fname, ...) _sentinel_;
#define parse_env_file_fd(fd, fname, ...) parse_env_file_fd_sentinel(fd, fname, __VA_ARGS__, NULL)
+
+int parse_env_datav(const char *data, size_t size, const char *fname, va_list ap);
+int parse_env_data_sentinel(const char *data, size_t size, const char *fname, ...) _sentinel_;
+#define parse_env_data(text, size, fname, ...) parse_env_data_sentinel(text, size, fname, __VA_ARGS__, NULL)
+
int load_env_file(FILE *f, const char *fname, char ***ret);
int load_env_file_pairs(FILE *f, const char *fname, char ***ret);
int load_env_file_pairs_fd(int fd, const char *fname, char ***ret);
#include "bus-wait-for-jobs.h"
#include "chase.h"
#include "env-file.h"
-#include "fd-util.h"
-#include "fileio.h"
#include "format-table.h"
#include "fs-util.h"
#include "install.h"
nl = true;
} else {
_cleanup_free_ char *pretty_portable = NULL, *pretty_os = NULL;
- _cleanup_fclose_ FILE *f = NULL;
- f = fmemopen_unlocked((void*) data, sz, "r");
- if (!f)
- return log_error_errno(errno, "Failed to open /etc/os-release buffer: %m");
-
- r = parse_env_file(f, "/etc/os-release",
- "PORTABLE_PRETTY_NAME", &pretty_portable,
- "PRETTY_NAME", &pretty_os);
+ r = parse_env_data(
+ data, sz,
+ "/etc/os-release",
+ "PORTABLE_PRETTY_NAME", &pretty_portable,
+ "PRETTY_NAME", &pretty_os);
if (r < 0)
return log_error_errno(r, "Failed to parse /etc/os-release: %m");
*confext_version_id = NULL, *confext_scope = NULL,
*confext_image_id = NULL, *confext_image_version = NULL,
*confext_build_id = NULL;
- _cleanup_fclose_ FILE *f = NULL;
-
- f = fmemopen_unlocked((void*) data, sz, "r");
- if (!f)
- return log_error_errno(errno, "Failed to open extension-release buffer: %m");
-
- r = parse_env_file(f, name,
- "SYSEXT_ID", &sysext_id,
- "SYSEXT_VERSION_ID", &sysext_version_id,
- "SYSEXT_BUILD_ID", &sysext_build_id,
- "SYSEXT_IMAGE_ID", &sysext_image_id,
- "SYSEXT_IMAGE_VERSION", &sysext_image_version,
- "SYSEXT_SCOPE", &sysext_scope,
- "SYSEXT_LEVEL", &sysext_level,
- "SYSEXT_PRETTY_NAME", &sysext_pretty_os,
- "CONFEXT_ID", &confext_id,
- "CONFEXT_VERSION_ID", &confext_version_id,
- "CONFEXT_BUILD_ID", &confext_build_id,
- "CONFEXT_IMAGE_ID", &confext_image_id,
- "CONFEXT_IMAGE_VERSION", &confext_image_version,
- "CONFEXT_SCOPE", &confext_scope,
- "CONFEXT_LEVEL", &confext_level,
- "CONFEXT_PRETTY_NAME", &confext_pretty_os,
- "ID", &id,
- "VERSION_ID", &version_id,
- "PORTABLE_PRETTY_NAME", &pretty_portable,
- "PORTABLE_PREFIXES", &portable_prefixes);
+
+ r = parse_env_data(
+ data, sz,
+ name,
+ "SYSEXT_ID", &sysext_id,
+ "SYSEXT_VERSION_ID", &sysext_version_id,
+ "SYSEXT_BUILD_ID", &sysext_build_id,
+ "SYSEXT_IMAGE_ID", &sysext_image_id,
+ "SYSEXT_IMAGE_VERSION", &sysext_image_version,
+ "SYSEXT_SCOPE", &sysext_scope,
+ "SYSEXT_LEVEL", &sysext_level,
+ "SYSEXT_PRETTY_NAME", &sysext_pretty_os,
+ "CONFEXT_ID", &confext_id,
+ "CONFEXT_VERSION_ID", &confext_version_id,
+ "CONFEXT_BUILD_ID", &confext_build_id,
+ "CONFEXT_IMAGE_ID", &confext_image_id,
+ "CONFEXT_IMAGE_VERSION", &confext_image_version,
+ "CONFEXT_SCOPE", &confext_scope,
+ "CONFEXT_LEVEL", &confext_level,
+ "CONFEXT_PRETTY_NAME", &confext_pretty_os,
+ "ID", &id,
+ "VERSION_ID", &version_id,
+ "PORTABLE_PRETTY_NAME", &pretty_portable,
+ "PORTABLE_PREFIXES", &portable_prefixes);
if (r < 0)
return log_error_errno(r, "Failed to parse extension release from '%s': %m", name);
_cleanup_free_ char *fname = NULL, *os_pretty_name = NULL, *os_image_id = NULL, *os_name = NULL, *os_id = NULL,
*os_image_version = NULL, *os_version = NULL, *os_version_id = NULL, *os_build_id = NULL;
const char *k, *good_name, *good_version, *good_sort_key;
- _cleanup_fclose_ FILE *f = NULL;
int r;
assert(root);
if (!k)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Path is not below root: %s", path);
- f = fmemopen_unlocked((void*) osrelease_text, strlen(osrelease_text), "r");
- if (!f)
- return log_oom();
-
- r = parse_env_file(f, "os-release",
+ r = parse_env_data(osrelease_text, /* size= */ SIZE_MAX,
+ ".osrel",
"PRETTY_NAME", &os_pretty_name,
"IMAGE_ID", &os_image_id,
"NAME", &os_name,
_cleanup_free_ char *profile_id = NULL, *profile_title = NULL;
if (profile_text) {
- fclose(f);
-
- f = fmemopen_unlocked((void*) profile_text, strlen(profile_text), "r");
- if (!f)
- return log_oom();
-
- r = parse_env_file(
- f, "profile",
+ r = parse_env_data(
+ profile_text, /* size= */ SIZE_MAX,
+ ".profile",
"ID", &profile_id,
"TITLE", &profile_title);
if (r < 0)