Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 392457

Summary: =sys-apps/openrc-0.9.4 : init scripts can't be executed from /etc/init.d/ directory
Product: Gentoo Hosted Projects Reporter: Nathaniel <nathaniel>
Component: OpenRCAssignee: OpenRC Team <openrc>
Status: RESOLVED FIXED    
Severity: normal CC: galandilias, veejar.net
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Bug Depends on:    
Bug Blocks: 394205    

Description Nathaniel 2011-11-29 20:06:31 UTC
After updating to openrc-0.9.4, I can no longer start and stop services from the /etc/init.d directory.

Instead, this happens:
dactyl init.d # ./dovecot restart
/lib64/rc/sh/runscript.sh: line 13: ./dovecot: No such file or directory
 * ERROR: dovecot failed to stop
dactyl init.d # 

However, typing the command as /etc/init.d/dovecot restart works fine.

I didn't see this behavior with openrc-0.8.4-r2

Reproducible: Always

Steps to Reproduce:
1. upgrade to openrc-0.9.4
2. cd /etc/init.d
3. try to start or stop a service
Actual Results:  
Error from /lib64/rc/sh/runscript.sh

Expected Results:  
the service should have started/stopped/whatever
Comment 1 Agostino Sarubbo gentoo-dev 2011-11-29 21:09:45 UTC
confirmed here
Comment 2 Marcin 2011-11-30 20:12:29 UTC
confirmed
Comment 3 Erik Fjeldstrom 2011-12-02 14:10:47 UTC
I confirm this as well on i686 (32-bit) OpenRC 0.9.4.

Adding `pwd' to the start of runscript.sh, it appears that the pwd is set to the root directory when runscript calls runscript.sh. This is the cause of the error that occurs.

Line 1129 of runscript.c shows why this is happening:
1128         /* Change dir to / to ensure all init scripts don't use stuff in pwd */
1129         if (chdir("/") == -1)
1130                 eerror("chdir: %s", strerror(errno));

Obviously this breaks scripts called using a relative path. To fix this, I propose:
--- a/src/rc/runscript.c
+++ b/src/rc/runscript.c
@@ -1122,1 +1122,1 @@ runscript(int argc, char **argv)
-         service = xstrdup(argv[1]);
+         service = realpath(argv[1], NULL);
Comment 4 William Hubbs gentoo-dev 2011-12-10 16:38:04 UTC
(In reply to comment #3)
> I confirm this as well on i686 (32-bit) OpenRC 0.9.4.
> 
> Adding `pwd' to the start of runscript.sh, it appears that the pwd is set to
> the root directory when runscript calls runscript.sh. This is the cause of the
> error that occurs.
> 
> Line 1129 of runscript.c shows why this is happening:
> 1128         /* Change dir to / to ensure all init scripts don't use stuff in
> pwd */
> 1129         if (chdir("/") == -1)
> 1130                 eerror("chdir: %s", strerror(errno));
> 
> Obviously this breaks scripts called using a relative path. To fix this, I
> propose:
> --- a/src/rc/runscript.c
> +++ b/src/rc/runscript.c
> @@ -1122,1 +1122,1 @@ runscript(int argc, char **argv)
> -         service = xstrdup(argv[1]);
> +         service = realpath(argv[1], NULL);

I just tested this, and it breaks any script in /etc/init.d that is a symbolic link, e.g. net.eth0. So we can't use this proposal.
Comment 5 William Hubbs gentoo-dev 2011-12-11 18:25:30 UTC
This is fixed in git, commit 5e01051.

Thanks for the report.