Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to use errno in embedded linux

Posted on 2012-03-16
5
Medium Priority
?
422 Views
Last Modified: 2012-03-16
Hello, we're getting the hang of embedded linux, and we have a call to the POSIX command (in unistd.h) "write" that sometimes returns -1 indicating failure, and we have no idea why (happen to be writing to a USB port).

So I did a little digging and found that a lot of these POSIX commands set something called errno when they fail, which appears to be a centralized error code, which seemed like something we could use.  We included "errno.h" and set the errno to zero before the call that sometimes fails, and then after it fails it is set to 11.

So trying to figure out what that means, consulted this link:

http://publib.boulder.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Fapis%2Funix14.htm

which actually doesn't have an 11, so I assumed that it means 3011, which sorta fits because it is ESTDOUT "The stdout stream cannot be opened.", not very useful but the right direction.  However, consulting this page:

http://pubs.opengroup.org/onlinepubs/7908799/xsh/write.html

does NOT list ESTDOUT as one of the possible errnos.  

So:

* are we misinterpreting our value of ESTDOUT?
* does that error make sense for the write command
* why would the write command intermittently fail to a USB port?

Thanks very much for any insight!
0
Comment
Question by:RonMexico
  • 3
  • 2
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 37731369
Acutally, errno 11 is EAGAIN (IIRC) or "Resource temporarily unavailable" (http://linux.die.net/man/3/errno)
0
 

Author Comment

by:RonMexico
ID: 37731422
Oh... that would be consistent with the intermittent nature.  Your web link didn't have numbers, do you just have that memorized?  That IBM page has EAGAIN as 3406... meaning I will never again use that page.

So we are relatively new to linux, and you are clearly expert (or more accurate guru by the list to the right).  What kinds of things can cause "resource temporarily unavailable" for a USB port?
0
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 37731444
That could be a lot of things, and given the nature of USB communications, I'd just guess that something else is going on on the bus at that very moment. IMO the best thing is to do what the name of the error code suggest - trying the 'write()' request again until it can be completed successfuly, e.g. (pseudocode):

int ret;

do {

  ret = write(...);

} while (ret == -1 && errno == EAGAIN);

// check other error conditions:
if (ret == -1) {

  // evaluate errno for different values
}

Open in new window

0
 

Author Comment

by:RonMexico
ID: 37731538
Thanks very much jkr!
0
 
LVL 86

Expert Comment

by:jkr
ID: 37731557
You're welcome ;o)

BTW, adding a delay in the above loop would help to make that less CPU-intensive.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses
Course of the Month11 days, 2 hours left to enroll

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question