LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   read() on pipe returns -1 and errno set to 0 (https://www.linuxquestions.org/questions/programming-9/read-on-pipe-returns-1-and-errno-set-to-0-a-775793/)

velemas 12-15-2009 09:10 AM

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?

wje_lq 12-15-2009 02:34 PM

Quote:

Originally Posted by velemas (Post 3792310)
So is there any possible case for read() to return -1 and set errno to 0?

No.
Quote:

Originally Posted by velemas (Post 3792310)
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?

velemas 12-18-2009 06:19 AM

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)".


All times are GMT -5. The time now is 03:01 PM.