unit: set default working directory to the user's home directory when running in user mode
This commit is contained in:
parent
d05c5031ad
commit
e06c73cc91
|
@ -89,8 +89,12 @@
|
||||||
|
|
||||||
<listitem><para>Takes an absolute
|
<listitem><para>Takes an absolute
|
||||||
directory path. Sets the working
|
directory path. Sets the working
|
||||||
directory for executed
|
directory for executed processes. If
|
||||||
processes.</para></listitem>
|
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>
|
||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
|
|
|
@ -631,6 +631,10 @@ static int mount_load(Unit *u) {
|
||||||
r = mount_add_extras(m);
|
r = mount_add_extras(m);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
r = unit_patch_working_directory(UNIT(m), &m->exec_context);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
return mount_verify(m);
|
return mount_verify(m);
|
||||||
|
|
|
@ -1282,6 +1282,10 @@ static int service_load(Unit *u) {
|
||||||
if (UNIT(s)->default_dependencies)
|
if (UNIT(s)->default_dependencies)
|
||||||
if ((r = service_add_default_dependencies(s)) < 0)
|
if ((r = service_add_default_dependencies(s)) < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
r = unit_patch_working_directory(UNIT(s), &s->exec_context);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
return service_verify(s);
|
return service_verify(s);
|
||||||
|
|
|
@ -372,6 +372,10 @@ static int socket_load(Unit *u) {
|
||||||
if (UNIT(s)->default_dependencies)
|
if (UNIT(s)->default_dependencies)
|
||||||
if ((r = socket_add_default_dependencies(s)) < 0)
|
if ((r = socket_add_default_dependencies(s)) < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
r = unit_patch_working_directory(UNIT(s), &s->exec_context);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
return socket_verify(s);
|
return socket_verify(s);
|
||||||
|
|
|
@ -294,6 +294,10 @@ static int swap_load(Unit *u) {
|
||||||
if (UNIT(s)->default_dependencies)
|
if (UNIT(s)->default_dependencies)
|
||||||
if ((r = swap_add_default_dependencies(s)) < 0)
|
if ((r = swap_add_default_dependencies(s)) < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
r = unit_patch_working_directory(UNIT(s), &s->exec_context);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
return swap_verify(s);
|
return swap_verify(s);
|
||||||
|
|
|
@ -2817,6 +2817,19 @@ int unit_add_mount_links(Unit *u) {
|
||||||
return 0;
|
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] = {
|
static const char* const unit_active_state_table[_UNIT_ACTIVE_STATE_MAX] = {
|
||||||
[UNIT_ACTIVE] = "active",
|
[UNIT_ACTIVE] = "active",
|
||||||
[UNIT_RELOADING] = "reloading",
|
[UNIT_RELOADING] = "reloading",
|
||||||
|
|
|
@ -537,6 +537,8 @@ void unit_ref_unset(UnitRef *ref);
|
||||||
int unit_add_one_mount_link(Unit *u, Mount *m);
|
int unit_add_one_mount_link(Unit *u, Mount *m);
|
||||||
int unit_add_mount_links(Unit *u);
|
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);
|
const char *unit_active_state_to_string(UnitActiveState i);
|
||||||
UnitActiveState unit_active_state_from_string(const char *s);
|
UnitActiveState unit_active_state_from_string(const char *s);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue