From: Andrey Borzenkov <arvidjaar@mail.ru>
To: Andrew Patterson <andrew.patterson@hp.com>
Cc: Tejun Heo <teheo@suse.de>, Greg KH <greg@kroah.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, linux-hotplug@vger.kernel.org,
bjorn.helgaas@hp.com
Subject: Re: Error returns not handled correctly by sysfs.c:subsys_attr_store()
Date: Fri, 4 Jan 2008 10:30:35 +0300 [thread overview]
Message-ID: <200801041030.43494.arvidjaar@mail.ru> (raw)
In-Reply-To: <1199408174.7025.40.camel@bluto.andrew>
[-- Attachment #1: Type: text/plain, Size: 5152 bytes --]
On Friday 04 January 2008, Andrew Patterson wrote:
> On Thu, 2008-01-03 at 17:17 -0700, Andrew Patterson wrote:
> > On Fri, 2008-01-04 at 09:07 +0900, Tejun Heo wrote:
> > > Hello,
> > >
> > > Andrew Patterson wrote:
> > > > It looks like this is a shell issue. After looking through the sysfs
> > > > code, I realized that this problem seems to be driven from user-land.
> > > > So I performed some experiments:
> > > >
> > > > 1. Wrote a simple program that just used write(2) to write to the
> > > > sysfs entry. This works fine.
> > > > 2. Used /bin/echo instead of the built-in echo command. This too
> > > > works fine.
> > > > 3. Tried several shells. Zsh and Bash both fail. Csh works fine.
> > > >
> > > > I then ran strace on the following shell-script:
> > > >
> > > > #!/bin/bash
> > > >
> > > > echo x > allow_restart
> > > > echo y > allow_restart
> > > > echo z > allow_restart
> > > >
> > > > and got:
> > > >
> > > > # strace -e trace=write ~/tmp/tester.sh
> > > > write(1, "x\n", 2) = -1 EINVAL (Invalid argument)
> > > > write(1, "x\n", 2) = -1 EINVAL (Invalid argument)
> > > > write(2, "/home/andrew/tmp/tester.sh: line"...,
72/home/andrew/tmp/tester.sh: line 4: echo: write error: Invalid argument
> > > > ) = 72
> > > > write(1, "x\ny\n", 4) = -1 EINVAL (Invalid argument)
> > > > write(1, "x\ny\n", 4) = -1 EINVAL (Invalid argument)
> > > > write(2, "/home/andrew/tmp/tester.sh: line"...,
72/home/andrew/tmp/tester.sh: line 5: echo: write error: Invalid argument
> > > > ) = 72
> > > > write(1, "x\ny\nz\n", 6) = -1 EINVAL (Invalid argument)
> > > > write(1, "x\ny\nz\n", 6) = -1 EINVAL (Invalid argument)
> > > > write(2, "/home/andrew/tmp/tester.sh: line"...,
72/home/andrew/tmp/tester.sh: line 6: echo: write error: Invalid argument
> > > > ) = 72
> > > > write(1, "x\ny\nz\n", 6x
> > > > y
> > > > z
> > > > ) = 6
> > > > Process 3800 detached
> > >
> > > Eeeeeeeekkkk.... That's scary. Which distro are you using and what does
> > > 'bash --version' say?
> >
> > IA64 Debian lenny.
> >
> > # bash --version
> > GNU bash, version 3.1.17(1)-release (ia64-unknown-linux-gnu)
> >
> > # zsh --version
> > zsh 4.3.4 (ia64-unknown-linux-gnu)
> >
> > # csh --version
> > tcsh 6.14.00 (Astron) 2005-03-25 (ia64-unknown-linux) options
> > wide,nls,dl,al,kan,rh,nd,color,filec
> >
> > I suppose I should try this an ia32 box again, and perhaps with some
> > other distros. I am not sure what the kernel can do about this, but it
> > might be nice to report it to the shell maintainers.
>
> Some further tests:
>
> AMD running Debian lenny with i686 kernel -- fails.
> Bash version = 3.1.17(1)
>
> Intel running Ubuntu/gutsy with i686 kernel -- fails.
> Bash version = 3.2.25(1)
>
> Itanium running SLES10 with ia64 kernel -- succeeds.
> Bash version = 3.1.17(1)
>
> BTW, I found a way to reproduce this without modifying the kernel.
> The /sys/class/scsi_host/*/state sysfs store routine returns EINVAL if
> an invalid state is written. So just echo 2 bad values to the the state
> sysfs entry while running strace.
>
I can't reproduce it using zsh either 4.3.4 as shipped by Mandriva or zsh CVS
head. In both cases it echoes correct argument. Nor do I see double writes's in
strace.
{pts/0}% sudo strace -e trace=write /tmp/foo # zsh 4.3.4
write(1, "x\n", 2) = -1 EINVAL (Invalid argument)
write(2, "/tmp/foo:echo:3: write error: \320\235"..., 72/tmp/foo:echo:3: write
error: Недопустимый аргумент
) = 72
write(1, "y\n", 2) = -1 EINVAL (Invalid argument)
write(2, "/tmp/foo:echo:4: write error: \320\235"..., 72/tmp/foo:echo:4: write
error: Недопустимый аргумент
) = 72
write(1, "z\n", 2) = -1 EINVAL (Invalid argument)
write(2, "/tmp/foo:echo:5: write error: \320\235"..., 72/tmp/foo:echo:5: write
error: Недопустимый аргумент
) = 72
{pts/0}% sudo strace -e trace=write /tmp/foo # zsh CVS head
write(1, "x\n", 2) = -1 EINVAL (Invalid argument)
write(2, "/tmp/foo:echo:3: write error: \320\235"..., 72/tmp/foo:echo:3: write
error: Недопустимый аргумент
) = 72
write(1, "y\n", 2) = -1 EINVAL (Invalid argument)
write(2, "/tmp/foo:echo:4: write error: \320\235"..., 72/tmp/foo:echo:4: write
error: Недопустимый аргумент
) = 72
write(1, "z\n", 2) = -1 EINVAL (Invalid argument)
write(2, "/tmp/foo:echo:5: write error: \320\235"..., 72/tmp/foo:echo:5: write
error: Недопустимый аргумент
) = 72
{pts/0}% cat /tmp/foo
#!/home/bor/pkg/bin/zsh -f
echo x > state
echo y > state
echo z > state
where state is /sys/power/state
{pts/1}% zsh --version
zsh 4.3.4 (i586-mandriva-linux-gnu)
{pts/1}% ~/pkg/bin/zsh --version
zsh 4.3.4-dev-6 (i686-pc-linux-gnu)
-andrey
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
next prev parent reply other threads:[~2008-01-04 7:30 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-21 22:16 Error returns not handled correctly by sysfs.c:subsys_attr_store() Andrew Patterson
2007-11-27 4:31 ` Andrew Morton
2007-11-27 5:33 ` Greg KH
2007-11-27 5:38 ` Tejun Heo
2007-11-28 7:42 ` Tejun Heo
2007-11-28 19:31 ` Andrew Patterson
2007-11-28 20:05 ` Greg KH
2007-11-29 1:07 ` Tejun Heo
2007-12-03 21:15 ` Andrew Patterson
2007-12-21 20:35 ` Greg KH
2008-01-03 23:51 ` Andrew Patterson
2008-01-04 0:07 ` Tejun Heo
2008-01-04 0:17 ` Andrew Patterson
2008-01-04 0:56 ` Andrew Patterson
2008-01-04 7:30 ` Andrey Borzenkov [this message]
2008-01-07 21:13 ` Andrew Patterson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200801041030.43494.arvidjaar@mail.ru \
--to=arvidjaar@mail.ru \
--cc=akpm@linux-foundation.org \
--cc=andrew.patterson@hp.com \
--cc=bjorn.helgaas@hp.com \
--cc=greg@kroah.com \
--cc=linux-hotplug@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=teheo@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.