Date: Wed, 24 Oct 2012 21:18:21 GMT From: Mark Johnston <markjdb@gmail.com> To: freebsd-gnats-submit@FreeBSD.org Subject: bin/173039: [mv][patch] don't prompt the user if stdin isn't a TTY Message-ID: <201210242118.q9OLIL65051382@red.freebsd.org> Resent-Message-ID: <201210242120.q9OLK10N070287@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 173039 >Category: bin >Synopsis: [mv][patch] don't prompt the user if stdin isn't a TTY >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: Wed Oct 24 21:20:01 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Mark Johnston >Release: CURRENT >Organization: >Environment: FreeBSD oddish.laptop 10.0-CURRENT FreeBSD 10.0-CURRENT #13 r240519+3cc2dea-dirty: Sat Sep 15 22:29:45 EDT 2012 mark@oddish.laptop:/usr/obj/usr/home/mark/src/freebsd/sys/GENERIC amd64 >Description: According to POSIX, when the dst file already exists, mv(1) should only prompt the user if -i is specified, or if the file isn't writable and stdin is a terminal. FreeBSD's mv(1) doesn't check this latter condition and exits early when it receives EOF from the "user." This is "step 1" in the POSIX description of mv: If the destination path exists, the -f option is not specified, and either of the following conditions is true: - The permissions of the destination path do not permit writing and the standard input is a terminal. - The -i option is specified. the mv utility shall write a prompt to standard error and read a line from standard input. If the response is not affirmative, mv shall do nothing more with the current source_file and go on to any remaining source_files. >How-To-Repeat: $ alias mv=mv # just in case mv is aliased to mv -i $ touch foo1 foo2 $ chmod a-w foo2 $ mv foo1 foo2 0>/dev/null override r--r--r-- mark/mark for foo2? (y/n [n]) not overwritten $ ls foo1 foo1 $ On NetBSD and Linux, mv(1) continues and renames foo1 to foo2. >Fix: Apply the attached patch. Patch attached with submission follows: diff --git a/bin/mv/mv.c b/bin/mv/mv.c index d33b28d..5147a2db 100644 --- a/bin/mv/mv.c +++ b/bin/mv/mv.c @@ -199,7 +199,7 @@ do_move(const char *from, const char *to) } else if (iflg) { (void)fprintf(stderr, "overwrite %s? %s", to, YESNO); ask = 1; - } else if (access(to, W_OK) && !stat(to, &sb)) { + } else if (access(to, W_OK) && !stat(to, &sb) && isatty(STDIN_FILENO)) { strmode(sb.st_mode, modep); (void)fprintf(stderr, "override %s%s%s/%s for %s? %s", modep + 1, modep[9] == ' ' ? "" : " ", >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201210242118.q9OLIL65051382>