From xemacs-m  Mon Dec 16 19:21:51 1996
Received: from altair.xemacs.org (steve@xemacs.miranova.com [206.190.83.19]) by xemacs.cs.uiuc.edu (8.8.3/8.8.3) with ESMTP id TAA28158 for <xemacs-beta@xemacs.org>; Mon, 16 Dec 1996 19:21:44 -0600 (CST)
Received: (from steve@localhost)
          by altair.xemacs.org (8.8.4/8.8.4)
	  id RAA00974; Mon, 16 Dec 1996 17:31:42 -0800
Sender: steve@xemacs.org
To: xemacs-beta@xemacs.org
Subject: Re: Writing at end of disk -- critical XEmacs bug
References: <m2n2ve3ul0.fsf@altair.xemacs.org> <m2k9qi3sje.fsf@altair.xemacs.org> <rvvia256ax.fsf@sdnp5.ucsd.edu>
X-Url: http://www.miranova.com/%7Esteve/
Mail-Copies-To: never
X-Face: #!T9!#9s-3o8)*uHlX{Ug[xW7E7Wr!*L46-OxqMu\xz23v|R9q}lH?cRS{rCNe^'[`^sr5"
 f8*@r4ipO6Jl!:Ccq<xoV[Qz2u8<8-+Vwf2gzJ44lf_/y9OaQ`@#Q65{U4/TC)i2`~/M&QI$X>p:9I
 OSS'2{-)-4wBnVeg0S\O4Al@)uC[pD|+
X-Attribution: sb
From: Steven L Baur <steve@miranova.com>
In-Reply-To: David Moore's message of 16 Dec 1996 17:05:26 -0800
Mime-Version: 1.0 (generated by tm-edit 7.96)
Content-Type: text/plain; charset=US-ASCII
Date: 16 Dec 1996 17:31:42 -0800
Message-ID: <m2916y3qip.fsf@altair.xemacs.org>
Lines: 75
X-Mailer: Red Gnus v0.72/XEmacs 19.15

>>>>> "David" == David Moore <dmoore@UCSD.EDU> writes:

David> 	Well, it's not a bug that it doesn't explicitly return -1
David> there, since some streams (like sockets) will return a short
David> write count, without it meaning anything is wrong.  You are
David> simply expected to try writing again.

O.K.

David> 	When it falls into that case, it updates the remaining count
David> and loops back up for another attempt to write it out.  In the
David> case of your disk, that second pass should be failing on the
David> write which causes the -1 to be returned.  Is the write() call
David> returning 0 on that second pass?

It does indeed end up returning -1.  So far so good.  Going back up we
end up in Lstream_close.

The exit status of Lstream_pseudo_close is ignored.  It could be the
fix is nothing more than saving the return result of
Lstream_pseudo_close and returning that at the end.  I notice that the
call to lstr->imp->closer succeeds.

Proposed patch is in brackets.

int
Lstream_close (Lstream *lstr)
{
[ int rc = 0; ]
  if (lstr->flags & LSTREAM_FL_IS_OPEN)
    {
      /* don't return here on error, or file descriptor leak will result. */
      [ rc = ] Lstream_pseudo_close (lstr);
      if (lstr->imp->closer)
	{
	  if ((lstr->imp->closer) (lstr) < 0)
	    return -1;
	}
    }

  lstr->flags &= ~LSTREAM_FL_IS_OPEN;
  lstr->byte_count = 0;
  /* Note that Lstream_flush() reset all the buffer indices.  That way,
     the next call to Lstream_putc(), Lstream_getc(), or Lstream_ungetc()
     on a closed stream will call into the function equivalents, which will
     cause an error. */

  /* We set the pointers to 0 so that we don't lose when this function
     is called more than once on the same object */
  if (lstr->out_buffer)
    {
      xfree (lstr->out_buffer);
      lstr->out_buffer = 0;
    }
  if (lstr->in_buffer)
    {
      xfree (lstr->in_buffer);
      lstr->in_buffer = 0;
    }
  if (lstr->unget_buffer)
    {
      xfree (lstr->unget_buffer);
      lstr->unget_buffer = 0;
    }

[ return rc; ]
  return 0;
}


-- 
steve@miranova.com baur
Unsolicited commercial e-mail will be billed at $250/message.
"That Bill Clinton.  He probably doesn't know how to log on to the
Internet."  -- Rush Limbaugh, noted Computer Expert

