chiark / gitweb /
unit: don't serialize job state, only unit state across switch-root
[elogind.git] / src / core / unit.c
index ed519b3bd561f265ec7fe4f6d1af6034b692380c..ae6f69183d284055ec624391c9670a80a1a8a3e8 100644 (file)
@@ -2232,7 +2232,7 @@ static char *specifier_user_name(char specifier, void *data, void *userdata) {
 
         /* fish username from passwd */
         username = s->exec_context.user;
-        r = get_user_creds(&username, NULL, NULL, NULL);
+        r = get_user_creds(&username, NULL, NULL, NULL, NULL);
         if (r < 0)
                 return NULL;
 
@@ -2256,13 +2256,37 @@ static char *specifier_user_home(char specifier, void *data, void *userdata) {
         }
 
         username = s->exec_context.user;
-        r = get_user_creds(&username, NULL, NULL, &home);
+        r = get_user_creds(&username, NULL, NULL, &home, NULL);
         if (r < 0)
                return NULL;
 
         return strdup(home);
 }
 
+static char *specifier_user_shell(char specifier, void *data, void *userdata) {
+        Service *s = userdata;
+        int r;
+        const char *username, *shell;
+
+        /* return HOME if set, otherwise from passwd */
+        if (!s->exec_context.user) {
+                char *sh;
+
+                r = get_shell(&sh);
+                if (r < 0)
+                        return strdup("/bin/sh");
+
+                return sh;
+        }
+
+        username = s->exec_context.user;
+        r = get_user_creds(&username, NULL, NULL, NULL, &shell);
+        if (r < 0)
+                return strdup("/bin/sh");
+
+        return strdup(shell);
+}
+
 char *unit_name_printf(Unit *u, const char* format) {
 
         /*
@@ -2316,6 +2340,7 @@ char *unit_full_printf(Unit *u, const char *format) {
                 { 't', specifier_runtime,             NULL },
                 { 'u', specifier_user_name,           NULL },
                 { 'h', specifier_user_home,           NULL },
+                { 's', specifier_user_shell,          NULL },
                 { 0, NULL, NULL }
         };
 
@@ -2376,7 +2401,7 @@ bool unit_can_serialize(Unit *u) {
         return UNIT_VTABLE(u)->serialize && UNIT_VTABLE(u)->deserialize_item;
 }
 
-int unit_serialize(Unit *u, FILE *f, FDSet *fds) {
+int unit_serialize(Unit *u, FILE *f, FDSet *fds, bool serialize_jobs) {
         int r;
 
         assert(u);
@@ -2389,14 +2414,17 @@ int unit_serialize(Unit *u, FILE *f, FDSet *fds) {
         if ((r = UNIT_VTABLE(u)->serialize(u, f, fds)) < 0)
                 return r;
 
-        if (u->job) {
-                fprintf(f, "job\n");
-                job_serialize(u->job, f, fds);
-        }
 
-        if (u->nop_job) {
-                fprintf(f, "job\n");
-                job_serialize(u->nop_job, f, fds);
+        if (serialize_jobs) {
+                if (u->job) {
+                        fprintf(f, "job\n");
+                        job_serialize(u->job, f, fds);
+                }
+
+                if (u->nop_job) {
+                        fprintf(f, "job\n");
+                        job_serialize(u->nop_job, f, fds);
+                }
         }
 
         dual_timestamp_serialize(f, "inactive-exit-timestamp", &u->inactive_exit_timestamp);
@@ -2792,6 +2820,19 @@ int unit_add_mount_links(Unit *u) {
         return 0;
 }
 
+int unit_patch_working_directory(Unit *u, ExecContext *c) {
+        assert(u);
+        assert(c);
+
+        if (u->manager->running_as != MANAGER_USER)
+                return 0;
+
+        if (c->working_directory)
+                return 0;
+
+        return get_home_dir(&c->working_directory);
+}
+
 static const char* const unit_active_state_table[_UNIT_ACTIVE_STATE_MAX] = {
         [UNIT_ACTIVE] = "active",
         [UNIT_RELOADING] = "reloading",