* System call v.s. errno
@ 2005-05-04 13:22 Richard B. Johnson
2005-05-04 13:30 ` Måns Rullgård
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Richard B. Johnson @ 2005-05-04 13:22 UTC (permalink / raw)
To: Linux kernel
Does anybody know for sure if global 'errno' is supposed to
be altered after a successful system call? I'm trying to
track down a problem where system calls return with EINTR
even though all signal handlers are set with SA_RESTART in
the flags. It appears as though there may be a race somewhere
because if I directly set errno to 0x1234, within a few
hundred system calls, it gets set to EINTR even though all
system calls seemed to return 'good'. This makes it
hard to trace down the real problem.
The answer is not obvious because the 'C' runtime library
doesn't really give access to 'errno' instead it is dereferenced
off some pointer returned from a function called __errno_location().
This problem does not exist with Linux-2.4.x. It started to show
up when user's updated their machines to newer RH stuff that uses
linux-2.6.5-1.358.
Cheers,
Dick Johnson
Penguin : Linux version 2.6.11 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by Dictator Bush.
98.36% of all statistics are fiction.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: System call v.s. errno
2005-05-04 13:22 System call v.s. errno Richard B. Johnson
@ 2005-05-04 13:30 ` Måns Rullgård
2005-05-04 13:41 ` Wichert Akkerman
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Måns Rullgård @ 2005-05-04 13:30 UTC (permalink / raw)
To: linux-kernel
"Richard B. Johnson" <linux-os@analogic.com> writes:
> Does anybody know for sure if global 'errno' is supposed to
> be altered after a successful system call? I'm trying to
> track down a problem where system calls return with EINTR
> even though all signal handlers are set with SA_RESTART in
> the flags. It appears as though there may be a race somewhere
> because if I directly set errno to 0x1234, within a few
> hundred system calls, it gets set to EINTR even though all
> system calls seemed to return 'good'. This makes it
> hard to trace down the real problem.
>
> The answer is not obvious because the 'C' runtime library
> doesn't really give access to 'errno' instead it is dereferenced
> off some pointer returned from a function called __errno_location().
The kernel knows nothing about errno. Have you tried using strace to
check the actual return values of the system calls?
> This problem does not exist with Linux-2.4.x. It started to show
> up when user's updated their machines to newer RH stuff that uses
> linux-2.6.5-1.358.
So go file a bug with redhat. It wouldn't be the first time they ship
broken stuff.
--
Måns Rullgård
mru@inprovide.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: System call v.s. errno
2005-05-04 13:22 System call v.s. errno Richard B. Johnson
2005-05-04 13:30 ` Måns Rullgård
@ 2005-05-04 13:41 ` Wichert Akkerman
2005-05-04 13:42 ` Jakub Jelinek
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Wichert Akkerman @ 2005-05-04 13:41 UTC (permalink / raw)
To: Richard B. Johnson; +Cc: Linux kernel
Previously Richard B. Johnson wrote:
> Does anybody know for sure if global 'errno' is supposed to
> be altered after a successful system call?
It's not. Also this is not a kernel related question: errno is managed
by libc.
Wichert.
--
Wichert Akkerman <wichert@wiggy.net> It is simple to make things.
http://www.wiggy.net/ It is hard to make things simple.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: System call v.s. errno
2005-05-04 13:22 System call v.s. errno Richard B. Johnson
2005-05-04 13:30 ` Måns Rullgård
2005-05-04 13:41 ` Wichert Akkerman
@ 2005-05-04 13:42 ` Jakub Jelinek
2005-05-04 13:49 ` Richard B. Johnson
2005-05-04 13:55 ` Martin Waitz
2005-05-04 14:22 ` Arjan van de Ven
4 siblings, 1 reply; 8+ messages in thread
From: Jakub Jelinek @ 2005-05-04 13:42 UTC (permalink / raw)
To: Richard B. Johnson; +Cc: Linux kernel
On Wed, May 04, 2005 at 09:22:09AM -0400, Richard B. Johnson wrote:
> Does anybody know for sure if global 'errno' is supposed to
> be altered after a successful system call? I'm trying to
> track down a problem where system calls return with EINTR
> even though all signal handlers are set with SA_RESTART in
> the flags. It appears as though there may be a race somewhere
> because if I directly set errno to 0x1234, within a few
> hundred system calls, it gets set to EINTR even though all
> system calls seemed to return 'good'. This makes it
> hard to trace down the real problem.
http://www.opengroup.org/onlinepubs/009695399/functions/errno.html
is very clear on this. Unless indicated that errno is valid after a call
(for many syscalls it is valid when the syscall returns -1), errno has
unspecified value.
Jakub
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: System call v.s. errno
2005-05-04 13:42 ` Jakub Jelinek
@ 2005-05-04 13:49 ` Richard B. Johnson
2005-05-04 16:03 ` Stephen Hemminger
0 siblings, 1 reply; 8+ messages in thread
From: Richard B. Johnson @ 2005-05-04 13:49 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Linux kernel
On Wed, 4 May 2005, Jakub Jelinek wrote:
> On Wed, May 04, 2005 at 09:22:09AM -0400, Richard B. Johnson wrote:
>> Does anybody know for sure if global 'errno' is supposed to
>> be altered after a successful system call? I'm trying to
>> track down a problem where system calls return with EINTR
>> even though all signal handlers are set with SA_RESTART in
>> the flags. It appears as though there may be a race somewhere
>> because if I directly set errno to 0x1234, within a few
>> hundred system calls, it gets set to EINTR even though all
>> system calls seemed to return 'good'. This makes it
>> hard to trace down the real problem.
>
> http://www.opengroup.org/onlinepubs/009695399/functions/errno.html
> is very clear on this. Unless indicated that errno is valid after a call
> (for many syscalls it is valid when the syscall returns -1), errno has
> unspecified value.
>
> Jakub
> -
Okay, thanks. That means that it's okay for it to get trashed
NotGood(tm) for debugging.
Cheers,
Dick Johnson
Penguin : Linux version 2.6.11 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by Dictator Bush.
98.36% of all statistics are fiction.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: System call v.s. errno
2005-05-04 13:22 System call v.s. errno Richard B. Johnson
` (2 preceding siblings ...)
2005-05-04 13:42 ` Jakub Jelinek
@ 2005-05-04 13:55 ` Martin Waitz
2005-05-04 14:22 ` Arjan van de Ven
4 siblings, 0 replies; 8+ messages in thread
From: Martin Waitz @ 2005-05-04 13:55 UTC (permalink / raw)
To: Richard B. Johnson; +Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 560 bytes --]
hoi :)
On Wed, May 04, 2005 at 09:22:09AM -0400, Richard B. Johnson wrote:
> Does anybody know for sure if global 'errno' is supposed to
> be altered after a successful system call? I'm trying to
> track down a problem where system calls return with EINTR
> even though all signal handlers are set with SA_RESTART in
> the flags.
syscalls are only automatically restarted by the interrupt if the
syscall returns -ERESTARTSYS. If it returns -EINTR itself then that will
be delivered to userspace even when it sets SA_RESTART.
--
Martin Waitz
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: System call v.s. errno
2005-05-04 13:22 System call v.s. errno Richard B. Johnson
` (3 preceding siblings ...)
2005-05-04 13:55 ` Martin Waitz
@ 2005-05-04 14:22 ` Arjan van de Ven
4 siblings, 0 replies; 8+ messages in thread
From: Arjan van de Ven @ 2005-05-04 14:22 UTC (permalink / raw)
To: linux-os; +Cc: Linux kernel
On Wed, 2005-05-04 at 09:22 -0400, Richard B. Johnson wrote:
> Does anybody know for sure if global 'errno' is supposed to
errno is a glibc level thing really, and in recent glibc tehre is no
global errno anymore, only a per thread errno.
> The answer is not obvious because the 'C' runtime library
> doesn't really give access to 'errno' instead it is dereferenced
> off some pointer returned from a function called __errno_location().
yeah to make sure you get the per thread errno instead. Any reasonable
sane code (and all standards conforming code) just deals with that fine.
The case that is known to break is if your app has it's own
extern int errno;
in it, instead of using the proper header to get it.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: System call v.s. errno
2005-05-04 13:49 ` Richard B. Johnson
@ 2005-05-04 16:03 ` Stephen Hemminger
0 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2005-05-04 16:03 UTC (permalink / raw)
To: linux-kernel
On Wed, 4 May 2005 09:49:37 -0400 (EDT)
"Richard B. Johnson" <linux-os@analogic.com> wrote:
> On Wed, 4 May 2005, Jakub Jelinek wrote:
>
> > On Wed, May 04, 2005 at 09:22:09AM -0400, Richard B. Johnson wrote:
> >> Does anybody know for sure if global 'errno' is supposed to
> >> be altered after a successful system call? I'm trying to
> >> track down a problem where system calls return with EINTR
> >> even though all signal handlers are set with SA_RESTART in
> >> the flags. It appears as though there may be a race somewhere
> >> because if I directly set errno to 0x1234, within a few
> >> hundred system calls, it gets set to EINTR even though all
> >> system calls seemed to return 'good'. This makes it
> >> hard to trace down the real problem.
> >
> > http://www.opengroup.org/onlinepubs/009695399/functions/errno.html
> > is very clear on this. Unless indicated that errno is valid after a call
> > (for many syscalls it is valid when the syscall returns -1), errno has
> > unspecified value.
> >
> > Jakub
> > -
>
> Okay, thanks. That means that it's okay for it to get trashed
> NotGood(tm) for debugging.
>
> Cheers,
> Dick Johnson
Also, on with NPTL and many thread libraries errno is really a macro
that refers to a per-thread variable.
--
Stephen Hemminger <shemminger@osdl.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2005-05-05 0:44 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-04 13:22 System call v.s. errno Richard B. Johnson
2005-05-04 13:30 ` Måns Rullgård
2005-05-04 13:41 ` Wichert Akkerman
2005-05-04 13:42 ` Jakub Jelinek
2005-05-04 13:49 ` Richard B. Johnson
2005-05-04 16:03 ` Stephen Hemminger
2005-05-04 13:55 ` Martin Waitz
2005-05-04 14:22 ` Arjan van de Ven
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox