From bmah@vinson.ca.sandia.gov  Tue Jul  7 15:38:08 1998
Received: from vinson.ca.sandia.gov (vinson.ca.sandia.gov [146.246.243.200])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id PAA13450
          for <FreeBSD-gnats-submit@freebsd.org>; Tue, 7 Jul 1998 15:38:07 -0700 (PDT)
          (envelope-from bmah@vinson.ca.sandia.gov)
Received: (from bmah@localhost)
	by vinson.ca.sandia.gov (8.8.8/8.8.8) id PAA09782;
	Tue, 7 Jul 1998 15:37:39 -0700 (PDT)
	(envelope-from bmah)
Message-Id: <199807072237.PAA09782@vinson.ca.sandia.gov>
Date: Tue, 7 Jul 1998 15:37:39 -0700 (PDT)
From: bmah@ca.sandia.gov
Reply-To: bmah@ca.sandia.gov
To: FreeBSD-gnats-submit@freebsd.org
Subject: [PATCH] fetch -o - file:/path/name doesn't go to stdout
X-Send-Pr-Version: 3.2

>Number:         7203
>Category:       bin
>Synopsis:       [PATCH] fetch -o - file:/path/name doesn't go to stdout
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    des
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jul  7 15:40:01 PDT 1998
>Closed-Date:    Wed Sep 16 17:20:15 PDT 1998
>Last-Modified:  Wed Sep 16 17:20:49 PDT 1998
>Originator:     Bruce A. Mah
>Release:        FreeBSD 2.2.6-RELEASE i386
>Organization:
Sandia National Laboratories
>Environment:

Observed on 2.2.6-RELEASE, but it appears that all versions of fetch(1)
in the CVS tree have this problem.

>Description:

"fetch -o - url://file/name" generally retrieves the URL to stdout.  
However, in the case of "file:/" URLs, fetch(1) creates a file called 
"-" in the current directory, containing the file contents.

>How-To-Repeat:

fetch -o - /etc/hosts
cat ./-

>Fix:
	
*** fetch.h.orig	Tue Jul  7 15:06:41 1998
--- fetch.h	Tue Jul  7 15:06:55 1998
***************
*** 36,41 ****
--- 36,42 ----
  #define BUFFER_SIZE 1024
  #define	FETCH_VERSION "fetch/1.0"
  #define PATH_CP "/bin/cp"
+ #define PATH_CAT "/bin/cat"
  
  struct fetch_state {
  	const char *fs_status;
*** file.c.orig	Tue Jul  7 15:07:56 1998
--- file.c	Tue Jul  7 15:13:18 1998
***************
*** 98,112 ****
  file_retrieve(struct fetch_state *fs)
  {
  	struct stat sb;
  
! 	/* XXX - this seems bogus to me! */
! 	if (access(fs->fs_outputfile, F_OK) == 0) {
! 		errno = EEXIST;
! 		warn("%s", fs->fs_outputfile);
! 		return EX_USAGE;
  	}
  
! 	if (fs->fs_linkfile) {
  		fs->fs_status = "checking path";
  		if (stat(fs->fs_proto, &sb) == -1) {
  			warn("non-unexistent");
--- 98,116 ----
  file_retrieve(struct fetch_state *fs)
  {
  	struct stat sb;
+ 	int to_stdout;
  
! 	to_stdout = (strcmp(fs->fs_outputfile, "-") == 0);
! 	if (!to_stdout) {
! 		/* XXX - this seems bogus to me! */
! 		if (access(fs->fs_outputfile, F_OK) == 0) {
! 			errno = EEXIST;
! 			warn("%s", fs->fs_outputfile);
! 			return EX_USAGE;
! 		}
  	}
  
! 	if ((fs->fs_linkfile) && (!to_stdout)) {
  		fs->fs_status = "checking path";
  		if (stat(fs->fs_proto, &sb) == -1) {
  			warn("non-unexistent");
***************
*** 128,136 ****
  			warn("fork");
  			return EX_TEMPFAIL;
  		} else if (pid == 0) {
! 			execl(PATH_CP, "cp", "-p", fs->fs_proto, 
! 			      fs->fs_outputfile, (char *)0);
! 			warn("execl: " PATH_CP);
  			fflush(stderr);
  			_exit(EX_OSERR);
  		} else {
--- 132,146 ----
  			warn("fork");
  			return EX_TEMPFAIL;
  		} else if (pid == 0) {
! 			if (to_stdout) {
! 				execl(PATH_CAT, "cat", fs->fs_proto,
! 				      (char *)0);
! 				warn("execl: " PATH_CAT);
! 			} else {
! 				execl(PATH_CP, "cp", "-p", fs->fs_proto, 
! 				      fs->fs_outputfile, (char *)0);
! 				warn("execl: " PATH_CP);
! 			}
  			fflush(stderr);
  			_exit(EX_OSERR);
  		} else {
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->suspended 
State-Changed-By: phk 
State-Changed-When: Wed Jul 8 23:25:59 PDT 1998 
State-Changed-Why:  
awaiting committer 

From: smoergrd@oslo.geco-prakla.slb.com (Dag-Erling Coidan Smrgrav)
To: bmah@ca.sandia.gov
Cc: FreeBSD-gnats-submit@freebsd.org, jkh@freebsd.org
Subject: Re: bin/7203: [PATCH] fetch -o - file:/path/name doesn't go to stdout
Date: 09 Jul 1998 14:14:08 +0200

 bmah@ca.sandia.gov writes:
 > "fetch -o - url://file/name" generally retrieves the URL to stdout.  
 > However, in the case of "file:/" URLs, fetch(1) creates a file called 
 > "-" in the current directory, containing the file contents.
 
 This is a result of fetch(1) trying to be smart instead of generic,
 and will go away when I rewrite fetch(1) to use the fetch(3) library.
 
 BTW Jordan, still no feedback from you... should I go ahead and import
 libfetch into the tree? I'm halfway through rewriting the FTP bits, if
 I get my lazy arse in gear I might finish that this weekend; then I
 can start hacking away on fetch(1)...
 
 DES
 -- 
 Dag-Erling Smrgrav - smoergrd@oslo.geco-prakla.slb.com
Responsible-Changed-From-To: freebsd-bugs->des 
Responsible-Changed-By: des 
Responsible-Changed-When: Wed Sep 16 17:00:49 PDT 1998 
Responsible-Changed-Why:  
I'll look into it (since I'm already working on fetch...) 
State-Changed-From-To: suspended->closed 
State-Changed-By: des 
State-Changed-When: Wed Sep 16 17:20:15 PDT 1998 
State-Changed-Why:  
Better fix applied to -current and -stable. 
>Unformatted:
