X Tutup
Skip to content

Commit 2caed04

Browse files
committed
sysusers: add a generic specifier table for common cases
This moves the definition of the specifier table consisting only of system and /tmp specifiers into generic code so that we can share it. This patch only adds one user of it for now. Follow-up patches will add more.
1 parent 3dfeb04 commit 2caed04

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/shared/specifier.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,9 @@ int specifier_escape_strv(char **l, char ***ret) {
364364

365365
return 0;
366366
}
367+
368+
const Specifier system_and_tmp_specifier_table[] = {
369+
COMMON_SYSTEM_SPECIFIERS,
370+
COMMON_TMP_SPECIFIERS,
371+
{}
372+
};

src/shared/specifier.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ int specifier_var_tmp_dir(char specifier, const void *data, const void *userdata
8080
{ 'w', specifier_os_version_id, NULL }, \
8181
{ 'W', specifier_os_variant_id, NULL }
8282

83-
8483
#define COMMON_CREDS_SPECIFIERS \
8584
{ 'g', specifier_group_name, NULL }, \
8685
{ 'G', specifier_group_id, NULL }, \
@@ -96,3 +95,6 @@ static inline char* specifier_escape(const char *string) {
9695
}
9796

9897
int specifier_escape_strv(char **l, char ***ret);
98+
99+
/* A generic specifier table consisting of COMMON_SYSTEM_SPECIFIERS and COMMON_TMP_SPECIFIERS */
100+
extern const Specifier system_and_tmp_specifier_table[];

src/sysusers/sysusers.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,12 +1466,6 @@ static bool item_equal(Item *a, Item *b) {
14661466

14671467
static int parse_line(const char *fname, unsigned line, const char *buffer) {
14681468

1469-
static const Specifier specifier_table[] = {
1470-
COMMON_SYSTEM_SPECIFIERS,
1471-
COMMON_TMP_SPECIFIERS,
1472-
{}
1473-
};
1474-
14751469
_cleanup_free_ char *action = NULL,
14761470
*name = NULL, *resolved_name = NULL,
14771471
*id = NULL, *resolved_id = NULL,
@@ -1515,7 +1509,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
15151509
name = mfree(name);
15161510

15171511
if (name) {
1518-
r = specifier_printf(name, NAME_MAX, specifier_table, NULL, &resolved_name);
1512+
r = specifier_printf(name, NAME_MAX, system_and_tmp_specifier_table, NULL, &resolved_name);
15191513
if (r < 0)
15201514
return log_error_errno(r, "[%s:%u] Failed to replace specifiers in '%s': %m", fname, line, name);
15211515

@@ -1530,7 +1524,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
15301524
id = mfree(id);
15311525

15321526
if (id) {
1533-
r = specifier_printf(id, PATH_MAX-1, specifier_table, NULL, &resolved_id);
1527+
r = specifier_printf(id, PATH_MAX-1, system_and_tmp_specifier_table, NULL, &resolved_id);
15341528
if (r < 0)
15351529
return log_error_errno(r, "[%s:%u] Failed to replace specifiers in '%s': %m",
15361530
fname, line, name);
@@ -1541,7 +1535,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
15411535
description = mfree(description);
15421536

15431537
if (description) {
1544-
r = specifier_printf(description, LONG_LINE_MAX, specifier_table, NULL, &resolved_description);
1538+
r = specifier_printf(description, LONG_LINE_MAX, system_and_tmp_specifier_table, NULL, &resolved_description);
15451539
if (r < 0)
15461540
return log_error_errno(r, "[%s:%u] Failed to replace specifiers in '%s': %m",
15471541
fname, line, description);
@@ -1557,7 +1551,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
15571551
home = mfree(home);
15581552

15591553
if (home) {
1560-
r = specifier_printf(home, PATH_MAX-1, specifier_table, NULL, &resolved_home);
1554+
r = specifier_printf(home, PATH_MAX-1, system_and_tmp_specifier_table, NULL, &resolved_home);
15611555
if (r < 0)
15621556
return log_error_errno(r, "[%s:%u] Failed to replace specifiers in '%s': %m",
15631557
fname, line, home);
@@ -1573,7 +1567,7 @@ static int parse_line(const char *fname, unsigned line, const char *buffer) {
15731567
shell = mfree(shell);
15741568

15751569
if (shell) {
1576-
r = specifier_printf(shell, PATH_MAX-1, specifier_table, NULL, &resolved_shell);
1570+
r = specifier_printf(shell, PATH_MAX-1, system_and_tmp_specifier_table, NULL, &resolved_shell);
15771571
if (r < 0)
15781572
return log_error_errno(r, "[%s:%u] Failed to replace specifiers in '%s': %m",
15791573
fname, line, shell);

0 commit comments

Comments
 (0)
X Tutup