Eintr Error Number
Contents |
Aug 2004 on RedHat 7.3 #define EPERM 1 /* Operation not permitted */ #define ENOENT 2 /* No such file or directory */ #define ESRCH 3 /* linux kernel error codes No such process */ #define EINTR 4 /* Interrupted system call */ #define
Posix Error Codes
EIO 5 /* I/O error */ #define ENXIO 6 /* No such device or address */ #define E2BIG 7 /*
Linux Errno Example
Arg list too long */ #define ENOEXEC 8 /* Exec format error */ #define EBADF 9 /* Bad file number */ #define ECHILD 10 /* No child processes */ #define EAGAIN 11
Eintr Errno
/* Try again */ #define ENOMEM 12 /* Out of memory */ #define EACCES 13 /* Permission denied */ #define EFAULT 14 /* Bad address */ #define ENOTBLK 15 /* Block device required */ #define EBUSY 16 /* Device or resource busy */ #define EEXIST 17 /* File exists */ #define EXDEV 18 /* Cross-device link */ #define ENODEV 19 /* No such device */ #define eintr linux ENOTDIR 20 /* Not a directory */ #define EISDIR 21 /* Is a directory */ #define EINVAL 22 /* Invalid argument */ #define ENFILE 23 /* File table overflow */ #define EMFILE 24 /* Too many open files */ #define ENOTTY 25 /* Not a typewriter */ #define ETXTBSY 26 /* Text file busy */ #define EFBIG 27 /* File too large */ #define ENOSPC 28 /* No space left on device */ #define ESPIPE 29 /* Illegal seek */ #define EROFS 30 /* Read-only file system */ #define EMLINK 31 /* Too many links */ #define EPIPE 32 /* Broken pipe */ #define EDOM 33 /* Math argument out of domain of func */ #define ERANGE 34 /* Math result not representable */ #define EDEADLK 35 /* Resource deadlock would occur */ #define ENAMETOOLONG 36 /* File name too long */ #define ENOLCK 37 /* No record locks available */ #define ENOSYS 38 /* Function not implemented */ #define ENOTEMPTY 39 /* Directory not empty */ #define ELOOP 40 /* Too many symbolic links encountered */ #define EWOULDBLOCK EAGAIN /* Operation would block */ #define ENOMSG 42 /* No message of desired ty
DESCRIPTION top The
that you can get from different blocking functions (send, recv, poll, sem_wait etc.) The POSIX standard unhelpfully describes it as "Interrupted function." Googling for EINTR returns mainly random questions like "I am getting teh EINTR error. What now?" answered mostly by "Just restart the http://250bpm.com/blog:12 interrupted function." None of this helps much when you want to correctly handle EINTR, actually understand what you are doing and why. In this blog post I'll try to explain what EINTR is good for and how to handle it in http://www.ibm.com/developerworks/aix/library/au-errnovariable/ your code. To understand the rationale behind EINTR, let's do a little coding exercise. Let's write a simple event loop that performs some action for every byte it receives from a socket. And let's pretend there's no EINTR and recv just error codes continues waiting for data whatever happens: void event_loop (int sock) { while (1) { char buf [1]; recv (sock, buf, 1, 0); printf ("perform an action\n"); } } The above program works great. However, interrupting the program using Ctrl+C kills it immediately, which may be a problem if we want to do some clean-up, for example, release some system-wide resources. To handle Ctrl+C in a custom way we have to implement a signal handler: volatile int stop = 0; void handler (int) eintr error number { stop = 1; } void event_loop (int sock) { signal (SIGINT, handler); while (1) { if (stop) { printf ("do cleanup\n"); return; } char buf [1]; recv (sock, buf, 1, 0); printf ("perform an action\n"); } } Ok. Looks good. What's the problem with that? The problem is that recv is a blocking function. If Ctrl+C is pressed while the event loop is blocked in recv, you'll get a kind of deadlock: Signal handler is executed as expected, it sets 'stop' to 1, but then the execution blocks. The event loop is stuck in recv and has no opportunity to check whether 'stop' was set to 1. The deadlock unblocks only when new data arrive via the socket. Then 'stop' is checked and the program exits decently. However, there's no guarantee that new data will arrive in a reasonable time, so pressing Ctrl+C may seem to have no effect. The program is probably going to terminate at some later point, but at the moment it's just stuck. Enter EINTR. POSIX specification defines that when signal (such as Ctrl+C) is caught, recv returns EINTR error. That allows the event loop to wrap over and check the 'stop' variable: volatile int stop = 0; void handler (int) { stop = 1; } void event_loop (int sock) { signal (SIGINT, handler); while (1) { if (stop) { printf ("do cleanup\n"); return; } char buf [1]; int rc = recv (sock, buf, 1, 0); if (rc
and UNIXTechnical library Errors: errno in UNIX programsWorking with the standard error mechanism Learn more than you ever wanted to know about the UNIX® standard error reporting mechanism, the errno global variable. You'll also learn about a couple of associated global variables ( sys_nerr and sys_errlist) and the standard functions that help you report errors to the user. Share: Chris Herborth (chrish@pobox.com), Freelance Writer, Author Close [x] Chris Herborth is an award-winning Senior Technical Writer with more than 10 years of experience writing about operating systems and programming. When he's not playing with his son Alex or hanging out with his wife Lynette, Chris spends his spare time designing, writing, and researching (that is, playing) video games. 05 September 2006 Also available inChineseJapanese Table of contents Introduction Before you start Error reporting in C programs Reporting failure Error global variables and standard values Dealing with errors Summary Download Resources Comments IntroductionProper error detection and recovery is often ignored by UNIX® developers. The lack of exceptions from the C language and the rudimentary error mechanisms from the standard C library certainly contribute to this. This article familiarizes you with UNIX error reporting in the standard C library and (hopefully) encourages you to report and handle errors in a user-friendly way.Let's dig in!Back to topBefore you startIf you want to follow along with the code samples in this article, you'll need to Download the source archive (unless you want to type it in). I'm going to be working in Eclipse using the C/C++ Development Tooling (CDT). If you've never tried Eclipse before, there are links in the Resources section that help you get started.The code examples are fairly trivial, but using an integrated development environment (IDE), such as Eclipse, makes it easier for you to open system headers, find specific symbols, and so forth. The latest versions of Eclipse (3.2) and the CDT plug-ins (2.0) are packed with great, helpful features.Back to topError reporting in C programsC is the most commonly used programming language on UNIX platforms. Despite the popularity of other languages on UNIX (such as Ja