From 622f0169994adc1df6521af49329c11f0a4e373c Mon Sep 17 00:00:00 2001 From: "Anna (navi) Figueiredo Gomes" Date: Sat, 21 Sep 2024 11:18:43 +0200 Subject: [PATCH] misc: Add --user/-U flag to common flags. Some binaries required to have their `atexit(cleanup)` calls moved to after argument parsing, since setting user mode also adds an atexit call, and cleaning up user paths should only happen after the cleanup of the application is done, thus needs to be set first. --- src/mark_service/mark_service.c | 3 +++ src/openrc-run/openrc-run.c | 5 ++++- src/openrc/rc.c | 3 ++- src/service/service.c | 3 +++ src/shared/_usage.h | 9 +++++++-- src/value/value.c | 3 +++ 6 files changed, 22 insertions(+), 4 deletions(-) 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..4773a4b52 100644 --- a/src/openrc/rc.c +++ b/src/openrc/rc.c @@ -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"); @@ -870,6 +869,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/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);