Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncate does not flush the output buffer before truncating the file. #990

Closed
p5pRT opened this issue Dec 24, 1999 · 8 comments
Closed

Truncate does not flush the output buffer before truncating the file. #990

p5pRT opened this issue Dec 24, 1999 · 8 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 24, 1999

Migrated from rt.perl.org#1939 (status was 'resolved')

Searchable as RT1939$

@p5pRT
Copy link
Author

p5pRT commented Dec 24, 1999

From lim@ds9.actcom.co.il

Created by lim@israel.net

This is a bug report for perl from lim@​israel.net,
generated with the help of perlbug 1.26 running under perl 5.00503.

-----------------------------------------------------------------
While using the truncate on file opened for writing, output buffer is not
flushed out before truncating the file, thus when files is closed the
buffer data goes to the end of the new file and it's size differs from
one that was given to truncate. See perl example below, and the trace of
sys-calls (note first ftrucncate and than write - I guess write is
initiated by close). OUT will be 400 bytes and not 200 as intended.

#!/usr/local/bin/perl5

open(OUT, ">OUT") || die "Can't open OUT​: $!\n";
print OUT "x\n"x200;
truncate(OUT, 2*200 - 200) || die "Can't truncate OUT​: $!\n";
close(OUT) || die "Can't close OUT";

Trace​:
...
sniped
...
open("OUT", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
fstat(3, {st_mode=S_IFREG|0664, st_size=0, ...}) = 0
fcntl(3, F_SETFD, FD_CLOEXEC) = 0
fstat(3, {st_mode=S_IFREG|0664, st_size=0, ...}) = 0
mmap(0, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40013000
ftruncate(3, 200) = 0
write(3, "x\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\n"..., 400) = 400
close(3) = 0
munmap(0x40013000, 4096) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
_exit(0) = ?

Leonid Igolnik
Software Developer.
ACTCOM - Active Communications ltd.

Perl Info


Site configuration information for perl 5.00503:

Configured by root at Mon Aug 30 23:08:56 EDT 1999.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
  Platform:
    osname=linux, osvers=2.2.5-22smp, archname=i386-linux
    uname='linux porky.devel.redhat.com 2.2.5-22smp #1 smp wed jun 2 09:11:51 edt 1999 i686 unknown '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
  Compiler:
    cc='cc', optimize='-O2', gccversion=egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
    cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    stdchar='char', d_stdstdio=undef, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -ldl -lm -lc -lposix -lcrypt
    libc=, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl 5.00503:
    /usr/lib/perl5/5.00503/i386-linux
    /usr/lib/perl5/5.00503
    /usr/lib/perl5/site_perl/5.005/i386-linux
    /usr/lib/perl5/site_perl/5.005
    .


Environment for perl 5.00503:
    HOME=/home/lim
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/X11R6/bin:/usr/sbin:/sbin:/opt/kde/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/local/bin:/opt/bin:/usr/X11R6/bin:/home/lim/bin:/usr/X11R6/bin:/home/lim/bin=
    PERL_BADLANG (unset)
    SHELL=/bin/tcsh


Site configuration information for perl 5.00503:

Configured by root at Mon Aug 30 23:08:56 EDT 1999.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
  Platform:
    osname=linux, osvers=2.2.5-22smp, archname=i386-linux
    uname='linux porky.devel.redhat.com 2.2.5-22smp #1 smp wed jun 2 09:11:51 edt 1999 i686 unknown '
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
  Compiler:
    cc='cc', optimize='-O2', gccversion=egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
    cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    stdchar='char', d_stdstdio=undef, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -ldl -lm -lc -lposix -lcrypt
    libc=, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl 5.00503:
    /usr/lib/perl5/5.00503/i386-linux
    /usr/lib/perl5/5.00503
    /usr/lib/perl5/site_perl/5.005/i386-linux
    /usr/lib/perl5/site_perl/5.005
    .


Environment for perl 5.00503:
    HOME=/home/lim
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/X11R6/bin:/usr/sbin:/sbin:/opt/kde/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/local/bin:/opt/bin:/usr/X11R6/bin:/home/lim/bin:/usr/X11R6/bin:/home/lim/bin=
    PERL_BADLANG (unset)
    SHELL=/bin/tcsh

@p5pRT
Copy link
Author

p5pRT commented Dec 25, 1999

From [Unknown Contact. See original ticket]

lim@​ds9.actcom.co.il writes​:

While using the truncate on file opened for writing, output buffer is not
flushed out before truncating the file,

Last time this was reported I suggested that Perl should
auto-flush/seek/whatever things between buffered/unbuffered ops and
between read/write ops on the same filehandle.

The result is nil.

Hope this helps,
Ilya

@p5pRT
Copy link
Author

p5pRT commented Dec 27, 1999

From [Unknown Contact. See original ticket]

Ilya Zakharevich <ilya@​math.ohio-state.edu> writes​:

lim@​ds9.actcom.co.il writes​:

While using the truncate on file opened for writing, output buffer is not
flushed out before truncating the file,

Last time this was reported I suggested that Perl should
auto-flush/seek/whatever things between buffered/unbuffered ops and
between read/write ops on the same filehandle.

The result is nil.

I thought p5p agreed it made sense, and that SIFO did (it to some extent)
already. We just have not done it yet.

--
Nick Ing-Simmons

@p5pRT
Copy link
Author

p5pRT commented Dec 27, 1999

From [Unknown Contact. See original ticket]

On Mon, Dec 27, 1999 at 08​:58​:14PM +0000, Nick Ing-Simmons wrote​:

Last time this was reported I suggested that Perl should
auto-flush/seek/whatever things between buffered/unbuffered ops and
between read/write ops on the same filehandle.

The result is nil.

I thought p5p agreed it made sense, and that SIFO did (it to some extent)
already. We just have not done it yet.

Glad to hear that there is some progress. However, I do not
*remember* any progress. What exactly do you mean? Are there flags
on a filehandle "buffer may be active", "last action was write/read"?
[I do not understand how something may be done without these flags.]

Ilya

@p5pRT
Copy link
Author

p5pRT commented Dec 29, 1999

From [Unknown Contact. See original ticket]

Ilya Zakharevich <ilya@​math.ohio-state.edu> writes​:

On Mon, Dec 27, 1999 at 08​:58​:14PM +0000, Nick Ing-Simmons wrote​:

Last time this was reported I suggested that Perl should
auto-flush/seek/whatever things between buffered/unbuffered ops and
between read/write ops on the same filehandle.

The result is nil.

I thought p5p agreed it made sense, and that SIFO did (it to some extent)
already. We just have not done it yet.

Glad to hear that there is some progress. However, I do not
*remember* any progress. What exactly do you mean? Are there flags
on a filehandle "buffer may be active", "last action was write/read"?
[I do not understand how something may be done without these flags.]

SFIO's equivalent of FILE * does indeed have those flags.
So iff PerlIO == SFIO so does perl - but I mean the 'and only if' :-(

--
Nick Ing-Simmons

@p5pRT
Copy link
Author

p5pRT commented Jan 4, 2000

From [Unknown Contact. See original ticket]

On Wed, Dec 29, 1999 at 10​:22​:41PM +0000, Nick Ing-Simmons wrote​:

I thought p5p agreed it made sense, and that SIFO did (it to some extent)
already. We just have not done it yet.

Glad to hear that there is some progress. However, I do not
*remember* any progress. What exactly do you mean? Are there flags
on a filehandle "buffer may be active", "last action was write/read"?
[I do not understand how something may be done without these flags.]

SFIO's equivalent of FILE * does indeed have those flags.
So iff PerlIO == SFIO so does perl - but I mean the 'and only if' :-(

Since we have an IO level *above* SFIO, and the read/write flags
should be active on sysread/syswrite operations too, so we need to
able to freely check/set/reset these flags, SvIO (sp?) is where the
flags should be stored. (Of course, add "IMO" wherever appropriate.)

Ilya

@p5pRT
Copy link
Author

p5pRT commented Jan 4, 2000

From [Unknown Contact. See original ticket]

Ilya Zakharevich <ilya@​math.ohio-state.edu> writes​:

On Wed, Dec 29, 1999 at 10​:22​:41PM +0000, Nick Ing-Simmons wrote​:

I thought p5p agreed it made sense, and that SIFO did (it to some extent)
already. We just have not done it yet.

Glad to hear that there is some progress. However, I do not
*remember* any progress. What exactly do you mean? Are there flags
on a filehandle "buffer may be active", "last action was write/read"?
[I do not understand how something may be done without these flags.]

SFIO's equivalent of FILE * does indeed have those flags.
So iff PerlIO == SFIO so does perl - but I mean the 'and only if' :-(

Since we have an IO level *above* SFIO, and the read/write flags
should be active on sysread/syswrite operations too, so we need to
able to freely check/set/reset these flags, SvIO (sp?) is where the
flags should be stored. (Of course, add "IMO" wherever appropriate.)

I think 'my opinion' aligns with yours in this. But noone has added
those flags yet.

It is far from clear that the "level *above*" is
necessary - i.e. we could roll all the SFIO/STDIO features we need
into PerlIO or SvIO and then only ever call open/read/write/lseek/close
+ (recv,send,...)

Ilya
--
Nick Ing-Simmons <nik@​tiuk.ti.com>
Via, but not speaking for​: Texas Instruments Ltd.

@p5pRT
Copy link
Author

p5pRT commented Jan 4, 2000

From @TimToady

Nick Ing-Simmons writes​:
: It is far from clear that the "level *above*" is
: necessary - i.e. we could roll all the SFIO/STDIO features we need
: into PerlIO or SvIO and then only ever call open/read/write/lseek/close
: + (recv,send,...)

I also think this is where we'll end up. Er, not up.

Someone just needs to up and do it. Er...

Larry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant