Debian Bug report logs - #4293
mawk doesn't report an error on full filesystems

version graph

Package: mawk; Maintainer for mawk is Steve Langasek <vorlon@debian.org>; Source for mawk is src:mawk.

Reported by: Herbert Thielen <Herbert.Thielen@lpr.e-technik.tu-muenchen.de>

Date: Mon, 26 Aug 1996 15:18:01 UTC

Severity: normal

Merged with 28249

Found in versions 1.2.2-1, 1.3.3-2

Done: James Troup <james@nocrew.org>

Bug is archived. No further changes may be made.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-devel@lists.debian.org, Chris Fearnley <cjf@netaxs.com>:
Bug#4293; Package mawk. Full text and rfc822 format available.

Acknowledgement sent to Herbert Thielen <Herbert.Thielen@lpr.e-technik.tu-muenchen.de>:
New bug report received and forwarded. Copy sent to Chris Fearnley <cjf@netaxs.com>. Full text and rfc822 format available.

Message #5 received at submit@bugs.debian.org (full text, mbox):

From: Herbert Thielen <Herbert.Thielen@lpr.e-technik.tu-muenchen.de>
To: submit@bugs.debian.org
Cc: herbert.thielen@lpr.e-technik.tu-muenchen.de
Subject: mawk doesn't report an error on full filesystems
Date: Mon, 26 Aug 1996 14:43:47 +0200 (MET DST)
Package: mawk
Version: 1.2.2-1

Mawk doesn't report an error when writing to a full filesystem:

	$ mawk '{print}' < /etc/motd > /dev/full
	$ echo $?
	0

Probably no write error is catched. Gawk does it's job correct:

	$ gawk '{print}' < /etc/motd > /dev/full
	gawk: cmd. line:1: (FILENAME=- FNR=9) warning: error writing standard output (No space left on device)

Regards
	Herbert.


Information forwarded to Chris Fearnley <cjf@netaxs.com>:
Bug#4293; Package mawk. Full text and rfc822 format available.

Acknowledgement sent to remco@blaakmeer.student.utwente.nl (Remco Blaakmeer):
Extra info received and forwarded to maintainer. Copy sent to Chris Fearnley <cjf@netaxs.com>. Full text and rfc822 format available.

Message #10 received at 4293-maintonly@bugs.debian.org (full text, mbox):

From: remco@blaakmeer.student.utwente.nl (Remco Blaakmeer)
To: 4293-maintonly@bugs.debian.org
Subject: Old bugs need to be looked at
Date: Sun, 1 Feb 1998 12:22:25 +0100 (CET)
This is an automated message sent to all bugs older than one year.

This bug is very old. Please take a look at it and see if you can fix it.
If it has already been fixed, please close it.

If you have problems fixing it or if you don't have the time to fix it,
please ask the people on debian-devel@lists.debian.org for help, so that
at least the oldest bugs can be solved before Debian 2.0 is released.

Remco Blaakmeer


Merged 4293 28249. Request was from Torsten Landschoff <t.landschoff@gmx.net> to control@bugs.debian.org. Full text and rfc822 format available.

Information forwarded to debian-bugs-dist@lists.debian.org, James Troup <awkmaint@nocrew.org>:
Bug#4293; Package mawk. Full text and rfc822 format available.

Acknowledgement sent to Torsten Landschoff <t.landschoff@gmx.net>:
Extra info received and forwarded to list. Copy sent to James Troup <awkmaint@nocrew.org>. Full text and rfc822 format available.

Message #17 received at 4293@bugs.debian.org (full text, mbox):

From: Torsten Landschoff <t.landschoff@gmx.net>
To: 4293@bugs.debian.org
Cc: Christian Kurz <shorty@jupiter.rhein-neckar.de>
Subject: [PATCH] The libc is corrent, mawk is wrong
Date: Tue, 30 Mar 1999 02:44:28 +0200
Hi Folks, 

"Shorty" alias Christian Kurz pointed me towards this bug. I took the time to
do a small patch to this. I would like to comment on the messages in the BTS
concerning this bug:


                        Debian bug report logs - #4293
               mawk doesn't report an error on full filesystems
[...]

> Mawk doesn't report an error when writing to a full filesystem:
>
>         $ mawk '{print}' < /etc/motd > /dev/full
>         $ echo $?
>         0
>
> Probably no write error is catched. Gawk does it's job correct:

In fact the return value of fclose is not checked or fflush is not called
respectivly. 


                        Debian bug report logs - #28249
                        mawk doesn't check write errors

From: Anthony Towns <aj@azure.humbug.org.au>
[...]
> Hello world,
>
> Here's some sample code that demonstrates how to check this correctly
> (afaict):
>
>
> #include <stdio.h>
> #define FOO "Foo"
> int main(void) {
>         if ( strlen(FOO) + 1 != printf( "%s\n", FOO ) ) {
>                 perror( "printf" ); /* printf reported the error */
>         }
>
>         if ( EOF == fflush(stdout) ) {
>                 perror( "fflush" ); /* the output was buffered, and the
>                                      * error wasn't noticed until it was
>                                      * flushed
>                                      */
>         }
>
>         exit(0);
> }

Right. Probably it should be done that way. Problem is: I do not know where to
place the call to fflush correctly ;)

> [...]
> So to report errors in every case, programs do need to explicitly check
> *every* printf, *and* explicitly fflush before calling exit, and check
> the return value of that.

This is really needed :( That's what I have learned from this bugs. In the
past I did never check the return value of fclose - I never thought of the
buffering the library might have done...

> From: Chris Fearnley <cjf@i21.com>
> [...]
> The problem, as I discussed with the upstream author at the time of #4293,
> is that mawk doesn't flush it's buffers properly before closing them.
> Hence unless the file is greater than 4096 bytes (on Linux - other
> OSs seem to notice the problem on close and hence do not experience
> this problem with mawk - it's just a peculiarity of our libc stdlib
> buffering).

Our libc DOES notice the problem on close - at least since hamm, I do not want
to install bo to check against libc5 ;) But mawk does not check the return
value of fclose. 

Some comment on what the patch does:

1. I added a function close_error to files.c to report the problem if 
   the file can't be closed.
2. I moved the prototypes behind the type declarations because I need 
   a type declared there and I think the prototypes should be at one place.
3. I checked the return value of every fclose call (I did not do that in 
   fin.c because it closes only input streams so there should not be such 
   a problem) and called close_error accordingly.
4. This leads to an infinite loop because mawk_exit calls close_out_pipes 
   in turn which tries to close the same file again and so on...

   So I changed close_out_pipes and file_close to remove the item from the 
   list before calling close_error. This way both functions can be 
   reentered but control should not return to the previous invocation - I 
   did not think about the consequences. I guess it would not work ;)

I hope the patch is okay. Please forward it upstream if you decide to
incorporate it - there is no need to invent the wheel twice ;)

cu
    Torsten

=== PATCH FOLLOWS ===
diff -r -u mawk-1.3.3/files.c mawk-1.3.3.new/files.c
--- mawk-1.3.3/files.c	Sun Jan 14 18:14:10 1996
+++ mawk-1.3.3.new/files.c	Tue Mar 30 00:39:31 1999
@@ -61,17 +61,11 @@
 #include "memory.h"
 #include "fin.h"
 
-static FILE *PROTO(tfopen, (char *, char *)) ;
-static void PROTO(efflush, (FILE*)) ;
-static void PROTO(add_to_child_list, (int, int)) ;
-static struct child *PROTO(remove_from_child_list, (int)) ;
-extern int PROTO(isatty, (int)) ;
 
 #ifdef	V7
 #include  <sgtty.h>		/* defines FIOCLEX */
 #endif
 
-
 #ifndef	 NO_FCNTL_H
 
 #include <fcntl.h>
@@ -103,6 +97,14 @@
 
 static FILE_NODE *file_list ;
 
+/* Prototypes for local functions */
+
+static FILE *PROTO(tfopen, (char *, char *)) ;
+static void PROTO(efflush, (FILE*)) ;
+static void PROTO(add_to_child_list, (int, int)) ;
+static struct child *PROTO(remove_from_child_list, (int)) ;
+extern int PROTO(isatty, (int)) ;
+static void PROTO(close_error, (FILE_NODE *p));
 
 /* find a file on file_list */
 PTR
@@ -233,16 +235,28 @@
       if (strcmp(name, p->name->str) == 0)
       {
 	 /* found */
-	 switch (p->type)
+
+         /* Remove it from the list first because we might be called 
+            again if an error occurs leading to an infinite loop. 
+
+            Note that we don't have to consider the list corruption 
+            cause by a recursive call because it will never return. */
+
+	 q->link = p->link ;
+         file_list = dummy.link ;   /* maybe it was the first file */
+         
+         switch (p->type)
 	 {
 	    case F_TRUNC:
 	    case F_APPEND:
-	       fclose((FILE *) p->ptr) ;
+	       if( fclose((FILE *) p->ptr) != 0 )
+		  close_error(p) ;
 	       retval = 0 ;
 	       break ;
 
 	    case PIPE_OUT:
-	       fclose((FILE *) p->ptr) ;
+	       if( fclose((FILE *) p->ptr) != 0 )
+	       	  close_error(p) ;
 
 #if  HAVE_REAL_PIPES
 	       retval = wait_for(p->pid) ;
@@ -274,8 +288,8 @@
 	 }
 
 	 free_STRING(p->name) ;
-	 hold = p ;
-	 q->link = p = p->link ;
+         hold = p ;
+	 p = p->link ;
 	 ZFREE(hold) ;
       }
       else
@@ -284,7 +298,6 @@
       }
    }
 
-   file_list = dummy.link ;
    return retval ;
 }
 
@@ -364,7 +377,14 @@
    {
       if (IS_OUTPUT(p->type))
       {
-	 fclose((FILE *) p->ptr) ;   
+	 if( fclose((FILE *) p->ptr) != 0 )
+         {
+            /* if another error occurs we do not want to be called 
+               for the same file again */
+
+            file_list = p->link ;
+	    close_error(p) ;
+         }
 	 if (p->type == PIPE_OUT) wait_for(p->pid) ; 
       }
 
@@ -397,7 +417,8 @@
    {
       if (p->type == PIPE_OUT)
       {
-	 fclose(p->ptr) ;
+	 if( fclose(p->ptr) != 0 )
+	    close_error(p) ;
 	 close_fake_outpipe(p->name->str, p->pid) ;
       }
       p = p->link ;
@@ -563,18 +584,24 @@
 set_stderr()   /* and stdout */
 {
    FILE_NODE *p, *q ; 
+
+   /* We insert stderr first to get it at the end of the list. This is 
+      needed because we want to output errors encountered on closing 
+      stdout. */
    
-   p = ZMALLOC(FILE_NODE) ;
-   p->link = (FILE_NODE*) 0 ;
-   p->type = F_TRUNC ;
-   p->name = new_STRING("/dev/stdout") ;
-   p->ptr = (PTR) stdout ;
    q = ZMALLOC(FILE_NODE);
-   q->link = p ;
+   q->link = (FILE_NODE*) 0 ;
    q->type = F_TRUNC ;
    q->name = new_STRING("/dev/stderr") ;
    q->ptr = (PTR) stderr ;
-   file_list = q ;
+
+   p = ZMALLOC(FILE_NODE) ;
+   p->link = q;
+   p->type = F_TRUNC ;
+   p->name = new_STRING("/dev/stdout") ;
+   p->ptr = (PTR) stdout ;
+
+   file_list = p ;
 }
 
 /* fopen() but no buffering to ttys */
@@ -619,3 +646,13 @@
    }
 }
 #endif /* MSDOS */
+
+/* An error occured closing the file referred to by P. We tell the 
+   user and terminate the program. */
+
+static void close_error(p)
+   FILE_NODE *p ;
+{
+   errmsg(errno, "close failed on file %s", p->name->str) ;
+   mawk_exit(2) ;
+}


Information forwarded to debian-bugs-dist@lists.debian.org, James Troup <awkmaint@nocrew.org>:
Bug#4293; Package mawk. Full text and rfc822 format available.

Acknowledgement sent to Christian Kurz <shorty@debian.org>:
Extra info received and forwarded to list. Copy sent to James Troup <awkmaint@nocrew.org>. Full text and rfc822 format available.

Message #22 received at 4293@bugs.debian.org (full text, mbox):

From: Christian Kurz <shorty@debian.org>
To: 4293@bugs.debian.org
Subject: mawk
Date: Wed, 14 Apr 1999 22:44:57 +0200
Hi, 

could you please apply the patch from Torsten Landschoff and close this
bug report now? Thanks for doing so.

Cheers
       Christian
-- 
In just seven days, I can make you a man!
		-- The Rocky Horror Picture Show
/* http://www.rhein-neckar.de/~jupiter/                Stardate: 36260.5  */



Information forwarded to debian-bugs-dist@lists.debian.org, James Troup <awkmaint@nocrew.org>:
Bug#4293; Package mawk. Full text and rfc822 format available.

Acknowledgement sent to Torsten Landschoff <t.landschoff@gmx.net>:
Extra info received and forwarded to list. Copy sent to James Troup <awkmaint@nocrew.org>. Full text and rfc822 format available.

Message #27 received at 4293@bugs.debian.org (full text, mbox):

From: Torsten Landschoff <t.landschoff@gmx.net>
To: 4293@bugs.debian.org
Subject: Fixed package at www.debian.org...
Date: Sat, 5 Jun 1999 12:05:45 +0200
Hiho!

I came back to my patch to make a fixed package available. Problem:
The patch from the BTS does not apply and is some bytes bigger than my
local version. 

You can find the fix at http://www.debian.org/~torsten/qa/4293/ -
there is a new diff also.

Thanks
    Torsten


Reply sent to James Troup <james@nocrew.org>:
You have taken responsibility. Full text and rfc822 format available.

Notification sent to Herbert Thielen <Herbert.Thielen@lpr.e-technik.tu-muenchen.de>:
Bug acknowledged by developer. Full text and rfc822 format available.

Message #32 received at 4293-done@bugs.debian.org (full text, mbox):

From: James Troup <james@nocrew.org>
To: 4293-done@bugs.debian.org
Subject: Re: mawk doesn't report an error on full filesystems
Date: 10 Oct 1999 13:14:08 +0100
Herbert Thielen <Herbert.Thielen@lpr.e-technik.tu-muenchen.de> writes:

> Package: mawk
> Version: 1.2.2-1
> 
> Mawk doesn't report an error when writing to a full filesystem:
> 
>         $ mawk '{print}' < /etc/motd > /dev/full
>         $ echo $?
>         0
> 
> Probably no write error is catched. Gawk does it's job correct:
> 
>         $ gawk '{print}' < /etc/motd > /dev/full
>         gawk: cmd. line:1: (FILENAME=- FNR=9) warning: error writing standard output (No space left on device)

Fixed by a patch from Torsten Landschoff in mawk 1.3.3-3.

-- 
James


Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Fri Apr 18 03:50:56 2014; Machine Name: buxtehude.debian.org

Debian Bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.