Skip to content

Commit

Permalink
user services flag
Browse files Browse the repository at this point in the history
  • Loading branch information
navi-desu committed Sep 21, 2024
1 parent 995ef05 commit bed3b48
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 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
7 changes: 5 additions & 2 deletions src/openrc-run/openrc-run.c
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,9 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}

if (rc_yesno(getenv("RC_USER_SERVICES")))
rc_set_user();

/* We need to work out the real full path to our service.
* multiplexed services must point to a target in a init dir. */
if (!realpath(argv[1], service_path)) {
Expand All @@ -1182,8 +1185,6 @@ int main(int argc, char **argv)
service = normalize_path(argv[1]);
applet = basename_c(service);

atexit(cleanup);

if (argc < 3)
usage(EXIT_FAILURE);

Expand Down Expand Up @@ -1277,6 +1278,8 @@ int main(int argc, char **argv)
case_RC_COMMON_GETOPT
}

atexit(cleanup);

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

Expand Down
6 changes: 4 additions & 2 deletions src/openrc/rc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 @@ -859,6 +858,7 @@ int main(int argc, char **argv)
}
}

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.
Expand All @@ -870,6 +870,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 bed3b48

Please sign in to comment.