FAQ
To: perlbug@perl.com
Subject: read, fork and exit mismatch file positions
Reply-To: salvador.fandino@corp.vizzavi.net

This is a bug report for perl from salvador.fandino@corp.vizzavi.net,
generated with the help of perlbug 1.28 running under perl v5.6.0.


-----------------------------------------------------------------
[Please enter your report here]

Hello,

I think I have found a bug. When using the read, fork, exit commands,
file positions get wrong. The script below will show:


---cut-here---
#!/usr/bin/perl

use strict;
use warnings;

use Getopt::Std;

our ($opt_s,$opt_w);
getopts("sw");

select STDERR; $|=1;
select STDOUT; $|=1;

open F, "<".$ARGV[0];

my $s;
my $t;

while ($s=read(F,$_,1024)) {
$t+=$s;
my $tell=tell F;
seek(F,0,1) if $opt_s; # work around to solve the problem
print "read: $s, total: $t, position: $tell\n";
my $f=fork;
if (defined($f) and $f == 0) {
sleep 10 if $opt_w; # this delay hides the problem.
exit(0);
}
}

1 while ( wait != -1);

---cut-here---

if I run this test:

[salva@sws0045eu:~]$ testfork.pl /bin/ls
read: 1024, total: 1024, position: 1024
read: 1024, total: 2048, position: -5120
read: 1024, total: 3072, position: -4096
read: 1024, total: 4096, position: -3072
read: 1024, total: 5120, position: -2048
read: 1024, total: 6144, position: -1024
read: 1024, total: 7168, position: 0
read: 1024, total: 8192, position: 1024
read: 1024, total: 9216, position: 2048
read: 1024, total: 10240, position: 3072
read: 1024, total: 11264, position: 4096
read: 1024, total: 12288, position: 5120
read: 1024, total: 13312, position: 6144
read: 1024, total: 14336, position: 7168
read: 1024, total: 15360, position: 8192
read: 1024, total: 16384, position: 9216
read: 1024, total: 17408, position: 10240
read: 1024, total: 18432, position: 11264
read: 1024, total: 19456, position: 12288
read: 1024, total: 20480, position: 13312
read: 1024, total: 21504, position: 14336
read: 1024, total: 22528, position: 15360
read: 1024, total: 23552, position: 16384
read: 1024, total: 24576, position: 17408
read: 32, total: 24608, position: 17440

As you can see the file position reported by the tell command gets
wrong after the first fork.

If I do a seek to the current position with "seek(F,0,SEEK_CUR)" the
problem disappears:

[salva@sws0045eu:~]$ testfork.pl -s /bin/ls
read: 1024, total: 1024, position: 1024
read: 1024, total: 2048, position: 2048
read: 1024, total: 3072, position: 3072
read: 1024, total: 4096, position: 4096
read: 1024, total: 5120, position: 5120
read: 1024, total: 6144, position: 6144
read: 1024, total: 7168, position: 7168
read: 1024, total: 8192, position: 8192
read: 1024, total: 9216, position: 9216
read: 1024, total: 10240, position: 10240
read: 1024, total: 11264, position: 11264
read: 1024, total: 12288, position: 12288
read: 1024, total: 13312, position: 13312
read: 1024, total: 14336, position: 14336
read: 1024, total: 15360, position: 15360
read: 1024, total: 16384, position: 16384
read: 1024, total: 17408, position: 17408
read: 32, total: 17440, position: 17440

Delaying the 'exit' call, everything works ok too, so the problems
seems to be between 'exit' doing something to open files and 'read'
letting the file state in an inconsistent way.

I have tried this script with the current perl 5.7.0 development version
obtaining the same result.


Bye,

- Salva


[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
category=core
severity=medium
---
Site configuration information for perl v5.6.0:

Configured by root at Mon Jul 24 21:57:26 BST 2000.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
Platform:
osname=solaris, osvers=2.6, archname=sun4-solaris
uname='sunos sfile01eu 5.6 generic_105181-21 sun4u sparc
sunw,ultra-4 '
config_args='-Dprefix=/apps/perl/std -Dcc=gcc
-Dperladmin=sampo@iki.fi -des'
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
useperlio=undef d_sfio=undef uselargefiles=define
use64bitint=undef use64bitall=undef uselongdouble=undef
usesocks=undef
Compiler:
cc='gcc', optimize='-O', gccversion=2.95.2 19991024 (release)
cppflags='-fno-strict-aliasing -I/usr/local/include'
ccflags ='-fno-strict-aliasing -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
stdchar='unsigned char', d_stdstdio=define, usevfork=false
intsize=4, longsize=4, ptrsize=4, doublesize=8
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=8, usemymalloc=y, prototype=define
Linker and Libraries:
ld='gcc', ldflags =' -L/usr/local/lib '
libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib
libs=-lsocket -lnsl -ldl -lm -lc -lcrypt -lsec
libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib'

Locally applied patches:


---
@INC for perl v5.6.0:
/home/salva
/home/salva/apache
/home/salva/lib/5.6.0/sun4-solaris
/home/salva/lib/5.6.0/sun4-solaris
/home/salva/lib/5.6.0
/home/salva/lib/site_perl/5.6.0/sun4-solaris
/home/salva/lib/site_perl/5.6.0/sun4-solaris
/home/salva/lib/site_perl/5.6.0
/home/salva/lib/site_perl/5.6.0/sun4-solaris
/home/salva/lib/site_perl/5.6.0
/home/salva/lib/site_perl
/home/salva/apache/lib/5.6.0/sun4-solaris
/home/salva/apache/lib/5.6.0/sun4-solaris
/home/salva/apache/lib/5.6.0
/home/salva/apache/lib/site_perl/5.6.0/sun4-solaris
/home/salva/apache/lib/site_perl/5.6.0/sun4-solaris
/home/salva/apache/lib/site_perl/5.6.0
/home/salva/apache/lib/site_perl/5.6.0/sun4-solaris
/home/salva/apache/lib/site_perl/5.6.0
/home/salva/apache/lib/site_perl
/apps/perl/std/lib/5.6.0/sun4-solaris
/apps/perl/std/lib/5.6.0
/apps/perl/std/lib/site_perl/5.6.0/sun4-solaris
/apps/perl/std/lib/site_perl/5.6.0
/apps/perl/std/lib/site_perl
.

---
Environment for perl v5.6.0:
HOME=/home/salva
LANG=en_UK
LANGUAGE (unset)
LC_COLLATE=en_UK
LC_CTYPE=en_UK
LC_MESSAGES=C
LC_MONETARY=en_UK
LC_NUMERIC=en_UK
LC_TIME=en_UK
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PERL5LIB=/home/salva:/home/salva/apache:\
/home/salva/lib/5.6.0/sun4-solaris:/home/salva/lib/5.6.0:\
/home/salva/lib/site_perl/5.6.0/sun4-solaris:\
/home/salva/lib/site_perl/5.6.0:/home/salva/lib/site_perl:\

/home/salva/apache/lib/5.6.0/sun4-solaris:/home/salva/apache/lib/5.6.0:\
/home/salva/apache/lib/site_perl/5.6.0/sun4-solaris:\

/home/salva/apache/lib/site_perl/5.6.0:/home/salva/apache/lib/site_perl
PERL_BADLANG (unset)
SHELL=/opt/VIZZutil/bin/bash


**********************************************************************
This message contains confidential information and is intended only
for the individual named. If you are not the named addressee you
should not disseminate, distribute or copy this e-mail: to do so could be
a breach of confidence. Please notify us immediately by reply e-mail and
then delete this e-mail from your system. Please contact our IT Helpdesk
on +44 (0) 20 8228 5157 or e-mail ithelpdesk@corp.vizzavi.net if you need
assistance.

E-mail transmission cannot be guaranteed to be secure or error-free
as information could be intercepted, corrupted, lost, destroyed, arrive
late or incomplete or contain viruses. The sender therefore does not
accept liability for any errors or omissions in the contents of this message
which arise as a result of e-mail transmission. If verification is required
please request a hard-copy version. This message is provided for informational
purposes and should not be construed as a solicitation or offer to buy or sell
any securities or related financial instruments.

Vizzavi Limited
Registered office - The Courtyard, 2-4 London Road, Newbury,
Berkshire RG14 1JX, England. Registered in England No. 04017435

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl5-porters @
categoriesperl
postedMar 9, '01 at 4:16p
activeMar 9, '01 at 4:16p
posts1
users1
websiteperl.org

1 user in discussion

Salvador Fandino: 1 post

People

Translate

site design / logo © 2022 Grokbase