diff --git a/src/mark_service/mark_service.c b/src/mark_service/mark_service.c index e9239c04d..5011a35dd 100644 --- a/src/mark_service/mark_service.c +++ b/src/mark_service/mark_service.c @@ -45,6 +45,9 @@ int main(int argc, char **argv) if (service == NULL || *service == '\0') eerrorx("%s: no service specified", applet); + if (rc_yesno(getenv("RC_USER_SERVICES"))) + rc_set_user(); + if (!strncmp(applet, "mark_", 5) && (bit = lookup_service_state(applet + 5))) ok = rc_service_mark(service, bit); diff --git a/src/openrc-run/openrc-run.c b/src/openrc-run/openrc-run.c index c4c0c6315..4f492bef9 100644 --- a/src/openrc-run/openrc-run.c +++ b/src/openrc-run/openrc-run.c @@ -1119,7 +1119,8 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } - atexit(cleanup); + if (rc_yesno(getenv("RC_USER_SERVICES"))) + rc_set_user(); /* We need to work out the real full path to our service. * This works fine, provided that we ONLY allow multiplexed services @@ -1250,6 +1251,8 @@ int main(int argc, char **argv) case_RC_COMMON_GETOPT } + atexit(cleanup); + if (rc_yesno(getenv("RC_NODEPS"))) deps = false; diff --git a/src/openrc/rc.c b/src/openrc/rc.c index bbe337b35..241906d49 100644 --- a/src/openrc/rc.c +++ b/src/openrc/rc.c @@ -772,7 +772,7 @@ int main(int argc, char **argv) RC_STRING *service; bool going_down = false; int depoptions = RC_DEP_STRICT | RC_DEP_TRACE; - const char *svcdir = rc_svcdir(); + const char *svcdir; char *rc_starting, *rc_stopping; char *deptree_skewed; char *krunlevel = NULL; @@ -796,7 +796,6 @@ int main(int argc, char **argv) applet = basename_c(argv[0]); LIST_INIT(&service_pids); LIST_INIT(&free_these_pids); - atexit(cleanup); if (!applet) eerrorx("arguments required"); @@ -807,11 +806,6 @@ int main(int argc, char **argv) if (chdir("/") == -1) eerror("chdir: %s", strerror(errno)); - /* Ensure our environment is pure - * Also, add our configuration to it */ - env_filter(); - env_config(); - /* complain about old configuration settings if they exist */ if (exists(RC_CONF_OLD)) { ewarn("%s still exists on your system and should be removed.", RC_CONF_OLD); @@ -859,6 +853,13 @@ int main(int argc, char **argv) } } + /* Ensure our environment is pure + * Also, add our configuration to it */ + env_filter(); + env_config(); + + svcdir = rc_svcdir(); + newlevel = argv[optind++]; /* To make life easier, we only have the shutdown runlevel as * nothing really needs to know that we're rebooting. @@ -870,6 +871,8 @@ int main(int argc, char **argv) } } + atexit(cleanup); + /* Enable logging */ setenv("EINFO_LOG", "openrc", 1); diff --git a/src/service/service.c b/src/service/service.c index 2545a0229..6444d6802 100644 --- a/src/service/service.c +++ b/src/service/service.c @@ -40,6 +40,9 @@ int main(int argc, char **argv) if (service == NULL || *service == '\0') eerrorx("%s: no service specified", applet); + if (rc_yesno(getenv("RC_USER_SERVICES"))) + rc_set_user(); + state = rc_service_state(service); bit = lookup_service_state(applet); if (bit) { diff --git a/src/shared/_usage.h b/src/shared/_usage.h index 91b956e06..c66b792e7 100644 --- a/src/shared/_usage.h +++ b/src/shared/_usage.h @@ -12,8 +12,9 @@ #include #include +#include "librc.h" -#define getoptstring_COMMON "ChqVv" +#define getoptstring_COMMON "ChqVvU" #define longopts_COMMON \ { "help", 0, NULL, 'h'}, \ @@ -21,6 +22,7 @@ { "version", 0, NULL, 'V'}, \ { "verbose", 0, NULL, 'v'}, \ { "quiet", 0, NULL, 'q'}, \ + { "user", 0, NULL, 'U'}, \ { NULL, 0, NULL, 0 } #define longopts_help_COMMON \ @@ -28,13 +30,15 @@ "Disable color output", \ "Display software version", \ "Run verbosely", \ - "Run quietly (repeat to suppress errors)" + "Run quietly (repeat to suppress errors)", \ + "Run in user mode" #define case_RC_COMMON_getopt_case_C setenv ("EINFO_COLOR", "NO", 1); #define case_RC_COMMON_getopt_case_h usage (EXIT_SUCCESS); #define case_RC_COMMON_getopt_case_V if (argc == 2) show_version(); #define case_RC_COMMON_getopt_case_v setenv ("EINFO_VERBOSE", "YES", 1); #define case_RC_COMMON_getopt_case_q set_quiet_options(); +#define case_RC_COMMON_getopt_case_U rc_set_user(); #define case_RC_COMMON_getopt_default usage (EXIT_FAILURE); #define case_RC_COMMON_GETOPT \ @@ -43,6 +47,7 @@ case 'V': case_RC_COMMON_getopt_case_V; break; \ case 'v': case_RC_COMMON_getopt_case_v; break; \ case 'q': case_RC_COMMON_getopt_case_q; break; \ + case 'U': case_RC_COMMON_getopt_case_U; break; \ default: case_RC_COMMON_getopt_default; break; extern const char *applet; diff --git a/src/start-stop-daemon/start-stop-daemon.c b/src/start-stop-daemon/start-stop-daemon.c index 5868dd377..d40042a6e 100644 --- a/src/start-stop-daemon/start-stop-daemon.c +++ b/src/start-stop-daemon/start-stop-daemon.c @@ -361,6 +361,9 @@ int main(int argc, char **argv) signal_setup(SIGQUIT, handle_signal); signal_setup(SIGTERM, handle_signal); + if (rc_yesno(getenv("RC_USER_SERVICES"))) + rc_set_user(); + openlog(applet, LOG_PID, LOG_DAEMON); if ((tmp = getenv("SSD_NICELEVEL"))) diff --git a/src/supervise-daemon/supervise-daemon.c b/src/supervise-daemon/supervise-daemon.c index ed60f5e46..f7d19a532 100644 --- a/src/supervise-daemon/supervise-daemon.c +++ b/src/supervise-daemon/supervise-daemon.c @@ -823,6 +823,8 @@ int main(int argc, char **argv) svcname = getenv("RC_SVCNAME"); if (!svcname) eerrorx("%s: The RC_SVCNAME environment variable is not set", applet); + if (rc_yesno(getenv("RC_USER_SERVICES"))) + rc_set_user(); openlog(applet, LOG_PID, LOG_DAEMON); if (argc <= 1 || strcmp(argv[1], svcname)) @@ -1085,7 +1087,7 @@ int main(int argc, char **argv) umask(numask); if (!pidfile) - xasprintf(&pidfile, "/var/run/supervise-%s.pid", svcname); + xasprintf(&pidfile, "%s/supervise-%s.pid", rc_is_user() ? getenv("XDG_RUNTIME_DIR") : "/var/run", svcname); xasprintf(&fifopath, "%s/supervise-%s.ctl", rc_svcdir(), svcname); if (mkfifo(fifopath, 0600) == -1 && errno != EEXIST) eerrorx("%s: unable to create control fifo: %s", diff --git a/src/value/value.c b/src/value/value.c index e5190379d..c9620cf0c 100644 --- a/src/value/value.c +++ b/src/value/value.c @@ -33,6 +33,9 @@ int main(int argc, char **argv) if (service == NULL) eerrorx("%s: no service specified", applet); + if (rc_yesno(getenv("RC_USER_SERVICES"))) + rc_set_user(); + if (argc < 2 || !argv[1] || *argv[1] == '\0') eerrorx("%s: no option specified", applet);