Skip to content

Commit d045f77

Browse files
committed
fix error message when running as non-root
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.
1 parent ef3f90a commit d045f77

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/openrc-run/openrc-run.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,9 @@ svc_start_check(void)
557557
if (exclusive_fd == -1)
558558
exclusive_fd = svc_lock(applet, !deps);
559559
if (exclusive_fd == -1) {
560-
if (state & RC_SERVICE_STOPPING)
560+
if (errno != EWOULDBLOCK)
561+
eerrorx("%s: failed to acquire lock: %s", applet, strerror(errno));
562+
else if (state & RC_SERVICE_STOPPING)
561563
ewarnx("WARNING: %s is stopping", applet);
562564
else
563565
ewarnx("WARNING: %s is already starting", applet);
@@ -631,6 +633,10 @@ svc_start_deps(void)
631633
printf(" %s", svc->value);
632634
continue;
633635
}
636+
/* FIXME(NRK): service_start() can return -1 on
637+
* failure and feeding that to rc_waitpid seems
638+
* very suspicious. needs investigation.
639+
*/
634640
pid = service_start(svc->value);
635641
if (!rc_conf_yesno("rc_parallel"))
636642
rc_waitpid(pid);
@@ -792,7 +798,9 @@ svc_stop_check(RC_SERVICE *state)
792798
if (exclusive_fd == -1)
793799
exclusive_fd = svc_lock(applet, !deps);
794800
if (exclusive_fd == -1) {
795-
if (*state & RC_SERVICE_STOPPING)
801+
if (errno != EWOULDBLOCK)
802+
eerrorx("%s: failed to acquire lock: %s", applet, strerror(errno));
803+
else if (*state & RC_SERVICE_STOPPING)
796804
ewarnx("WARNING: %s is already stopping", applet);
797805
eerrorx("ERROR: %s stopped by something else", applet);
798806
}

src/shared/misc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ svc_lock(const char *applet, bool ignore_lock_failure)
289289
if (fd == -1)
290290
return -1;
291291
if (flock(fd, LOCK_EX | LOCK_NB) == -1) {
292+
int saved_errno = errno;
292293
if (ignore_lock_failure) {
293294
/* Two services with a need b, and b's start()
294295
* calling restart --no-deps on a would cause
@@ -299,6 +300,7 @@ svc_lock(const char *applet, bool ignore_lock_failure)
299300
}
300301
eerror("Call to flock failed: %s", strerror(errno));
301302
close(fd);
303+
errno = saved_errno;
302304
return -1;
303305
}
304306
return fd;

0 commit comments

Comments
 (0)