This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Information on a commit related to libstdc++/9533


> But... regtesting we got the failure of this test ("fail bit 
> was not set!"):

Here's my take on what is going on:

> // libstdc++/2913, libstdc++/4879
> // John Fardo  <jfardo at laurelnetworks dot com>, Brad Garcia 
> <garsh at attbi dot com>
> void
> test_04()
> {
>   signal(SIGPIPE, SIG_IGN);
>  
>   if (0 != mkfifo("xxx", S_IRWXU))
>     {
>       std::cerr << "failed to creat fifo" << std::endl;
>       exit(-1);
>     }
>  
>   int fval = fork();
>   if (fval == -1)
>     {
>       std::cerr << "failed to fork" << std::endl;
>       unlink("xxx");
>       exit(-1);
>     }
>   else if (fval == 0)
>     {
>       std::ifstream ifs("xxx");
>       sleep(1);
>       ifs.close();
>       exit(0);

Here, one end of the pipe is opened for reading and then closed
again without reading anything. This allows the other end to
be opened without blocking.

>     }
> 
>   std::ofstream ofs("xxx");
>   sleep(2);

Opens the write end of the pipe, then waits for two seconds, by
which time the read end should have been closed.

>   ofs.put('t');
> 
>   /*
>    * ISO/IED 14882:1998(E) 27.8.1.10.4
>    *
>    * void close();
>    *
>    * Effects:  Calls rdbuf()->close() and, if that function fails
>    * (returns a null pointer), calls setstate(failbit)...
>    */
>   ofs.close();

This calls rdbuf()->close(), which calls _M_really_overflow, which
calls fwrite which should fail because the read end of the pipe
should have been closed, but since underflow was called at the
read end, the read end is still open.

>   if (!(ofs.rdstate() & std::ios::failbit))
>     {
>       std::cerr << "fail bit was not set!" << std::endl;
>       unlink("xxx");
>       exit(-1);
>     }
> 
>   unlink("xxx");
> }

Petur


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]