chiark / gitweb /
unit: set default working directory to the user's home directory when running in...
authorLennart Poettering <lennart@poettering.net>
Mon, 16 Jul 2012 10:44:42 +0000 (12:44 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 16 Jul 2012 10:44:42 +0000 (12:44 +0200)
man/systemd.exec.xml
src/core/mount.c
src/core/service.c
src/core/socket.c
src/core/swap.c
src/core/unit.c
src/core/unit.h

index eff75d0..2911786 100644 (file)
 
                                 <listitem><para>Takes an absolute
                                 directory path. Sets the working
-                                directory for executed
-                                processes.</para></listitem>
+                                directory for executed processes. If
+                                not set defaults to the root directory
+                                when systemd is running as a system
+                                instance and the respective user's
+                                home directory if run as
+                                user.</para></listitem>
                         </varlistentry>
 
                         <varlistentry>
index 15d5f21..a88b255 100644 (file)
@@ -631,6 +631,10 @@ static int mount_load(Unit *u) {
                 r = mount_add_extras(m);
                 if (r < 0)
                         return r;
+
+                r = unit_patch_working_directory(UNIT(m), &m->exec_context);
+                if (r < 0)
+                        return r;
         }
 
         return mount_verify(m);
index 0a66588..7a7e25f 100644 (file)
@@ -1282,6 +1282,10 @@ static int service_load(Unit *u) {
                 if (UNIT(s)->default_dependencies)
                         if ((r = service_add_default_dependencies(s)) < 0)
                                 return r;
+
+                r = unit_patch_working_directory(UNIT(s), &s->exec_context);
+                if (r < 0)
+                        return r;
         }
 
         return service_verify(s);
index 3613e84..8153a8e 100644 (file)
@@ -372,6 +372,10 @@ static int socket_load(Unit *u) {
                 if (UNIT(s)->default_dependencies)
                         if ((r = socket_add_default_dependencies(s)) < 0)
                                 return r;
+
+                r = unit_patch_working_directory(UNIT(s), &s->exec_context);
+                if (r < 0)
+                        return r;
         }
 
         return socket_verify(s);
index aeb8bda..ed61ba3 100644 (file)
@@ -294,6 +294,10 @@ static int swap_load(Unit *u) {
                 if (UNIT(s)->default_dependencies)
                         if ((r = swap_add_default_dependencies(s)) < 0)
                                 return r;
+
+                r = unit_patch_working_directory(UNIT(s), &s->exec_context);
+                if (r < 0)
+                        return r;
         }
 
         return swap_verify(s);
index 673af13..7994f70 100644 (file)
@@ -2817,6 +2817,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",
index 45849a4..2483e4e 100644 (file)
@@ -537,6 +537,8 @@ void unit_ref_unset(UnitRef *ref);
 int unit_add_one_mount_link(Unit *u, Mount *m);
 int unit_add_mount_links(Unit *u);
 
+int unit_patch_working_directory(Unit *u, ExecContext *c);
+
 const char *unit_active_state_to_string(UnitActiveState i);
 UnitActiveState unit_active_state_from_string(const char *s);