Solved

How to use errno in embedded linux

Posted on 2012-03-16
5
400 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Fine Tune your automatic Updates for Ubuntu / Debian
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

695 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