libgnomeui-2.0 vs pipes



I am trying to write a gnomemm2 C++ application, but I am having
problems related to pipes, GDB and "interrupted system calls."
I have been able to reproduce the problem partly with only
libgnomeui-2.0 (libgnomeui-2.0.3.0.200208181945-0.snap.ximian.1).

My application opens a pipe (with popen) to the '/bin/rpm --version'
command and expects to read (with fread) the string "RPM version 4.0.4\n".

When the application is started from the command line, the fread()
call sometimes fails by returning zero and setting errno to EINTR.

When I start the application from gdb (5.2), the fread() call
systematically fails in this manner.

I tried coding a loop that retries the fread() call after EINTR,
but (still under gdb) this loop executes infinitely.  There seems
to be something that interrupts the read(2) call each and every
time, when under gdb.  This problem has also happened from the
command line, but very sporadically, so I'm trying to understand
the problem from inside gdb.

The malfunction seems to be introduced by the construction of the
Gnome::Main object in main().  Before that construction, reading
from the pipe succeeds.  After the construction, fread() almost
always gets interrupted at least once.

I have partly reproduced the problem by using only libgnomeui-2.0
from a C program.  Here is the test program:

    int main(int argc, char *argv[])
    {
        test_pipe();
        gnome_program_init("x", "0.0", LIBGNOMEUI_MODULE, argc, argv, NULL);
        test_pipe();
        return 0;
    }

The test_pipe() function reads from a pipe to the command 'echo foo'.
If fread() fails with EINTR, it tries again up to 10 times.  Here is
the output of that program (it is the same from the command line as
from gdb):

    Testing pipe
    Attempt # 1
    buffer=[foo
    ]
    End of test

    Testing pipe
    Attempt # 1
    errno: Interrupted system call
    Attempt # 2
    buffer=[foo
    ]
    End of test

Almost each time I run the program, I get the same output.

In my larger C++ application, I have this:

    - zero fread() failure right before constructing the Gnome::Main object;

    - one fread() failure right after constructing the Gnome::Main object
      (the second try works);

    - an infinite loop of fread() failures later in the program.

Because of the size of the application, I don't know for the moment
how to reproduce the infinite loop in a simpler C program using
only libgnomeui-2.0.


I have attached two .c files that illustrate the output given above
(but not an infinite loop).  The program can be compiled this way:

    gcc -g -Wall gnome-and-pipe.c -o gnome-and-pipe \
        `pkg-config --cflags --libs libgnomeui-2.0`

It should be run this way to be sure to obtain the error message
in English:

    LC_ALL=en_US ./gnome-and-pipe


Has anyone had similar problems?  Any leads?


My system:

    RedHat      7.2
    gcc         2.96-112
    glibc       2.2.4
    libstdc++   2.96-112
    glib2       2.0.6.0.200209270739-0.snap.ximian.1
    gtk2        2.0.6.0.200209270739-0.snap.ximian.1
    libgnome    2.0.2.0.200208181945-0.snap.ximian.1
    libgnomeui  2.0.3.0.200208181945-0.snap.ximian.1
    glib        1.2.10-ximian.5
    gtk+        1.2.10-ximian.31
    gnome-core  1.4.1-1.ximian.4
    gnome-libs  1.4.1.7-1.ximian.1
    gdb         5.2
    Linux       2.4.18.7.x i686

-- 
Pierre Sarrazin <sarrazip at sympatico dot ca>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]