ls to stat patch
Hi,
I was randomly looking through the git repository and came across modules.d/95resume/resume.sh and its comment about not liking the use of ls. I modified it to use stat instead, and since stat has been in coreutils since at least late 2005, I assume it's safe to use.
Thanks
modules.d/95resume/resume.sh +1 -4
@@ -1,8 +1,5 @@ #!/bin/sh [ -s /.resume -a -b "$resume" ] && { - # parsing the output of ls is Bad, but until there is a better way... - ls -lH "$resume" | ( - read x x x x maj min x; - echo "${maj%,}:$min"> /sys/power/resume) + stat -c '%t:%T' "$resume" > /sys/power/resume >/.resume }
modules.d/99base/install +1 -1
@@ -1,8 +1,8 @@ #!/bin/bash dracut_install mount mknod mkdir modprobe pidof sleep chroot \ - sed ls flock cp mv dmesg rm ln + sed ls flock cp mv dmesg rm ln stat if [ ! -e "${initdir}/bin/sh" ]; then dracut_install bash (ln -s bash "${initdir}/bin/sh" || :) fi # install our scripts and hooks
Quoted 5 lines · Joe Pelkey
Hi,
I was randomly looking through the git repository and came acrossmodules.d/95resume/resume.shand its comment about not liking the use of ls. I modified it to use stat instead, and since stat has been in coreutils since at least late 2005, I assume it's safe to use.
<snip patch>
We had a patch that did that initally, but dropped it because it adds another binary to the initramfs.
Quoted 2 lines
Thanks
--
To unsubscribe from this list: send the line "unsubscribe initramfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · Victor Lowther
Quoted 6 lines · Joe Pelkey
Hi,
I was randomly looking through the git repository and came acrossmodules.d/95resume/resume.shand its comment about not liking the use of
ls. I modified it to use stat instead, and since stat has been in coreutils since at least late 2005, I assume it's safe to use.
Quoted 4 lines
<snip patch>
We had a patch that did that initally, but dropped it because it adds another binary to the initramfs.
What else depends on 'ls'?
I can see 'ls' is used only in modules.d/95nfs/install which is invoked during creating initramfs image only. Am I wrong?
btw: Joe's patch has bug, because stat returns major and minor in hex and we need decimal values. We can use printf (which is part of dash) to convert values.
my version:
Subject: [PATCH] use stat binary instead of ls
--- modules.d/95resume/install | 1 + modules.d/95resume/resume.sh | 7 +++---- modules.d/99base/install | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
modules.d/95resume/install +1 -0
@@ -1,4 +1,5 @@ #!/bin/bash +dracut_install stat inst_hook cmdline 10 "$moddir/parse-resume.sh" inst_hook pre-udev 30 "$moddir/resume-genrules.sh" inst_hook mount 10 "$moddir/resume.sh"
modules.d/95resume/resume.sh +3 -4
@@ -1,8 +1,7 @@ #!/bin/sh [ -s /.resume -a -b "$resume" ] && { - # parsing the output of ls is Bad, but until there is a better way... - ls -lH "$resume" | ( - read x x x x maj min x; - echo "${maj%,}:$min"> /sys/power/resume) + stat -L -c "0x%t 0x%T" "$resume" | ( + read maj min; + echo "$(printf %d $maj):$(printf %d $min)"> /sys/power/resume) >/.resume }
modules.d/99base/install +1 -1
@@ -1,6 +1,6 @@ #!/bin/bash dracut_install mount mknod mkdir modprobe pidof sleep chroot \ - sed ls flock cp mv dmesg rm ln rmmod mkfifo less + sed flock cp mv dmesg rm ln rmmod mkfifo less if [ ! -e "${initdir}/bin/sh" ]; then dracut_install bash (ln -s bash "${initdir}/bin/sh" || :)
Signature · 1 line
1.6.5.2
modules.d/95resume/install
Quoted 35 lines · Pawel Krzesniak
Quoted 9 lines · Victor Lowther
Quoted 6 lines · Joe Pelkey
Hi,
I was randomly looking through the git repository and came acrossmodules.d/95resume/resume.shand its comment about not liking the use of
ls. I modified it to use stat instead, and since stat has been in coreutils since at least late 2005, I assume it's safe to use.Quoted 4 lines
<snip patch>
We had a patch that did that initally, but dropped it because it adds another binary to the initramfs.
What else depends on 'ls'?
I can see 'ls' is used only in modules.d/95nfs/install which is invoked during creating initramfs image only. Am I wrong?btw: Joe's patch has bug, because stat returns major and minor in hex and we need decimal values. We can use printf (which is part of dash) to convert values.
my version:
Subject: [PATCH] use stat binary instead of ls
Signed-off-by Pawel Krzesniak<[email protected]>--- modules.d/95resume/install | 1 + modules.d/95resume/resume.sh | 7 +++---- modules.d/99base/install | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)modules.d/95resume/install +0
-0
Hmm, having "ls" in the rescue shell is better than "stat"