<listitem><para>Runs the service process under the UNIX user
and group. Also see <varname>User=</varname> and
<varname>Group=</varname> in
- <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
- option has no effect in conjunction with
- <option>--scope</option>.</para>
+ <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
</listitem>
</varlistentry>
<listitem><para>Runs the service process with the specified
nice level. Also see <varname>Nice=</varname> in
- <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
- option has no effect in conjunction with
- <option>--scope</option>.</para>
+ <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
</listitem>
</varlistentry>
<listitem><para>Runs the service process with the specified
environment variables set. Also see
<varname>Environment=</varname> in
- <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>. This
- option has no effect in conjunction with
- <option>--scope</option>.</para>
+ <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
</listitem>
</varlistentry>
#include "strv.h"
#include "build.h"
#include "unit-name.h"
+#include "env-util.h"
#include "path-util.h"
#include "bus-error.h"
return -EINVAL;
}
- if (arg_scope && (arg_remain_after_exit || arg_service_type || arg_exec_user || arg_exec_group || arg_nice_set || arg_environment)) {
- log_error("--remain-after-exit, --service-type=, --user=, --group=, --nice= and --setenv= are not supported in --scope mode.");
+ if (arg_scope && (arg_remain_after_exit || arg_service_type)) {
+ log_error("--remain-after-exit and --service-type= are not supported in --scope mode.");
return -EINVAL;
}
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
_cleanup_free_ char *name = NULL;
+ _cleanup_strv_free_ char **env = NULL, **user_env = NULL;
int r;
assert(bus);
if (r < 0)
return r;
- execvp(argv[0], argv);
+ if (arg_nice_set) {
+ if (setpriority(PRIO_PROCESS, 0, arg_nice) < 0) {
+ log_error("Failed to set nice level: %m");
+ return -errno;
+ }
+ }
+
+ if (arg_exec_group) {
+ gid_t gid;
+
+ r = get_group_creds(&arg_exec_group, &gid);
+ if (r < 0) {
+ log_error("Failed to resolve group %s: %s", arg_exec_group, strerror(-r));
+ return r;
+ }
+
+ if (setresgid(gid, gid, gid) < 0) {
+ log_error("Failed to change GID to " GID_FMT ": %m", gid);
+ return -errno;
+ }
+ }
+
+ if (arg_exec_user) {
+ const char *home, *shell;
+ uid_t uid;
+ gid_t gid;
+
+ r = get_user_creds(&arg_exec_user, &uid, &gid, &home, &shell);
+ if (r < 0) {
+ log_error("Failed to resolve user %s: %s", arg_exec_user, strerror(-r));
+ return r;
+ }
+
+ r = strv_extendf(&user_env, "HOME=%s", home);
+ if (r < 0)
+ return log_oom();
+
+ r = strv_extendf(&user_env, "SHELL=%s", shell);
+ if (r < 0)
+ return log_oom();
+
+ r = strv_extendf(&user_env, "USER=%s", arg_exec_user);
+ if (r < 0)
+ return log_oom();
+
+ r = strv_extendf(&user_env, "LOGNAME=%s", arg_exec_user);
+ if (r < 0)
+ return log_oom();
+
+ if (!arg_exec_group) {
+ if (setresgid(gid, gid, gid) < 0) {
+ log_error("Failed to change GID to " GID_FMT ": %m", gid);
+ return -errno;
+ }
+ }
+
+ if (setresuid(uid, uid, uid) < 0) {
+ log_error("Failed to change UID to " UID_FMT ": %m", uid);
+ return -errno;
+ }
+ }
+
+ env = strv_env_merge(3, environ, user_env, arg_environment);
+ if (!env)
+ return log_oom();
+
+ execvpe(argv[0], argv, env);
log_error("Failed to execute: %m");
return -errno;
}
int strv_extend_strv(char ***a, char **b);
int strv_extend_strv_concat(char ***a, char **b, const char *suffix);
int strv_extend(char ***l, const char *value);
+int strv_extendf(char ***l, const char *format, ...);
int strv_push(char ***l, char *value);
int strv_consume(char ***l, char *value);