LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-15-2009, 09:10 AM   #1
velemas
LQ Newbie
 
Registered: Dec 2009
Posts: 2

Rep: Reputation: 0
Question read() on pipe returns -1 and errno set to 0


Hello,

I have a server program which is running on Suse Linux Enterprise Server 10 SP1 on i686. This program works pretty well, but once a month or so it terminates abruptly. According to trace files it is caused by
Code:
if ((*length = read (PINPUT,Pbuffer,sizeof(PKOPF))) == -1 && errno != EINTR)
FEHLER(SYS_FEHLER_RTC, strerror(errno))
FEHLER is a macro that prints error code and terminates the program. PINPUT is a file descriptor for the read end of a pipe. read() call can be interrupted by signal and this is normal. In that case read() returns -1 and errno is set to EINTR and the program continues its execution. But in my case when program terminates at this point errno is always 0 and strerror() returns 'Success' which means that read() returned -1 and (0 != EINTR). So is there any possible case for read() to return -1 and set errno to 0? Or maybe it's a bug in libc?
 
Old 12-15-2009, 02:34 PM   #2
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Quote:
Originally Posted by velemas View Post
So is there any possible case for read() to return -1 and set errno to 0?
No.
Quote:
Originally Posted by velemas View Post
maybe it's a bug in libc?
Extremely unlikely.

This may seem silly, but are SYS_FEHLER_RTC and FEHLER macros? And can you post their definitions?

Last edited by wje_lq; 12-15-2009 at 02:35 PM.
 
Old 12-18-2009, 06:19 AM   #3
velemas
LQ Newbie
 
Registered: Dec 2009
Posts: 2

Original Poster
Rep: Reputation: 0
I'm sorry for a long reply. The exact code is
Code:
    errno = 0;
    if ((*length = read (PINPUT,Pbuffer,sizeof(PKOPF))) == -1 && errno != EINTR)
        FEHLER(SYS_FEHLER_RTC, 0)
The definition of FEHLER is
Code:
#define FEHLER(rtx,p)\
        {int s_errno=errno;\
        sprintf (Error_lab, "%s[%d]", __FILE__, __LINE__);\
		if (0 == p)\
          sprintf (Error_msg, "Msg code : %d (errno=%d)", rtx, s_errno);\
        else\
          sprintf (Error_msg, "Msg text : %s - Msg code : %d (errno=%d)", p, rtx, s_errno);\
        l_log(Error_lab, Error_msg);\
        errno=s_errno;\
        goto end_proc;}
And SYS_FEHLER_RTC is just a constant
Code:
#define SYS_FEHLER_RTC     101
I have replaced FEHLER(SYS_FEHLER_RTC, 0) with FEHLER(SYS_FEHLER_RTC, strerror(errno)) for investigation purposes. But it can change errno itself. Originally it was printed "Msg code : 101 (errno=0)" in a log file. Now with my changes it prints "Msg text : Success - Msg code : 101 (errno=0)".
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
does perror() set errno? ebd Programming 24 08-17-2009 11:52 PM
poll returns errno 22, EINVAL mallport Programming 5 08-21-2006 03:24 PM
semop returns -1 but errno is 0 DaveRob Programming 1 08-11-2003 05:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration