<div dir="ltr"><div><div><div>On the one hand, I understand your point. On the other hand, there are three other ways of doing this:<br><br>    <span class="gmail-im">systemd-run -t --setenv=XDG_RUNTIME_DIR=/run/<wbr>user/<uid> --uid=<uid> systemctl --user ...<br>    </span><span class="gmail-im">su -l <username> -c "XDG_RUNTIME_DIR=/run/user/<<wbr>uid> systemctl --user"<br>    </span><span class="gmail-im"><span class="gmail-im">machinectl --uid=<uid> shell /bin/systemctl --user ...</span></span><span class="gmail-im"></span><br><br></div>(I'm assuming the last way actually works. Does it?)<br><br></div>So I thought that my suggestion was an even cleaner way to accomplish the same thing. I get that you don't want priv code to depend on unpriv code but systemctl is a command line tool. It's up to the user if they want to run it that way.<br></div><div><br></div><div><br><br><div><br><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 24, 2017 at 5:05 AM, Lennart Poettering <span dir="ltr"><<a href="mailto:lennart@poettering.net" target="_blank">lennart@poettering.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Do, 23.11.17 22:56, Jeff Solomon (<a href="mailto:jsolomon8080@gmail.com">jsolomon8080@gmail.com</a>) wrote:<br>
<br>
> Hi,<br>
><br>
> More questions about the systemd user service.<br>
><br>
> Inside a script running as root, I want to control another user's service.<br>
><br>
> I have found two ways to do this:<br>
><br>
>     systemd-run -t --setenv=XDG_RUNTIME_DIR=/run/<wbr>user/<uid> --uid=<uid><br>
> systemctl --user ...<br>
><br>
> or:<br>
><br>
>     su -l <username> -c "XDG_RUNTIME_DIR=/run/user/<<wbr>uid> systemctl --user<br>
> ..."<br>
><br>
> Both work.<br>
><br>
> If there a better way to do this?<br>
><br>
> My distros aren't recent enough to include "machinectl shell" but is that<br>
> the recommended way now?<br>
><br>
>     machinectl --uid=<uid> shell /bin/systemctl --user ...<br>
><br>
> Perhaps there is not enough demand to justify it, but I would love if the<br>
> systemctl command itself had a way to specify that it should communicate<br>
> with a different user's service rather than system service or the calling<br>
> user's service. Something like:<br>
><br>
>     systemctl --uid=<uid> --user ..<br>
><br>
> would be awesome.<br>
<br>
</span>Hmm, sorry, but this is something we'll are unlikely to support in any<br>
special way. Making privileged code a client of unpriveled user code<br>
like this makes me feel very uncomfortable. Privileged code really<br>
should not transition and block on unprivileged user code likes<br>
this. Philosophically it has this feeling of being the wrong way<br>
round: the unpriv code should ask the priv code what it should do, it<br>
shouldn't be the priv code that asks the unpriv code, in any blocking<br>
way... I mean, the unpriv code can ultimately do whatever it wants,<br>
and priv code should not block on that for good. It's simply the wrong<br>
way round to design such a system, if you follow what i mean.<br>
<br>
Usually most usecase like that are better solved by making things<br>
asynchronous notifier based, and make the unpriv code just react to<br>
notifications, instead of synchronous call-ins...<br>
<span class="HOEnZb"><font color="#888888"><br>
Lennart<br>
<br>
--<br>
Lennart Poettering, Red Hat<br>
</font></span></blockquote></div><br></div>