chiark / gitweb /
unit: add %U for uids in units
authorDaniel Wallace <danielwallace@gtmanfred.com>
Fri, 7 Dec 2012 05:01:15 +0000 (00:01 -0500)
committerLennart Poettering <lennart@poettering.net>
Wed, 19 Dec 2012 16:36:24 +0000 (17:36 +0100)
man/systemd.unit.xml
src/core/unit-printf.c

index 35644d38a666c68dd1b7c0d37aeabbca1a624e33..bf91b4eb137eb1a03297f9311d84f01729065b84 100644 (file)
                         <entry>User name</entry>
                         <entry>This is the name of the configured user of the unit, or (if none is set) the user running the systemd instance.</entry>
                       </row>
+                      <row>
+                        <entry><literal>%U</literal></entry>
+                        <entry>User uid</entry>
+                        <entry>This is the uid of the configured user of the unit, or (if none is set) the user running the systemd instance.</entry>
+                      </row>
                       <row>
                         <entry><literal>%h</literal></entry>
                         <entry>User home directory</entry>
index a8eb60a3d4264de1f6b464f6ea5db2bda68fa468..a58c96c23877ea98642a700096ec8a9f0d4e242f 100644 (file)
@@ -123,6 +123,8 @@ static char *specifier_user_name(char specifier, void *data, void *userdata) {
         ExecContext *c;
         int r;
         const char *username;
+        uid_t uid;
+        char *printed = NULL;
 
         assert(u);
 
@@ -134,11 +136,21 @@ static char *specifier_user_name(char specifier, void *data, void *userdata) {
 
         /* fish username from passwd */
         username = c->user;
-        r = get_user_creds(&username, NULL, NULL, NULL, NULL);
+        r = get_user_creds(&username, &uid, NULL, NULL, NULL);
         if (r < 0)
                 return NULL;
 
-        return strdup(username);
+        switch (specifier) {
+                case 'U':
+                        if (asprintf(&printed, "%d", uid) < 0)
+                                return NULL;
+                        break;
+                case 'u':
+                        printed = strdup(username);
+                        break;
+        }
+
+        return printed;
 }
 
 static char *specifier_user_home(char specifier, void *data, void *userdata) {
@@ -292,6 +304,7 @@ char *unit_full_printf(Unit *u, const char *format) {
                 { 'r', specifier_cgroup_root,         NULL },
                 { 'R', specifier_cgroup_root,         NULL },
                 { 't', specifier_runtime,             NULL },
+                { 'U', specifier_user_name,           NULL },
                 { 'u', specifier_user_name,           NULL },
                 { 'h', specifier_user_home,           NULL },
                 { 's', specifier_user_shell,          NULL },