Date: 6 Jul 2000 23:44:32 +0000 From: lyonsm@netbistro.com To: FreeBSD-gnats-submit@freebsd.org Subject: bin/19748: fetch -o clobbers special files Message-ID: <20000706234432.925.qmail@cr280808-a.crdva1.bc.wave.home.com>
next in thread | raw e-mail | index | archive | help
>Number: 19748 >Category: bin >Synopsis: fetch -o will unlink special files >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Jul 07 00:30:01 PDT 2000 >Closed-Date: >Last-Modified: >Originator: M Lyons >Release: FreeBSD 4.0-RELEASE i386 >Organization: >Environment: >Description: (This is arguably a change-request and not a sw-bug.) In some circumstances, fetch -o will unlink the target file if a transfer fails. It's true that this behaviour can be suppressed with the -R switch; however, fetch should probably never unlink special files or files it didn't create (or other people who use fetch -o/dev/null in a script might find themselves wondering why /dev/null keeps disappearing. :) >How-To-Repeat: As root, fetch an unreachable address to /dev/null, and then kill with SIGINT before it times out: # cp -Rp /dev/null /tmp/mynull # fetch -o/tmp/mynull http://1.2.3.4/foo (wait a few sec, then hit CTRL-C) # ls -l /tmp/mynull (it's gone!) >Fix: The following patch to src/usr.bin/fetch/util.c makes fetch more careful about unlinking special files. A better fix might be to have fetch decline to unlink files it didn't create. *** util.c.orig Thu Jul 6 23:08:10 2000 --- util.c Thu Jul 6 23:23:53 2000 *************** *** 29,36 **** --- 29,37 ---- * $FreeBSD: src/usr.bin/fetch/util.c,v 1.7 1999/08/28 01:00:52 peter Exp $ */ #include <sys/types.h> + #include <sys/stat.h> #include <ctype.h> #include <err.h> #include <errno.h> *************** *** 104,117 **** } /* * Delete the file when exiting on error, if it is not `precious'. */ void rm(struct fetch_state *fs) { if (!(fs->fs_outputfile[0] == '-' && fs->fs_outputfile[1] == '\0')) { ! if (!fs->fs_restart && !fs->fs_mirror && !fs->fs_precious) unlink(fs->fs_outputfile); else adjmodtime(fs); } --- 105,126 ---- } /* * Delete the file when exiting on error, if it is not `precious'. + * Files which exist and are not plain files are automatically considered + * precious. */ void rm(struct fetch_state *fs) { + int precious = fs->fs_precious; + struct stat sb; + + if(lstat(fs->fs_outputfile, &sb)) return; + if((sb.st_mode & S_IFMT) != S_IFREG) precious = 1; + if (!(fs->fs_outputfile[0] == '-' && fs->fs_outputfile[1] == '\0')) { ! if (!fs->fs_restart && !fs->fs_mirror && !precious) unlink(fs->fs_outputfile); else adjmodtime(fs); } >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000706234432.925.qmail>