Skip to content

Commit

Permalink
openrc-run: Move argument parsing before env setup
Browse files Browse the repository at this point in the history
We need to handle --user before calling any functions that interact with
librc.
  • Loading branch information
navi-desu committed Oct 28, 2024
1 parent 29aefc5 commit fd62d58
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/openrc-run/openrc-run.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,26 +1170,6 @@ int main(int argc, char **argv)
if (chdir(workingdir) == -1)
eerror("chdir: %s", strerror(errno));

if ((runlevel = xstrdup(getenv("RC_RUNLEVEL"))) == NULL) {
env_filter();
env_config();
runlevel = rc_runlevel_get();
}

setenv("EINFO_LOG", service, 1);
setenv("RC_SVCNAME", applet, 1);

/* Set an env var so that we always know our pid regardless of any
subshells the init script may create so that our mark_service_*
functions can always instruct us of this change */
xasprintf(&pidstr, "%d", (int) getpid());
setenv("RC_OPENRC_PID", pidstr, 1);
/*
* RC_RUNSCRIPT_PID is deprecated, but we will keep it for a while
* for safety.
*/
setenv("RC_RUNSCRIPT_PID", pidstr, 1);

/* eprefix is kinda klunky, but it works for our purposes */
if (rc_conf_yesno("rc_parallel")) {
/* Get the longest service name */
Expand Down Expand Up @@ -1253,6 +1233,26 @@ int main(int argc, char **argv)

atexit(cleanup);

if ((runlevel = xstrdup(getenv("RC_RUNLEVEL"))) == NULL) {
env_filter();
env_config();
runlevel = rc_runlevel_get();
}

setenv("EINFO_LOG", service, 1);
setenv("RC_SVCNAME", applet, 1);

/* Set an env var so that we always know our pid regardless of any
subshells the init script may create so that our mark_service_*
functions can always instruct us of this change */
xasprintf(&pidstr, "%d", (int) getpid());
setenv("RC_OPENRC_PID", pidstr, 1);
/*
* RC_RUNSCRIPT_PID is deprecated, but we will keep it for a while
* for safety.
*/
setenv("RC_RUNSCRIPT_PID", pidstr, 1);

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

Expand Down

0 comments on commit fd62d58

Please sign in to comment.