Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-17 Thread Lord Laraby
Well, that is some interesting stuff. So, in POSIX, the child gets the same FD in the same place and it is actually a second reference to the kernels open file table. The same entry as the parent uses (via FD) to determine the offset, flags, etc. That would explain why the child calling exit() flus

Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-17 Thread Eric Blake
On 01/17/2014 01:10 PM, Eric Blake wrote: >> However.. >> >> Do I understand that to say that if the first thing my child does is >> >> fclose(fp); >> >> everything should be hunky-dory? > > No. You have to fix things _in the parent, before the fork()_ for > everything to be hunky-dory. The

Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-17 Thread tednolan
In message <52d98e1d.8010...@redhat.com>you write: > >No. You have to fix things _in the parent, before the fork()_ for >everything to be hunky-dory. The easiest way to do that is to >fflush(NULL) before fork()ing. > You learn something new every day. Usually just after you needed to know it.

Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-17 Thread Eric Blake
On 01/14/2014 08:50 AM, tedno...@bellsouth.net wrote: > In message <52d55d96.8070...@redhat.com>you write: >> >> Your program may be violating POSIX, which would trigger undefined behavior. >> >> Quoting POSIX: >> pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_05 >> > > [

Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-17 Thread Eric Blake
On 01/15/2014 08:28 AM, tedno...@bellsouth.net wrote: > Well, all I can say in this instance, is that arguably conforming to > the bare letter of the standard (if that's in fact what is happening) > is not "the right thing". People certainly don't expect that stdio > file pointers that exist at f

Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-17 Thread Eric Blake
On 01/14/2014 09:53 PM, Lord Laraby wrote: > My two cents say, since the child is not referencing 'fp' at all, > there is no violation of the POSIX semantics in this situation. But the child _IS_ referencing 'fp', via the implicit fflush(NULL) done by exit(). If you use _exit() to bypass that imp

Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-17 Thread Eric Blake
On 01/13/2014 09:06 AM, tedno...@bellsouth.net wrote: > while( fgets(buf, sizeof(buf), fp) ) { > ++i; > > if(sscanf(buf, "%s %s", infile, outfile) != 2) { > > switch (fork()) { > > case 0: >

Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-17 Thread Corinna Vinschen
On Jan 16 23:53, tedno...@bellsouth.net wrote: > In message <20140116085026.ga26...@calimero.vinschen.de>you write: > > > >Can you change your testcase another bit, please? Enable your > >`ftell' printf, but rather than printing the result of ftell, > >print the result of lseek: > > > > fprintf(s

Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-16 Thread tednolan
In message <20140116085026.ga26...@calimero.vinschen.de>you write: > >Can you change your testcase another bit, please? Enable your >`ftell' printf, but rather than printing the result of ftell, >print the result of lseek: > > fprintf(stderr, "(%s) (%s) %d %ld\n", infile, >outfile, i, lse

Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-16 Thread Corinna Vinschen
On Jan 15 23:42, tedno...@bellsouth.net wrote: > >> FWIW, FreeBSD, Linux and Solaris all compile and run the test program > >> with the behavoir I expect.. > > > >Just for completeness: I can test on Linux, but not on FreeBSD and > >Solaris. Does the testcase also work as expected on both of them

Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-15 Thread tednolan
In message <20140115163354.ga30...@calimero.vinschen.de>you write: >--ew6BAiZeqk4r7MaW >Content-Type: text/plain; charset=utf-8 >Content-Disposition: inline >Content-Transfer-Encoding: quoted-printable > >On Jan 15 10:28, tedno...@bellsouth.net wrote: >> In message <52d63ce2.9060...@lysator.liu.se>

Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-15 Thread Corinna Vinschen
On Jan 15 11:39, Tom Honermann wrote: > On 01/13/2014 11:06 AM, tedno...@bellsouth.net wrote: > ... > > switch (fork()) { > > > > /* error */ > > case -1: > ... > > /* child */ > > case

Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-15 Thread Tom Honermann
On 01/13/2014 11:06 AM, tedno...@bellsouth.net wrote: ... switch (fork()) { /* error */ case -1: ... /* child */ case 0: fprin

Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-15 Thread Corinna Vinschen
On Jan 15 10:28, tedno...@bellsouth.net wrote: > In message <52d63ce2.9060...@lysator.liu.se>you write: > >On 2014-01-15 05:53, Lord Laraby wrote: > >> On Tue, Jan 14, 2014 at 10:50 AM, Ted Nolan wrote: > >>> In message <52d55d96.8070...@redhat.com> you write: > > Your program may be viol

Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-15 Thread tednolan
In message <52d63ce2.9060...@lysator.liu.se>you write: >On 2014-01-15 05:53, Lord Laraby wrote: >> On Tue, Jan 14, 2014 at 10:50 AM, Ted Nolan wrote: >>> In message <52d55d96.8070...@redhat.com> you write: Your program may be violating POSIX, which would trigger undefined behavio >r.

Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-14 Thread Peter Rosin
On 2014-01-15 05:53, Lord Laraby wrote: > On Tue, Jan 14, 2014 at 10:50 AM, Ted Nolan wrote: >> In message <52d55d96.8070...@redhat.com> you write: >>> >>> Your program may be violating POSIX, which would trigger undefined behavior. >>> >>> Quoting POSIX: >>> pubs.opengroup.org/onlinepubs/969991979

Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-14 Thread Lord Laraby
Please forgive my TOFU above. This gmail client really has no manners at all. -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple

Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-14 Thread Lord Laraby
My two cents say, since the child is not referencing 'fp' at all, there is no violation of the POSIX semantics in this situation. It actually does seem, however, that the fork is closing, or at least forgetting the stdio file position of, fp when it forks. A possible memory corruption during fork f

Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-14 Thread tednolan
In message <52d55d96.8070...@redhat.com>you write: > >Your program may be violating POSIX, which would trigger undefined behavior. > >Quoting POSIX: > pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_05 > [long quote elided] Yikes! That's pretty impenatrable. And if it s

Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-14 Thread Eric Blake
On 01/13/2014 09:06 AM, tedno...@bellsouth.net wrote: > Hello, > > I'm running: > > CYGWIN_NT-6.1 prog5 1.7.27(0.271/5/3) 2013-12-09 11:54 x86_64 Cygwin > gcc (GCC) 4.8.2 > > on a 64 bit Win7 system. > > I have just run into an odd bug, which I have boiled down into the program > below (which s

Re: fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-14 Thread Corinna Vinschen
On Jan 13 11:06, tedno...@bellsouth.net wrote: > Hello, > > I'm running: > > CYGWIN_NT-6.1 prog5 1.7.27(0.271/5/3) 2013-12-09 11:54 x86_64 Cygwin > gcc (GCC) 4.8.2 > > on a 64 bit Win7 system. > > I have just run into an odd bug, which I have boiled down into the program > below (which started

fork() + file descriptor bug in 1.7.27(0.271/5/3) 2013-12-09 11:54

2014-01-13 Thread tednolan
Hello, I'm running: CYGWIN_NT-6.1 prog5 1.7.27(0.271/5/3) 2013-12-09 11:54 x86_64 Cygwin gcc (GCC) 4.8.2 on a 64 bit Win7 system. I have just run into an odd bug, which I have boiled down into the program below (which started as a mod to tiff2ps). If you compile this program: