Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 412677 - Star in "before"/"after" dependencies expanded by shell as a wildcard
Summary: Star in "before"/"after" dependencies expanded by shell as a wildcard
Status: IN_PROGRESS
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: OpenRC (show other bugs)
Hardware: All Linux
: Normal minor (vote)
Assignee: OpenRC Team
URL:
Whiteboard:
Keywords: InVCS
Depends on:
Blocks: openrc-0.10
  Show dependency tree
 
Reported: 2012-04-19 19:22 UTC by Guenther Brunthaler
Modified: 2012-05-11 09:45 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
Output of emerg --info (emerge-info.txt,7.05 KB, text/plain)
2012-04-19 19:23 UTC, Guenther Brunthaler
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Guenther Brunthaler 2012-04-19 19:22:36 UTC
I have severe doubts that the following is what depend() is intended to do:

$ cd /etc/init.d
$ /etc/init.d/local depend
after bin boot camlp5 dev etc home lib lib32 lib64 logit media opt proc root sbin srv sys tmp usr var
keyword -timeout


Reproducible: Always

Steps to Reproduce:
1. Run the above commands
2. Wonder whether the output is really what it is supposed to be
3. Blame me for a bogus bug if openrc never uses the depend action like I did
Actual Results:  
The "*" in "before"/"after" clauses within a depend() in a service script always expands to the entries of the file system's root directory.

Expected Results:  
If "*" shall expand at all, I expect it to rather expand to the entries of the /etc/init.d directory.

I encountered that problem when writing a script to analyze the openrc service dependencies and looked for a way to extract the information contained in the depend() functions of the service script.

I soon found out that just calling the service script with "depend" as the argument seems to display this information.

However, in all entries which use a "*", this is expanded by all entries of the root directory.

Obviously, the service helper /sbin/runscript runs the depend() function as a normal shell function, where the "*" is expanded by the contents of the current directory.

If this current directory were /etc/init.d/, this would expand to the names of all service scripts - what the documented semantics of "*" also suggests.

However, obviously /sbin/runscript runs the depend() function rather from directory "/", where the "*" expands to all top-level directory names instead.

I am not sure whether this bug report is valid, because it might very well be that openrc never calls depend as a service script action like I did.

If it does, however, then this would be a bug which renders the "after *" / "before *" clauses in all depend() essentially ineffective.

In this case, the problem should also be rather simple to fix: /sbin/runscript just needs to do a "cd /etc/init.d" just before running depend(). Then "*" would expand to the names of all the services.
Comment 1 Guenther Brunthaler 2012-04-19 19:23:34 UTC
Created attachment 309529 [details]
Output of emerg --info
Comment 2 Christian Ruppert (idl0r) gentoo-dev 2012-04-26 13:27:03 UTC
Fixed through commit:
http://git.overlays.gentoo.org/gitweb/?p=proj/openrc.git;a=commit;h=9d0dce3

Thank you for your bug report! :)
Comment 3 William Hubbs gentoo-dev 2012-04-26 15:46:39 UTC
I am concerned about the fix that was committed for this issue.

The fix does a cd to the init.d directory for all commands that the
service runs, not just depend.

This means that for any command an init script writer defines we are
starting them out in the init.d directory instead of /.

I"m not sure that is an assumption we should make, because I think it
could potentially break init scripts.
Comment 4 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2012-04-26 16:20:28 UTC
idl0r:
NAK on that fix.
We really need something that scans the directory better, and excludes: 
- tempfiles
- anything not executable
- anything that doesn't start with runscript.
Comment 5 Christian Ruppert (idl0r) gentoo-dev 2012-04-26 16:23:28 UTC
(In reply to comment #4)
> idl0r:
> NAK on that fix.
> We really need something that scans the directory better, and excludes: 
> - tempfiles
> - anything not executable
> - anything that doesn't start with runscript.

I was already thinking about that but that will be more difficult..
Best case would be to disable globbing temp. and expand the "*" ourself but in this case you'd have to disable the globbing in the depend() function.
Comment 6 William Hubbs gentoo-dev 2012-04-26 18:17:49 UTC
All, I have added commit 8d63719 on top of idl0r's commit.

This allows the reporter to do what he was requesting, so I would like
to close this bug and put it on the tracker.
I think the enhancements requested in this bug can go to a separate bug.

Thoughts?
Comment 7 SpanKY gentoo-dev 2012-05-11 09:45:24 UTC
(In reply to comment #6)

you should be using pushd/popd, and quoting the path, rather than hardcoding /

however, the '*' really should be expanded by openrc itself and not left to the shell.  it's easy enough to use `set -f` to disable pathname expansion before evaluating the depend function.