LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   a patch to script 'init' which in mkinitrd-1.4.6-i486-5 - slackware-current (https://www.linuxquestions.org/questions/slackware-14/a-patch-to-script-init-which-in-mkinitrd-1-4-6-i486-5-slackware-current-868813/)

hello.freeman 03-15-2011 09:24 PM

a patch to script 'init' which in mkinitrd-1.4.6-i486-5 - slackware-current
 
Make the code work when RESUMEDEV is a symbolic link which has a relative path.

Code:

diff -Naur initrd-tree-orig/init initrd-tree-new/init
--- initrd-tree-orig/init        2011-03-13 23:41:35.000000000 +0000
+++ initrd-tree-new/init        2011-03-16 02:03:42.990812427 +0000
@@ -260,12 +260,16 @@
 
  # Resume state from swap
  if [ "$RESUMEDEV" != "" ]; then
+    OLDCWD="$(pwd)"
    if ls -l $RESUMEDEV | grep -q "^l" ; then
+      cd "$(dirname "$RESUMEDEV")"
      RESUMEDEV=$(ls -l $RESUMEDEV | awk '{ print $NF }')
    fi
    echo "Trying to resume from $RESUMEDEV"
    RESMAJMIN=$(ls -l $RESUMEDEV | tr , : | awk '{ print $5$6 }')
    echo $RESMAJMIN > /sys/power/resume
+    cd "$OLDCWD"
+    unset OLDCWD
  fi
 
  # Switch to real root partition:


Bruce Hill 03-16-2011 06:22 AM

Submit your patch to Alien Bob for consideration.

hello.freeman 03-16-2011 07:26 PM

Quote:

Originally Posted by Bruce Hill (Post 4292436)
Submit your patch to Alien Bob for consideration.

I don't know who maintain the script before now.
I'll do it later.
thanks.
;)

willysr 03-16-2011 07:46 PM

I think it's AlienBOB
You can find his contact from his blog: http://alien.slackbook.org/blog/

Bruce Hill 03-16-2011 10:18 PM

Quote:

Originally Posted by willysr (Post 4293198)
I think it's AlienBOB
You can find his contact from his blog: http://alien.slackbook.org/blog/

Alien Bob

Or go straight to the top:
volkerdi

willy, on LQ we'd post the LQ username.

hello.freeman,

Pat Volkerding's email is posted in many Slackware files.

GazL 03-17-2011 06:02 AM

edit: deleted the last one as I think you can simplify further. (no need for all the readlink stuff)


Code:

printf '%d:%d\n' $(stat -L -c '0x%t 0x%T' $RESUMEDEV) >/sys/power/resume
looks like it ought to do the job.

+Alan Hicks+ 03-17-2011 08:45 AM

I fail to see precisely how this changes anything at all. For example:

Code:

alan@darkstar:~$ cd /home/alan
alan@darkstar:~$ mkdir /home/alan/bar
alan@darkstar:~$ ln -s /dev/../dev/../dev/sda2 /home/alan/foo
alan@darkstar:~$ ls -l foo
lrwxrwxrwx 1 alan users 23 Mar 17 09:41 foo -> /dev/../dev/../dev/sda2
export RESUMEDEV=/home/alan/foo

Now let's see what happens when running the current init.

Code:

alan@darkstar:~$    if [ "$RESUMEDEV" != "" ]; then
>      OLDCWD="$(pwd)"
>      if ls -l $RESUMEDEV | grep -q "^l" ; then
>        #cd "$(dirname "$RESUMEDEV")"
>        RESUMEDEV=$(ls -l $RESUMEDEV | awk '{ print $NF }')
>      fi
>      echo "Trying to resume from $RESUMEDEV"
>      RESMAJMIN=$(ls -l $RESUMEDEV | tr , : | awk '{ print $5$6 }')
>      echo $RESMAJMIN
>    fi
Trying to resume from /dev/../dev/../dev/sda2
8:2

Now let's look at it with your patch.

Code:

alan@darkstar:~$      if [ "$RESUMEDEV" != "" ]; then
>        OLDCWD="$(pwd)"
>        if ls -l $RESUMEDEV | grep -q "^l" ; then
>          cd "$(dirname "$RESUMEDEV")"
>          RESUMEDEV=$(ls -l $RESUMEDEV | awk '{ print $NF }')
>        fi
>        echo "Trying to resume from $RESUMEDEV"
>        RESMAJMIN=$(ls -l $RESUMEDEV | tr , : | awk '{ print $5$6 }')
>        echo $RESMAJMIN
>      fi
Trying to resume from /dev/../dev/../dev/sda2
8:2

So how exactly does your patch actually fix anything at all?

GazL 03-17-2011 12:54 PM

Perhaps this demonstrates what (s)he's getting at:
Code:

gazl@slack:/$ ls -ld /dev/wibble
lrwxrwxrwx 1 root root 6 Mar 17 16:19 /dev/wibble -> ./sda1
gazl@slack:/$ ls -ld /dev/sda1
brw-rw---- 1 root disk 8, 1 Mar 17 16:06 /dev/sda1
gazl@slack:/$ RESUMEDEV='/dev/wibble'
gazl@slack:/$ RESUMEDEV=$(ls -l $RESUMEDEV | awk '{ print $NF }')
gazl@slack:/$ RESMAJMIN=$(ls -l $RESUMEDEV | tr , : | awk '{ print $5$6 }')
ls: cannot access ./sda1: No such file or directory
gazl@slack:/$ echo $RESMAJMIN

gazl@slack:/$

Now, with the printf/stat I came up with above we still obtain the correct major:minor numbers rather than getting a file not found.
Code:

gazl@slack;/$ RESUMEDEV='/dev/wibble'
gazl@slack:/$ printf '%d:%d\n' $(stat -L -c '0x%t 0x%T' $RESUMEDEV)
8:1

Not only is my code shorter, it appears to correctly handle relative symlinks better.

I think the change the OP suggested does the same thing but relies on changing directory in order to get the appropriate result:
Code:

gazl@slack:/$ cd /dev
gazl@slack:/dev$ RESUMEDEV=$(ls -l $RESUMEDEV | awk '{ print $NF }')
gazl@slack:/dev$ RESMAJMIN=$(ls -l $RESUMEDEV | tr , : | awk '{ print $5$6 }')
gazl@slack:/dev$ echo $RESMAJMIN
8:1


Darth Vader 03-17-2011 02:33 PM

BTW, those changes are tested on a real initrd? With BusyBox tools?

We known that the BusyBox utilities sometimes works slighty different... ;)

GazL 03-17-2011 02:47 PM

I've not tried running it in an actual real initrd because I don't use resume, but I have confirmed that the busybox versions of printf and stat commands work as expected.

I don't really care about this issue, I just posted because I saw the ls -l | grep "^l" | awk.... stuff and thought: there must be a better way than that! ;)


All times are GMT -5. The time now is 06:16 AM.