Date: Tue, 7 Jul 1998 15:37:39 -0700 (PDT) From: bmah@ca.sandia.gov To: FreeBSD-gnats-submit@FreeBSD.ORG Subject: bin/7203: [PATCH] fetch -o - file:/path/name doesn't go to stdout Message-ID: <199807072237.PAA09782@vinson.ca.sandia.gov>
index | next in thread | raw e-mail
>Number: 7203
>Category: bin
>Synopsis: [PATCH] fetch -o - file:/path/name doesn't go to stdout
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Tue Jul 7 15:40:01 PDT 1998
>Last-Modified:
>Originator: Bruce A. Mah
>Organization:
Sandia National Laboratories
>Release: FreeBSD 2.2.6-RELEASE i386
>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 {
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199807072237.PAA09782>
