-
Notifications
You must be signed in to change notification settings - Fork 276
fix error message when running as non-root #976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
N-R-K
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rough draft, fixes the immediate issue but I didn't analyze it properly to make sure if the logic is wholly correct or not.
src/openrc-run/openrc-run.c
Outdated
| /* FIXME: service_start() can return -1 in case of failure */ | ||
| pid = service_start(svc->value); | ||
| if (!rc_conf_yesno("rc_parallel")) | ||
| rc_waitpid(pid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed this, we might be feeding -1 into rc_waitpid which looks very suspicious to me. More investigation is needed.
|
i swear i had a fix for this somewhere already, though i guess i never merged it thanks for the mr! |
|
One more issue still remaining: [openrc errmsg-fix]~> rc-service ${service} stop
* ${service}: failed to acquire lock: Permission denied
[openrc errmsg-fix]~> doas rc-service ${service} stop
* WARNING: ${service} is already stopped
[openrc errmsg-fix]~> rc-service ${service} status
* status: stoppedIt's kind of a troll to complain to the user about invalid permissions, misleading them to retry with root only to then tell them the service is already stopped - which we could've known without needing root perm as shown in the |
i think we can just check if maybe i'd be nice to see if there's a proper error for permission as well, and check that, so that other errors don't get mixed with "we have no perms but it's stopped so print 'already stopped'" |
|
Is there a reason not to just do this? Seems clean: @@ -795,6 +795,11 @@ svc_stop_check(RC_SERVICE *state)
if (in_background && !(*state & (RC_SERVICE_STARTED | RC_SERVICE_INACTIVE)))
exit(EXIT_FAILURE);
+ if (*state & RC_SERVICE_STOPPED) {
+ ewarn("WARNING: %s is already stopped", applet);
+ return 1;
+ }
+
if (exclusive_fd == -1)
exclusive_fd = svc_lock(applet, !deps);
if (exclusive_fd == -1) {
@@ -806,11 +811,6 @@ svc_stop_check(RC_SERVICE *state)
}
fcntl(exclusive_fd, F_SETFD, fcntl(exclusive_fd, F_GETFD, 0) | FD_CLOEXEC);
- if (*state & RC_SERVICE_STOPPED) {
- ewarn("WARNING: %s is already stopped", applet);
- return 1;
- }
-
rc_service_mark(applet, RC_SERVICE_STOPPING); |
the only issue i see really is a possible race, if another process is either STOPPED > STARTING or STOPPING > STOPPED, realistically either case would basically make it throw a wrong error, by checking state without having a lock however we're already checking for FAILED/STARTED/INACTIVE before getting the lock anyway, so we might as well just do this |
currently trying to stop a service as non-root prints:
* ERROR: ${service} stopped by something else
but this is plain wrong, the service isn't stopped and the real
reason for failure is due to permission problem. same issue with
starting a service.
otherwise running as non-root will print permission error, misleading the user to retry with root only to then tell them the service is already stopped - which we could've known without needing root perm.
My thought as well. And also, the state variable never gets updated after acquiring the lock either, so doing it after wasn't really solving the race anyways. |
|
thanks! |
currently trying to stop a service as non-root prints:
but this is plain wrong, the service isn't stopped and the real reason for failure is due to permission problem. same issue with starting a service.