summaryrefslogtreecommitdiff
path: root/src/shared/specifier.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2020-11-20 15:15:24 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2020-11-25 14:13:02 +0900
commit2824aa0796abbba718505bd5d4132dc6a6e179e8 (patch)
tree170f362b239c2011327d00f41621e1e9d0d40ec9 /src/shared/specifier.h
parentff84fadbf1466c5cd1da50394aba6ad3d3c3614c (diff)
downloadsystemd-2824aa0796abbba718505bd5d4132dc6a6e179e8.tar.gz
specifiers: introduce common macros for generating specifier tables
In many cases the tables are largely the same, hence define a common set of macros to generate the common parts. This adds in a couple of missing specifiers here and there, so is more thant just refactoring: it actually fixes accidental omissions. Note that some entries that look like they could be unified under these macros can't really be unified, since they are slightly different. For example in the DNSSD service logic we want to use the DNSSD hostname for %H rather than the unmodified kernel one.
Diffstat (limited to 'src/shared/specifier.h')
-rw-r--r--src/shared/specifier.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/shared/specifier.h b/src/shared/specifier.h
index f3c038a1f1..e01ee67db3 100644
--- a/src/shared/specifier.h
+++ b/src/shared/specifier.h
@@ -36,6 +36,30 @@ int specifier_user_shell(char specifier, const void *data, const void *userdata,
int specifier_tmp_dir(char specifier, const void *data, const void *userdata, char **ret);
int specifier_var_tmp_dir(char specifier, const void *data, const void *userdata, char **ret);
+/* Typically, in places where one of the above specifier is to be resolved the other similar ones are to be
+ * resolved, too. Hence let's define common macros for the relevant array entries. */
+#define COMMON_SYSTEM_SPECIFIERS \
+ { 'm', specifier_machine_id, NULL }, \
+ { 'b', specifier_boot_id, NULL }, \
+ { 'H', specifier_host_name, NULL }, \
+ { 'l', specifier_short_host_name, NULL }, \
+ { 'v', specifier_kernel_release, NULL }, \
+ { 'a', specifier_architecture, NULL }, \
+ { 'o', specifier_os_id, NULL }, \
+ { 'w', specifier_os_version_id, NULL }, \
+ { 'B', specifier_os_build_id, NULL }, \
+ { 'W', specifier_os_variant_id, NULL }
+
+#define COMMON_CREDS_SPECIFIERS \
+ { 'g', specifier_group_name, NULL }, \
+ { 'G', specifier_group_id, NULL }, \
+ { 'U', specifier_user_id, NULL }, \
+ { 'u', specifier_user_name, NULL }
+
+#define COMMON_TMP_SPECIFIERS \
+ { 'T', specifier_tmp_dir, NULL }, \
+ { 'V', specifier_var_tmp_dir, NULL }
+
static inline char* specifier_escape(const char *string) {
return strreplace(string, "%", "%%");
}