FS#5245 - mkinitcpio functions problems

Attached to Project: Arch Linux
Opened by Matt (v01d) - Saturday, 19 August 2006, 00:22 GMT
Last edited by Aaron Griffin (phrakture) - Wednesday, 21 May 2008, 23:26 GMT
Task Type Bug Report
Category System
Status Closed
Assigned To Aaron Griffin (phrakture)
Thomas Bächler (brain0)
Architecture All
Severity Low
Priority Normal
Reported Version 0.7.2 Gimmick
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

There are some problems in some of the functions (/lib/initcpio/functions):
* add_symlink: it tries to see if $1 is a link, and then uses $1 as the link name. Both things can't happen, since $1 is either a real path (to make -L true) or a pathname where to create the file in the cpio archive. I mean, either strip BASEDIR from $1 or, even better, don't check if this is a symlink. The second option I think it is better if the user want's to use add_symlink itself. If the user is just going to use add_file, then I'd go with the first option.
* add_dir has a problem when dealing with relative links. On add_symlink, add_dir is issued on the basedir's of fil and dst. When the link is realtive (like ./busybox), then the basedir is '.'. This makes add_dir go into infinite recursion and, finally, bash segfaults.
This task depends upon

Closed by  Aaron Griffin (phrakture)
Wednesday, 21 May 2008, 23:26 GMT
Reason for closing:  Implemented
Additional comments about closing:  Most suggestions implemented, final comment moved to  FS#10466 
Comment by Matt (v01d) - Saturday, 19 August 2006, 00:30 GMT
Well, to be provide a more constructive criticism, here's my proposition for add_symlink:
add_symlink ()
{
local fil dest dir
if [ -L ${1} ]; then
fil="${1##$BASEDIR}"
dest="${2##$BASEDIR}"
msg "$fil $dest"
# add_dir $(dirname "${dest}")
add_dir $(dirname "${fil}")
if ! grep "slink ${dest} " "${FILELIST}" 2>&1 > /dev/null; then
msg " adding link ${fil} -> ${dest}"
echo "slink ${fil} ${dest} $(stat -c '%a' ${1}) 0 0" >> "${FILELIST}"
fi
fi
#fail quietly
}

It assumes the destination parent directories are already there (which sounds reasonable, since I'm creating a symlink to something).
Also, I'm prunning $1 at fil declaration. Then I use the full path ($1) in stat.
Comment by Aaron Griffin (phrakture) - Monday, 11 September 2006, 06:35 GMT
Please check functions in svn: http://phraktured.net/initramfs/mkinitcpio/functions

Let me know if this fixes your issues.
Comment by Matt (v01d) - Monday, 11 September 2006, 16:51 GMT
It works now almost as expected. Links are ok, and the inifinite recursion is no more.
Now, the only issue is that adding empty directories (as a result of an add_full_dir) complain when globbing:

for f in ${1}/*; do

with:

ERROR: file '/home/v01d/coding/projects/archcluster/images/rootfs/var/*' does not exist

That's all.


Comment by Matt (v01d) - Thursday, 25 January 2007, 21:06 GMT
Hi, versions keep going up and the last issue I mentioned is still there. Just a reminder =]
Comment by Aaron Griffin (phrakture) - Monday, 12 February 2007, 09:13 GMT
Added -d tests in svn (r195), can you verify this works? It should be picked up in the next version.
Comment by Roman Kyrylych (Romashka) - Saturday, 14 April 2007, 19:10 GMT
Status?
Comment by Matt (v01d) - Sunday, 15 April 2007, 04:31 GMT
I can't currently test the the latest change, but it was just the "ERROR" message that was left to fix. If that isn't there anymore I think this can be marked as fixed.
Comment by Roman Kyrylych (Romashka) - Sunday, 15 April 2007, 08:57 GMT
I think this error message could be worked around by using
for f in $(find ${1}/* -maxdepth 0 2>/dev/null); do

Please check it.
Comment by Matt (v01d) - Saturday, 28 April 2007, 02:03 GMT
You should also use fgrep, not grep, since strings like '[' can create problems otherwise.
Comment by Matt (v01d) - Saturday, 28 April 2007, 02:52 GMT
Also, on add_dir you check for "." but not for "..".
Comment by Aaron Griffin (phrakture) - Saturday, 28 April 2007, 04:19 GMT
Actually, I checked the first character for '.', which has some side-effects, but shouldn't cause a problem (I don't see any reason atm to have hidden files in early userspace)
Comment by Matt (v01d) - Saturday, 28 April 2007, 04:37 GMT
I've found out while playing with mkinitcpio, that readlink can be used to discover the full path out of a relative path string. Maybe this is useful to you since this would mean you don't need to check for situations like /home/./something nor (and current mkinitpcio implementation has problems with this) ../bin/something (symbolic links like make mkinitcpio want to create a ".." and "../bin" directory).
The idea is to do something like this:
$ readlink -f /home/httpd/../httpd/html/./phpldapadmin/../../
/home/httpd

You could do readlink -f on everything before attempting to create directories and such.
Be careful that this makes readlink behave different regarding its exit code. If you need to check for a possible symbolic link, just use "readlink" (and check the exit code) and then, when you need the pointed file, use the -f.
Comment by Aaron Griffin (phrakture) - Saturday, 28 April 2007, 05:22 GMT
That sounds like a decent idea, but I don't know if I have the time at the moment to look into it. If you could provide a patch, that'd speed things up.
Comment by Matt (v01d) - Saturday, 28 April 2007, 05:29 GMT
I don't have a lot of free time either, but since I will use mkinitcpio frequently I'll probably play with the code a little and send a patch.
Comment by Greg (dolby) - Saturday, 17 May 2008, 10:39 GMT
Is this still an issue?

Loading...