errno

errno

Post by Pierre Decro » Fri, 15 Mar 1996 04:00:00



Does the 'errno' variable belong to a process or to the unix kernel ? Is
it a good thing for an "in-house" library subroutine to set errno or is
it not recommended (and why) ?

Thanks for your help.
--
Pierre Decrocq - SLIGOS Payment Services France

 
 
 

errno

Post by Xtof » Fri, 15 Mar 1996 04:00:00



Quote:Decrocq) writes:
>Does the 'errno' variable belong to a process or to the unix kernel ?

It is a per-process variable, set by library calls. it is defined in
libc.a

Quote:>it a good thing for an "in-house" library subroutine to set errno or is
>it not recommended (and why) ?

If you know what you're doing :^) !.. some subsequent system call,
hidden inside library functions, may modify errno.
You can safely use the values defined in <sys/errno.h> like EPERM,
ENOENT, ... to indicate error by return value.

Quote:>Thanks for your help.

De rien !...


"God is real, unless He was declared integer."

 
 
 

errno

Post by Ron McOu » Wed, 20 Mar 1996 04:00:00



>Does the 'errno' variable belong to a process or to the unix kernel ? Is
>it a good thing for an "in-house" library subroutine to set errno or is
>it not recommended (and why) ?
>Thanks for your help.
>--
>Pierre Decrocq - SLIGOS Payment Services France

It is an extern variable pulled in from libc at link time.

The value of errno is not cleared for a successful system call.  It is
set by any system call that returns -1 indicating an error and then
errno can be checked to see what kind of error.  If the next system
call executes successfully then errno is not updated.  You should be
able to write to it but if a system call fails between your write and
your next read the value will probably change unless you happened to
write the value that errno should be for that system call failure.

 
 
 

errno

Post by Sriram Srinivas » Wed, 20 Mar 1996 04:00:00


: >Does the 'errno' variable belong to a process or to the unix kernel ?
: It is a per-process variable, set by library calls. it is defined in
: libc.a

A small correction: On modern OSs, errno is a thread level concept(note,
I don't say "variable"). In solaris, for example, errno is not a variable -
it is #define'd to a function call (*(___errno())) .
Of course, it still is a user-level thingie.
:
: >it a good thing for an "in-house" library subroutine to set errno or is
: >it not recommended (and why) ?
:
: If you know what you're doing :^) !.. some subsequent system call,
: hidden inside library functions, may modify errno.
: You can safely use the values defined in <sys/errno.h> like EPERM,
: ENOENT, ... to indicate error by return value.

If there's any chance this system is going to use threads in the future,
you can't do this.

If not, there are still two ways to understand this question ...
When setting errno, do you propose to use existing values defined in
errno.h, or introduce your own values ?

The former is ok, but I'd be hesitant to use the latter, because a couple
of years from now that value may be used for some wholly unrelated purpose
by the OS vendor.

-Sriram

 
 
 

errno

Post by Pierre Decro » Thu, 21 Mar 1996 04:00:00



Quote:>It is an extern variable pulled in from libc at link time.

This brings one question and one remark:

Q1 - what happens to programs that are not linked with libc ? They should
have no errno. So how will system calls notice it ?

R1 - The fact that only system calls set errno seems to indicate that
errno is an attribute of system calls (kind of like in OO words a private
variable that can be queried from outside). So it seems not to be a good
thing to set it from user programs, although implementation makes it
possible (BTW TLI library designers chose to have their own private error
code variable).

--
Pierre Decrocq - SLIGOS Payment Services France

 
 
 

errno

Post by Andrew Gabri » Fri, 22 Mar 1996 04:00:00




Quote:

>A small correction: On modern OSs, errno is a thread level concept(note,
>I don't say "variable"). In solaris, for example, errno is not a variable -
>it is #define'd to a function call (*(___errno())) .
>Of course, it still is a user-level thingie.

This is only for code built to be threaded, i.e. with _REENTRANT defined.
It allows ___errno() to return a pointer to the errno appropriate to the
thread calling it, since there needs to be one errno per thread.

In non-threaded code, it's the good old traditional int, one per process.

Quote:>: If you know what you're doing :^) !.. some subsequent system call,
>: hidden inside library functions, may modify errno.
>: You can safely use the values defined in <sys/errno.h> like EPERM,
>: ENOENT, ... to indicate error by return value.

>If there's any chance this system is going to use threads in the future,
>you can't do this.

No, even in threaded environments this works fine.

     errno = ENOENT;

quite transparently due to the:   #define errno (*(___errno()))
becomes:

     *(___errno()) = ENOENT;

i.e. you are setting the errno appropriate to the current thread.

Of course, you need to build your library with -D_REENTRANT if you
think it might be used in threaded code (and you need to ensure all
the functions are indeed reentrant and Multi-thread safe), or you
need to take the special precautions required to link a non-
multi-threaded library into a multi-threaded app (only calling it
from the original thread).

--


 
 
 

errno

Post by Andrew Gier » Fri, 22 Mar 1996 04:00:00




>: >Does the 'errno' variable belong to a process or to the unix kernel ?
>: It is a per-process variable, set by library calls. it is defined in
>: libc.a

>A small correction: On modern OSs, errno is a thread level concept(note,
>I don't say "variable"). In solaris, for example, errno is not a variable -
>it is #define'd to a function call (*(___errno())) .
>Of course, it still is a user-level thingie.

Variable or not, IIRC the standards require it to be a modifiable lvalue.
So you can treat it like a variable.

Quote:>: >it a good thing for an "in-house" library subroutine to set errno or is
>: >it not recommended (and why) ?
>:
>: If you know what you're doing :^) !.. some subsequent system call,
>: hidden inside library functions, may modify errno.
>: You can safely use the values defined in <sys/errno.h> like EPERM,
>: ENOENT, ... to indicate error by return value.

>If there's any chance this system is going to use threads in the future,
>you can't do this.

Why not? Even if errno is defined as (*___errno()) which seems to be
the usual for multi-threaded environments, then statements such as

    errno = ERANGE;

are still valid and have the expected results.

Quote:>If not, there are still two ways to understand this question ...
>When setting errno, do you propose to use existing values defined in
>errno.h, or introduce your own values ?

>The former is ok, but I'd be hesitant to use the latter, because a couple
>of years from now that value may be used for some wholly unrelated purpose
>by the OS vendor.

I think this is the best basis on which to decide whether or not to
use errno.

BTW: it is incorrect to regard errno as something specifically
associated with system calls; there are a number of standard library
functions which are *not* system calls (at least, not on any system
I know of) and which set errno. The math library is a good example.


[.sig under construction]

 
 
 

errno

Post by Pierre Decro » Sat, 23 Mar 1996 04:00:00



says...

>BTW: it is incorrect to regard errno as something specifically
>associated with system calls; there are a number of standard library
>functions which are *not* system calls (at least, not on any system
>I know of) and which set errno. The math library is a good example.



Andrew, How do those libraries handle the case of signals being catched
after they have set errno, and the signal handler invokes a system call
that fails ?

--
Pierre Decrocq - SLIGOS Payment Services France

 
 
 

errno

Post by Xtof » Sat, 23 Mar 1996 04:00:00




>A small correction: On modern OSs, errno is a thread level concept(note,
>I don't say "variable").

Yeah, it sounds rather neat :)

Quote:>When setting errno, do you propose to use existing values defined in
>errno.h, or introduce your own values ?

In fact, I've never done this... If I need return values I just use
classical
things, like enum or #define...



>Q1 - what happens to programs that are not linked with libc ?

You cannot easily do that in C. libc.a is automatically linked in,
link is required to get an executable, even if you say 'main(){ }'...


"#include "/dev/tty" /* Ultimate program -- WiLL do whatever you want */"

 
 
 

errno

Post by Andrew Gier » Tue, 26 Mar 1996 04:00:00




>says...

>>BTW: it is incorrect to regard errno as something specifically
>>associated with system calls; there are a number of standard library
>>functions which are *not* system calls (at least, not on any system
>>I know of) and which set errno. The math library is a good example.

>Andrew, How do those libraries handle the case of signals being catched
>after they have set errno, and the signal handler invokes a system call
>that fails ?

How does application code handle the case where a system call returns
an error, and a signal is caught before the next line of code is
executed, and the signal handler invokes a system call that fails?

Bet you most programs just quietly break down and die... unless
the signal handler remembers to save & restore errno.

So it's not the libraries responsibility to handle this case...


[.sig under construction]

 
 
 

1. startx: errno 111, errno 3

I am bran new to Linux.
My computer is an AMD 300 MHz, 64 MB RAM, 8M Video Card, PCI Winmodem and
sound card, ps/2 3-button mouse, old 14" monitor
After finally thinking I had Redhat 5.2 installed, I can't run X Windows.
Entering the startx command results in the following:

"Too little memory for virtual resolution 1024 768
*** A configuration device found, but display modes could not be
resolved.***

Fatal Server Error:
no screens found"

"_X11TransSocketUNIXConnect:  Can't connect:  errorno = 111
giving up.
xinit:  Connection Refused (errno 111):  unable to connect to X server
xinit:  No such process (errno 3):  Server error."

Any input on this problem would be greatly appreciated.  I am at a total
loss.

Greg

2. how to use ircII

3. errno 146 & errno 3

4. Question before installing Koffice

5. 2.5.20 -- /usr/include/linux/errno.h:4: asm/errno.h: No such file or directory

6. NTP & Solaris 8

7. Disturbing change to errno.h

8. PPP, USR Sportster 28.8, Linux

9. HELP: POP client problem, (errno = 95)

10. msgrcv() setting errno badly

11. Unable to connect to X server (errno = 111)

12. Problem with dlopen - Errno=8 [ENOEXEC]

13. error handling when errno == ECHILD ...