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 a896659 commit fe3b01c
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions src/openrc-run/openrc-run.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,46 @@ int main(int argc, char **argv)
if (chdir(workingdir) == -1)
eerror("chdir: %s", strerror(errno));

/* Ok, we are ready to go, so setup selinux if applicable */
selinux_setup(argv);

deps = true;

/* Punt the first arg as its our service name */
argc--;
argv++;

/* Right then, parse any options there may be */
while ((opt = getopt_long(argc, argv, getoptstring,
longopts, (int *)0)) != -1)
switch (opt) {
case 'd':
setenv("RC_DEBUG", "YES", 1);
break;
case 'l':
exclusive_fd = atoi(optarg);
fcntl(exclusive_fd, F_SETFD,
fcntl(exclusive_fd, F_GETFD, 0) | FD_CLOEXEC);
break;
case 's':
if (!(rc_service_state(service) & RC_SERVICE_STARTED))
exit(EXIT_FAILURE);
break;
case 'S':
if (!(rc_service_state(service) & RC_SERVICE_STOPPED))
exit(EXIT_FAILURE);
break;
case 'D':
deps = false;
break;
case 'Z':
dry_run = true;
break;
case_RC_COMMON_GETOPT
}

atexit(cleanup);

if ((runlevel = xstrdup(getenv("RC_RUNLEVEL"))) == NULL) {
env_filter();
env_config();
Expand Down Expand Up @@ -1213,46 +1253,6 @@ int main(int argc, char **argv)
eprefix(prefix);
}

/* Ok, we are ready to go, so setup selinux if applicable */
selinux_setup(argv);

deps = true;

/* Punt the first arg as its our service name */
argc--;
argv++;

/* Right then, parse any options there may be */
while ((opt = getopt_long(argc, argv, getoptstring,
longopts, (int *)0)) != -1)
switch (opt) {
case 'd':
setenv("RC_DEBUG", "YES", 1);
break;
case 'l':
exclusive_fd = atoi(optarg);
fcntl(exclusive_fd, F_SETFD,
fcntl(exclusive_fd, F_GETFD, 0) | FD_CLOEXEC);
break;
case 's':
if (!(rc_service_state(service) & RC_SERVICE_STARTED))
exit(EXIT_FAILURE);
break;
case 'S':
if (!(rc_service_state(service) & RC_SERVICE_STOPPED))
exit(EXIT_FAILURE);
break;
case 'D':
deps = false;
break;
case 'Z':
dry_run = true;
break;
case_RC_COMMON_GETOPT
}

atexit(cleanup);

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

Expand Down

0 comments on commit fe3b01c

Please sign in to comment.