Subject: bin/957: compress + fdesc mount broken; fix included
To: None <gnats-admin@NetBSD.ORG>
From: Lon Willett <willett@math.utah.edu>
List: netbsd-bugs
Date: 04/11/1995 08:05:32
>Number:         957
>Category:       bin
>Synopsis:       compress + fdesc mount broken
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Apr 11 08:05:06 1995
>Originator:     Lon Willett
>Organization:
none
>Release:        7 Apr 95
>Environment:

NetBSD-current/{sparc,i386}

>Description:

	When compress/uncompress has its output redirected, it
	internally just sets the output file name to "/dev/stdout".
	This works fine if "/dev/stdout" is a character device, but
	if you use the "fdesc" file system, then /dev/stdout is just
	a symlink to "/dev/fd/1", which takes on the type of the
	actual target.  So compress will *always* ask if you really
	want to overwrite the file (which has already been truncated
	by then).

	Among other things, this completely breaks the "X11R6" build.

>How-To-Repeat:

	mount -t fdesc -o union fdesc /dev
	compress < SOMETHING > /tmp/foo
	# Compress asks you if you really want to overwrite "/dev/stdout".

>Fix:

	The easy workaround is to just not use the "fdesc" filesystem.

	The following patch will make "compress" work with the "fdesc"
	filesystem, but it is rather a kludge.  There are cleaner ways
	of handling this (e.g. compress doesn't really need to use
	"/dev/stdout" at all, and so probably shouldn't relie on it).

--- src/usr.bin/compress/compress.c.orig	Sun Mar 26 04:24:18 1995
+++ src/usr.bin/compress/compress.c	Thu Apr  6 08:08:31 1995
@@ -178,7 +178,8 @@
 	u_char buf[1024];
 
 	exists = !stat(out, &sb);
-	if (!force && exists && S_ISREG(sb.st_mode) && !permission(out))
+	if (!force && exists && S_ISREG(sb.st_mode) &&
+	    strcmp ("/dev/stdout", out) && !permission(out))
 		return;
 	isreg = oreg = !exists || S_ISREG(sb.st_mode);
 
@@ -268,7 +269,8 @@
 	u_char buf[1024];
 
 	exists = !stat(out, &sb);
-	if (!force && exists && S_ISREG(sb.st_mode) && !permission(out))
+	if (!force && exists && S_ISREG(sb.st_mode) &&
+	    strcmp ("/dev/stdout", out) && !permission(out))
 		return;
 	isreg = oreg = !exists || S_ISREG(sb.st_mode);
 
------------------------------------------------------------------------
>Audit-Trail:
>Unformatted: