Skip to content

Commit

Permalink
misc: Add --user/-U flag to common flags.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
navi-desu committed Oct 26, 2024
1 parent bf76632 commit 622f016
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/mark_service/mark_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/openrc-run/openrc-run.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1250,6 +1251,8 @@ int main(int argc, char **argv)
case_RC_COMMON_GETOPT
}

atexit(cleanup);

if (rc_yesno(getenv("RC_NODEPS")))
deps = false;

Expand Down
3 changes: 2 additions & 1 deletion src/openrc/rc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -870,6 +869,8 @@ int main(int argc, char **argv)
}
}

atexit(cleanup);

/* Enable logging */
setenv("EINFO_LOG", "openrc", 1);

Expand Down
3 changes: 3 additions & 0 deletions src/service/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 7 additions & 2 deletions src/shared/_usage.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,33 @@

#include <getopt.h>
#include <stdlib.h>
#include "librc.h"

#define getoptstring_COMMON "ChqVv"
#define getoptstring_COMMON "ChqVvU"

#define longopts_COMMON \
{ "help", 0, NULL, 'h'}, \
{ "nocolor", 0, NULL, 'C'}, \
{ "version", 0, NULL, 'V'}, \
{ "verbose", 0, NULL, 'v'}, \
{ "quiet", 0, NULL, 'q'}, \
{ "user", 0, NULL, 'U'}, \
{ NULL, 0, NULL, 0 }

#define longopts_help_COMMON \
"Display this help output", \
"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 \
Expand All @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/value/value.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 622f016

Please sign in to comment.