Bug 55163

Summary: Executing within home directory of the given user
Product: systemd Reporter: Dan T <rozelak>
Component: generalAssignee: systemd-bugs
Status: RESOLVED FIXED QA Contact: systemd-bugs
Severity: enhancement    
Priority: medium CC: j.witteveen, rektide, rozelak
Version: unspecified   
Hardware: All   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:

Description Dan T 2012-09-20 20:48:39 UTC
When setting User= option, the process is still started in / directory. This makes the configuration of daemons started under a non-root user (e,g, cruisecontrol) much harder, since relative paths cannot be used.

Although there a possibility to use WorkingDirectory= option to specify the home directory of the user (or to specify full absolute path in the config), it is not very convenient way - the home dir must be changed in several places, or the configuration may start to be difficult to read.

There are basically two possibilities of handling it:

1.
use home directory by default (instead of / currently used), if User= is set

2.
support, e.g. WorkingDirectory=~ special alias, which will be resolved by systemd and replaced by the home directory of the user set


Thank you for considering this
DT.
Comment 1 Lennart Poettering 2013-01-15 01:13:30 UTC
This is now supported with WorkingDirectory=%h
Comment 2 j.witteveen 2014-03-05 11:16:17 UTC
The resolution (WorkingDirectory=%h) is no longer supported.

Would it be possible to set the working directory to the user's home directory by default (in the absence of WorkingDirectory=) after forking?
Comment 3 David Strauss 2014-03-05 18:44:01 UTC
(In reply to comment #2)
> The resolution (WorkingDirectory=%h) is no longer supported.

Can you link to when (commit or mailing list message) this changed?
Comment 4 j.witteveen 2014-03-05 20:58:29 UTC
(In reply to comment #3)
> Can you link to when (commit or mailing list message) this changed?

http://cgit.freedesktop.org/systemd/systemd/commit/?id=2cfbd749af308bdbe56edcfed7f3eea0fc2b93d2


from NEWS:

CHANGES WITH 209:

        * %h, %s, %U specifier support is not available anymore when
          used in unit files for PID 1. This is because NSS calls are
          not safe from PID 1. They stay available for --user
          instances of systemd, and as special case for the root user.
Comment 5 j.witteveen 2014-05-26 09:13:15 UTC
One possible fix would be to change src/core/unit.c:unit_patch_contexts, replacing

if (u->manager->running_as == SYSTEMD_USER && !ec->working_directory) {

with something along the lines of

if (/* uid of process-to-run != 0 */ && !ec->working_directory) {

and also modify src/shared/util.c:get_home_dir, where we add the uid as a parameter.

Would this be acceptable? If so, I will try to come up with a patch.
Comment 6 Lennart Poettering 2016-02-01 17:58:47 UTC
This is now available again with the WorkingDirectory=~ syntax.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.