diff options
-rw-r--r-- | src/core/unit-printf.c | 31 | ||||
-rw-r--r-- | src/partition/repart.c | 11 | ||||
-rw-r--r-- | src/shared/install-printf.c | 17 | ||||
-rw-r--r-- | src/shared/specifier.h | 24 | ||||
-rw-r--r-- | src/sysusers/sysusers.c | 14 | ||||
-rw-r--r-- | src/test/test-specifier.c | 21 | ||||
-rw-r--r-- | src/test/test-strv.c | 10 | ||||
-rw-r--r-- | src/tmpfiles/tmpfiles.c | 8 |
8 files changed, 43 insertions, 93 deletions
diff --git a/src/core/unit-printf.c b/src/core/unit-printf.c index 27f09b3491..ba3e6456b7 100644 --- a/src/core/unit-printf.c +++ b/src/core/unit-printf.c @@ -203,20 +203,9 @@ int unit_name_printf(const Unit *u, const char* format, char **ret) { { 'i', specifier_string, u->instance }, { 'j', specifier_last_component, NULL }, - { 'g', specifier_group_name, NULL }, - { 'G', specifier_group_id, NULL }, - { 'U', specifier_user_id, NULL }, - { 'u', specifier_user_name, NULL }, - - { 'm', specifier_machine_id, NULL }, - { 'b', specifier_boot_id, NULL }, - { 'H', specifier_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 }, + COMMON_CREDS_SPECIFIERS, + + COMMON_SYSTEM_SPECIFIERS, {} }; @@ -279,21 +268,13 @@ int unit_full_printf(const Unit *u, const char *format, char **ret) { { 'C', specifier_special_directory, UINT_TO_PTR(EXEC_DIRECTORY_CACHE) }, { 'L', specifier_special_directory, UINT_TO_PTR(EXEC_DIRECTORY_LOGS) }, { 'E', specifier_special_directory, UINT_TO_PTR(EXEC_DIRECTORY_CONFIGURATION) }, - { 'T', specifier_tmp_dir, NULL }, - { 'V', specifier_var_tmp_dir, NULL }, + COMMON_TMP_SPECIFIERS, - { 'g', specifier_group_name, NULL }, - { 'G', specifier_group_id, NULL }, - { 'U', specifier_user_id, NULL }, - { 'u', specifier_user_name, NULL }, + COMMON_CREDS_SPECIFIERS, { 'h', specifier_user_home, NULL }, { 's', specifier_user_shell, NULL }, - { 'm', specifier_machine_id, NULL }, - { 'H', specifier_host_name, NULL }, - { 'l', specifier_short_host_name, NULL }, - { 'b', specifier_boot_id, NULL }, - { 'v', specifier_kernel_release, NULL }, + COMMON_SYSTEM_SPECIFIERS, {} }; diff --git a/src/partition/repart.c b/src/partition/repart.c index 40e0d6895c..6db413ed5e 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -918,16 +918,7 @@ static int config_parse_type( } static const Specifier specifier_table[] = { - { '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 }, + COMMON_SYSTEM_SPECIFIERS, {} }; diff --git a/src/shared/install-printf.c b/src/shared/install-printf.c index af350a63a5..7f60359c78 100644 --- a/src/shared/install-printf.c +++ b/src/shared/install-printf.c @@ -127,20 +127,9 @@ int install_full_printf(const UnitFileInstallInfo *i, const char *format, char * { 'i', specifier_instance, NULL }, { 'j', specifier_last_component, NULL }, - { 'g', specifier_group_name, NULL }, - { 'G', specifier_group_id, NULL }, - { 'U', specifier_user_id, NULL }, - { 'u', specifier_user_name, NULL }, - - { 'm', specifier_machine_id, NULL }, - { 'b', specifier_boot_id, NULL }, - { 'H', specifier_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 }, + COMMON_CREDS_SPECIFIERS, + + COMMON_SYSTEM_SPECIFIERS, {} }; 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, "%", "%%"); } diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index 9a8838d5eb..6b0acd529e 100644 --- a/src/sysusers/sysusers.c +++ b/src/sysusers/sysusers.c @@ -1391,18 +1391,8 @@ static bool item_equal(Item *a, Item *b) { static int parse_line(const char *fname, unsigned line, const char *buffer) { static const Specifier specifier_table[] = { - { '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 }, - { 'T', specifier_tmp_dir, NULL }, - { 'V', specifier_var_tmp_dir, NULL }, + COMMON_SYSTEM_SPECIFIERS, + COMMON_TMP_SPECIFIERS, {} }; diff --git a/src/test/test-specifier.c b/src/test/test-specifier.c index b1e8a61021..2648c1c3f5 100644 --- a/src/test/test-specifier.c +++ b/src/test/test-specifier.c @@ -47,25 +47,12 @@ static void test_specifier_escape_strv(void) { /* Any specifier functions which don't need an argument. */ static const Specifier specifier_table[] = { - { '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 }, - - { 'g', specifier_group_name, NULL }, - { 'G', specifier_group_id, NULL }, - { 'U', specifier_user_id, NULL }, - { 'u', specifier_user_name, NULL }, + COMMON_SYSTEM_SPECIFIERS, + + COMMON_CREDS_SPECIFIERS, { 'h', specifier_user_home, NULL }, - { 'T', specifier_tmp_dir, NULL }, - { 'V', specifier_var_tmp_dir, NULL }, + COMMON_TMP_SPECIFIERS, {} }; diff --git a/src/test/test-strv.c b/src/test/test-strv.c index 0c46af05cc..6b5005f9fc 100644 --- a/src/test/test-strv.c +++ b/src/test/test-strv.c @@ -11,15 +11,7 @@ static void test_specifier_printf(void) { static const Specifier table[] = { { 'X', specifier_string, (char*) "AAAA" }, { 'Y', specifier_string, (char*) "BBBB" }, - { 'm', specifier_machine_id, NULL }, - { 'b', specifier_boot_id, NULL }, - { 'H', specifier_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 }, + COMMON_SYSTEM_SPECIFIERS, {} }; diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index eb63bc3807..684762c842 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -199,18 +199,14 @@ static const Specifier specifier_table[] = { { 'B', specifier_os_build_id, NULL }, { 'W', specifier_os_variant_id, NULL }, - { 'g', specifier_group_name, NULL }, - { 'G', specifier_group_id, NULL }, - { 'U', specifier_user_id, NULL }, - { 'u', specifier_user_name, NULL }, + COMMON_CREDS_SPECIFIERS, { 'h', specifier_user_home, NULL }, { 't', specifier_directory, UINT_TO_PTR(DIRECTORY_RUNTIME) }, { 'S', specifier_directory, UINT_TO_PTR(DIRECTORY_STATE) }, { 'C', specifier_directory, UINT_TO_PTR(DIRECTORY_CACHE) }, { 'L', specifier_directory, UINT_TO_PTR(DIRECTORY_LOGS) }, - { 'T', specifier_tmp_dir, NULL }, - { 'V', specifier_var_tmp_dir, NULL }, + COMMON_TMP_SPECIFIERS, {} }; |