Bug 1528451

Summary: dracut var dracut_cmd set incorrectly
Product: [Fedora] Fedora Reporter: Stephen Champion <schamp>
Component: dracutAssignee: dracut-maint-list
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: urgent Docs Contact:
Priority: unspecified    
Version: 27CC: dracut-maint-list, harald, jonathan, schamp, zbyszek
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-01-10 11:48:31 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Stephen Champion 2017-12-21 21:52:17 UTC
Description of problem:
The dracut internal variable dracut_cmd is set with 'readlink -f $0'.
If the argument to readlink -f is not a full path and does not exist in the current working directly, then readlink -f returns $PWD/$0.

If regenerate _all is set, then dracut calls $dracut_cmd.

Presumably this is as root, so I'm setting a high severity.

Version-Release: dracut-046-5.fc27.x86_64

How reproducible: 100%

Steps to Reproduce:
1. Run dracut --regenerate all
2.
3.

Actual results:
It runs $PWD/dracut.

Expected results:
It runs /usr/bin/dracut.

Additional info:
I haven't actually run with --regenerate-all.  I'm chasing another problem, this jumped out at me, and I thought I should flag it...

With a fix, you may want to leave a testing override - which is presumably why readlink was used.

Comment 1 Robert Scheck 2017-12-21 23:27:56 UTC
Oh dear, fancy "pagure over dist-git" stuff is still broken. I am definitely
not the default assignee for "dracut", re-assigning manually for now. Reported
the issue at https://pagure.io/fedora-infrastructure/issue/6587 already.

Comment 2 Harald Hoyer 2018-01-10 10:27:41 UTC
Hmm, I don't know how $0 could end up without a path.

With "--help printing $dracut_cmd"

 cat << EOF
Usage: $dracut_cmd [OPTION]... [<initramfs> [<kernel-version>]]


Test:

creating local dracut executable:

~ # cat dracut
#!/bin/sh

echo "FAIL"
~ # ./dracut 
FAIL

Testing /usr/bin/dracut:

~ # dracut --help | head -1
Usage: /usr/bin/dracut [OPTION]... [<initramfs> [<kernel-version>]]

Comment 3 Stephen Champion 2018-01-10 11:48:31 UTC
In a POSIX shell, $0 is not required to include the full path - only the path components that were used.

But bash is not a POSIX shell, and this is not a bug.