X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:references:date:in-reply-to :message-id:mime-version:content-type; q=dns; s=default; b=TpK0C NhPYEMi9ijnUPrD+XBV58FagqdVm7uWkSJTTdEpPuWkHH6zixNbOs2zCuGRJSpg2 AfEMv/KuszQaa1Ahyrv0oby4YVIfTLivPBaxoIusKq9BTfEXlOu7SSrzjndVtWdd nG3f1Z1oLuqJAp99VIuHoTrCrbnOWFv4GSCJCE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:references:date:in-reply-to :message-id:mime-version:content-type; s=default; bh=kLr3qO4RBHQ CXV0d48a9zH5eZ4E=; b=FYrPssd1t/IS8hDSlyy44tr3pUHyWI1fVisth7AyT4l /+9pcAzls6QmVkHBKH591HCbBt3RsViHGFIZaJLf1LAnPV4RTl3bIkjK7ABoD0NL 8MEgfuCDEogHzeFZA8OlesGRmz2LJM4XokxeezHEIFcjtJEYvRTf+rgPl+LiBK2M = Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-in-12.arcor-online.net X-DKIM: Sendmail DKIM Filter v2.8.2 mail-in-14.arcor-online.net 3kv0hB5Yydz4nRk From: Achim Gratz To: cygwin AT cygwin DOT com Subject: Re: freopen/fread/popen bug References: <54EFDEF4 DOT 4060308 AT cornell DOT edu> <20150227084311 DOT GF11124 AT calimero DOT vinschen DOT de> <54F065A0 DOT 9030608 AT cornell DOT edu> <54F098AA DOT 9050503 AT redhat DOT com> Date: Fri, 27 Feb 2015 20:05:58 +0100 In-Reply-To: <54F098AA.9050503@redhat.com> (Eric Blake's message of "Fri, 27 Feb 2015 09:17:46 -0700") Message-ID: <87bnkfgoo9.fsf@Rainer.invalid> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Eric Blake writes: >> What's really happening is that we need to peek at the first few bytes >> of f before deciding which program to call in popen. After peeking, >> there's a call to fseek(f,0,0) before the popen, with the intention that >> the child receives a file pointer set to the beginning of the file. (I >> left this out of my STC because it didn't affect the outcome.) This >> apparently works on Linux. > > Corinna is correct - you need to fflush() after the fseek() for it to > affect the underlying offset. Or, just use read()/lseek() instead of > fread()/fseek() in the parent, to avoid stdio buffering altogether. > That way, you'll guarantee the offset the child process will inherit > without having to worry about flushing buffered state. Basically this is the same category of bug that was in rcs for a while. It isn't easy to find out what is and isn't guaranteed about these things across a fork and since things work slightly differently on Linux that's something you can probably expect to show up more often. Regards, Achim. -- +<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+ Samples for the Waldorf Blofeld: http://Synth.Stromeko.net/Downloads.html#BlofeldSamplesExtra -- 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