summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
authorDavide Cavalca <davide125@tiscali.it>2018-10-13 10:26:48 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-10-13 10:26:48 +0200
commitb75f0c69b3c80ab1d80f907de96f1c1a444c171a (patch)
treec2320b5e58c405c571b9ddd565d52d134501cc6c /src/shared
parentMerge pull request #10366 from poettering/in-set-fixes (diff)
downloadsystemd-b75f0c69b3c80ab1d80f907de96f1c1a444c171a.tar.xz
systemd-b75f0c69b3c80ab1d80f907de96f1c1a444c171a.zip
shared: add %g, %G specifiers for group / gid (#10368)
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/install-printf.c2
-rw-r--r--src/shared/specifier.c18
-rw-r--r--src/shared/specifier.h2
3 files changed, 22 insertions, 0 deletions
diff --git a/src/shared/install-printf.c b/src/shared/install-printf.c
index 078d5734be..b87d6b9d55 100644
--- a/src/shared/install-printf.c
+++ b/src/shared/install-printf.c
@@ -129,6 +129,8 @@ int install_full_printf(UnitFileInstallInfo *i, const char *format, char **ret)
{ '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 },
diff --git a/src/shared/specifier.c b/src/shared/specifier.c
index b5f22c8d1e..78dda05b48 100644
--- a/src/shared/specifier.c
+++ b/src/shared/specifier.c
@@ -175,6 +175,24 @@ int specifier_kernel_release(char specifier, void *data, void *userdata, char **
return 0;
}
+int specifier_group_name(char specifier, void *data, void *userdata, char **ret) {
+ char *t;
+
+ t = gid_to_name(getgid());
+ if (!t)
+ return -ENOMEM;
+
+ *ret = t;
+ return 0;
+}
+
+int specifier_group_id(char specifier, void *data, void *userdata, char **ret) {
+ if (asprintf(ret, UID_FMT, getgid()) < 0)
+ return -ENOMEM;
+
+ return 0;
+}
+
int specifier_user_name(char specifier, void *data, void *userdata, char **ret) {
char *t;
diff --git a/src/shared/specifier.h b/src/shared/specifier.h
index e1895129d7..722200b998 100644
--- a/src/shared/specifier.h
+++ b/src/shared/specifier.h
@@ -20,6 +20,8 @@ int specifier_boot_id(char specifier, void *data, void *userdata, char **ret);
int specifier_host_name(char specifier, void *data, void *userdata, char **ret);
int specifier_kernel_release(char specifier, void *data, void *userdata, char **ret);
+int specifier_group_name(char specifier, void *data, void *userdata, char **ret);
+int specifier_group_id(char specifier, void *data, void *userdata, char **ret);
int specifier_user_name(char specifier, void *data, void *userdata, char **ret);
int specifier_user_id(char specifier, void *data, void *userdata, char **ret);
int specifier_user_home(char specifier, void *data, void *userdata, char **ret);