summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaan De Meyer <daan.j.demeyer@gmail.com>2022-09-19 15:35:17 +0200
committerDaan De Meyer <daan.j.demeyer@gmail.com>2022-09-22 14:16:57 +0200
commit74235f6d085bd9a7bc5068287fb18dfa6dd39d49 (patch)
tree9d167ae5166ebd7ec77516a951aed8e37c3f9617
parentsystemd-run: refuse --working-directory option with --scope (diff)
downloadsystemd-74235f6d085bd9a7bc5068287fb18dfa6dd39d49.tar.xz
systemd-74235f6d085bd9a7bc5068287fb18dfa6dd39d49.zip
shared: Add specifier_id128() and specifier_uuid()
Diffstat (limited to '')
-rw-r--r--src/shared/specifier.c40
-rw-r--r--src/shared/specifier.h2
2 files changed, 28 insertions, 14 deletions
diff --git a/src/shared/specifier.c b/src/shared/specifier.c
index 0742fae39e..a49b16b736 100644
--- a/src/shared/specifier.c
+++ b/src/shared/specifier.c
@@ -151,9 +151,32 @@ int specifier_real_directory(char specifier, const void *data, const char *root,
return path_extract_directory(path, ret);
}
+int specifier_id128(char specifier, const void *data, const char *root, const void *userdata, char **ret) {
+ const sd_id128_t *id = ASSERT_PTR(data);
+ char *n;
+
+ n = new(char, SD_ID128_STRING_MAX);
+ if (!n)
+ return -ENOMEM;
+
+ *ret = sd_id128_to_string(*id, n);
+ return 0;
+}
+
+int specifier_uuid(char specifier, const void *data, const char *root, const void *userdata, char **ret) {
+ const sd_id128_t *id = ASSERT_PTR(data);
+ char *n;
+
+ n = new(char, SD_ID128_UUID_STRING_MAX);
+ if (!n)
+ return -ENOMEM;
+
+ *ret = sd_id128_to_uuid_string(*id, n);
+ return 0;
+}
+
int specifier_machine_id(char specifier, const void *data, const char *root, const void *userdata, char **ret) {
sd_id128_t id;
- char *n;
int r;
assert(ret);
@@ -172,17 +195,11 @@ int specifier_machine_id(char specifier, const void *data, const char *root, con
if (r < 0)
return r;
- n = new(char, SD_ID128_STRING_MAX);
- if (!n)
- return -ENOMEM;
-
- *ret = sd_id128_to_string(id, n);
- return 0;
+ return specifier_id128(specifier, &id, root, userdata, ret);
}
int specifier_boot_id(char specifier, const void *data, const char *root, const void *userdata, char **ret) {
sd_id128_t id;
- char *n;
int r;
assert(ret);
@@ -191,12 +208,7 @@ int specifier_boot_id(char specifier, const void *data, const char *root, const
if (r < 0)
return r;
- n = new(char, SD_ID128_STRING_MAX);
- if (!n)
- return -ENOMEM;
-
- *ret = sd_id128_to_string(id, n);
- return 0;
+ return specifier_id128(specifier, &id, root, userdata, ret);
}
int specifier_hostname(char specifier, const void *data, const char *root, const void *userdata, char **ret) {
diff --git a/src/shared/specifier.h b/src/shared/specifier.h
index abde3d9ad2..a245e546e0 100644
--- a/src/shared/specifier.h
+++ b/src/shared/specifier.h
@@ -16,6 +16,8 @@ int specifier_printf(const char *text, size_t max_length, const Specifier table[
int specifier_string(char specifier, const void *data, const char *root, const void *userdata, char **ret);
int specifier_real_path(char specifier, const void *data, const char *root, const void *userdata, char **ret);
int specifier_real_directory(char specifier, const void *data, const char *root, const void *userdata, char **ret);
+int specifier_id128(char specifier, const void *data, const char *root, const void *userdata, char **ret);
+int specifier_uuid(char specifier, const void *data, const char *root, const void *userdata, char **ret);
int specifier_machine_id(char specifier, const void *data, const char *root, const void *userdata, char **ret);
int specifier_boot_id(char specifier, const void *data, const char *root, const void *userdata, char **ret);