* ls to stat patch
@ 2009-09-03 6:33 Joe Pelkey
[not found] ` <4A9F6345.4050003-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Joe Pelkey @ 2009-09-03 6:33 UTC (permalink / raw)
To: initramfs-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 284 bytes --]
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
[-- Attachment #2: ls_to_stat.diff --]
[-- Type: text/plain, Size: 1132 bytes --]
diff -rN -U 5 dracut-001.orig/modules.d/95resume/resume.sh dracut-001/modules.d/95resume/resume.sh
--- dracut-001.orig/modules.d/95resume/resume.sh 2009-09-02 09:55:35.000000000 -0400
+++ dracut-001/modules.d/95resume/resume.sh 2009-09-03 02:29:27.000000000 -0400
@@ -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
}
diff -rN -U 5 dracut-001.orig/modules.d/99base/install dracut-001/modules.d/99base/install
--- dracut-001.orig/modules.d/99base/install 2009-09-02 09:55:35.000000000 -0400
+++ dracut-001/modules.d/99base/install 2009-09-03 02:00:35.000000000 -0400
@@ -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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: ls to stat patch
[not found] ` <4A9F6345.4050003-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2009-09-03 15:14 ` Victor Lowther
2009-11-23 14:44 ` Pawel Krzesniak
0 siblings, 1 reply; 4+ messages in thread
From: Victor Lowther @ 2009-09-03 15:14 UTC (permalink / raw)
To: Joe Pelkey; +Cc: initramfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
On Sep 3, 2009, at 1:33 AM, Joe Pelkey <pelkeyj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> 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.
<snip patch>
We had a patch that did that initally, but dropped it because it adds
another binary to the initramfs.
> Thanks
>
--
To unsubscribe from this list: send the line "unsubscribe initramfs" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: ls to stat patch
2009-09-03 15:14 ` Victor Lowther
@ 2009-11-23 14:44 ` Pawel Krzesniak
[not found] ` <loom.20091123T144413-833-eS7Uydv5nfjZ+VzJOa5vwg@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Pawel Krzesniak @ 2009-11-23 14:44 UTC (permalink / raw)
To: initramfs-u79uwXL29TY76Z2rM5mHXA
Victor Lowther <victor.lowther@...> writes:
> On Sep 3, 2009, at 1:33 AM, Joe Pelkey <pelkeyj@...> wrote:
>
> > 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.
>
> <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 <pawel.krzesniak-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
modules.d/95resume/install | 1 +
modules.d/95resume/resume.sh | 7 +++----
modules.d/99base/install | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/modules.d/95resume/install b/modules.d/95resume/install
index 9200f95..a88d608 100755
--- a/modules.d/95resume/install
+++ b/modules.d/95resume/install
@@ -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"
diff --git a/modules.d/95resume/resume.sh b/modules.d/95resume/resume.sh
index 8bb4114..022ef0e 100755
--- a/modules.d/95resume/resume.sh
+++ b/modules.d/95resume/resume.sh
@@ -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
}
diff --git a/modules.d/99base/install b/modules.d/99base/install
index 801c8d7..68c89c6 100755
--- a/modules.d/99base/install
+++ b/modules.d/99base/install
@@ -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" || :)
--
1.6.5.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: ls to stat patch
[not found] ` <loom.20091123T144413-833-eS7Uydv5nfjZ+VzJOa5vwg@public.gmane.org>
@ 2009-11-26 18:15 ` Harald Hoyer
0 siblings, 0 replies; 4+ messages in thread
From: Harald Hoyer @ 2009-11-26 18:15 UTC (permalink / raw)
To: Pawel Krzesniak; +Cc: initramfs-u79uwXL29TY76Z2rM5mHXA
On 11/23/2009 03:44 PM, Pawel Krzesniak wrote:
> Victor Lowther<victor.lowther@...> writes:
>
>> On Sep 3, 2009, at 1:33 AM, Joe Pelkey<pelkeyj@...> wrote:
>>
>>> 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.
>>
>> <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<pawel.krzesniak-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> ---
> modules.d/95resume/install | 1 +
> modules.d/95resume/resume.sh | 7 +++----
> modules.d/99base/install | 2 +-
> 3 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/modules.d/95resume/install b/modules.d/95resume/install
Hmm, having "ls" in the rescue shell is better than "stat"
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-11-26 18:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-03 6:33 ls to stat patch Joe Pelkey
[not found] ` <4A9F6345.4050003-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2009-09-03 15:14 ` Victor Lowther
2009-11-23 14:44 ` Pawel Krzesniak
[not found] ` <loom.20091123T144413-833-eS7Uydv5nfjZ+VzJOa5vwg@public.gmane.org>
2009-11-26 18:15 ` Harald Hoyer
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.