From nobody@FreeBSD.org  Wed Oct 24 21:18:21 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 9A212ED2
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 24 Oct 2012 21:18:21 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 6A4838FC12
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 24 Oct 2012 21:18:21 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id q9OLIL5e051383
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 24 Oct 2012 21:18:21 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id q9OLIL65051382;
	Wed, 24 Oct 2012 21:18:21 GMT
	(envelope-from nobody)
Message-Id: <201210242118.q9OLIL65051382@red.freebsd.org>
Date: Wed, 24 Oct 2012 21:18:21 GMT
From: Mark Johnston <markjdb@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [mv][patch] don't prompt the user if stdin isn't a TTY
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         173039
>Category:       bin
>Synopsis:       [patch] mv(1): don't prompt the user if stdin isn't a TTY
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    eadler
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Oct 24 21:20:01 UTC 2012
>Closed-Date:    Mon Nov 26 05:14:16 UTC 2012
>Last-Modified:  Mon Nov 26 05:14:16 UTC 2012
>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:
Responsible-Changed-From-To: freebsd-bugs->eadler 
Responsible-Changed-By: eadler 
Responsible-Changed-When: Wed Oct 24 21:24:36 UTC 2012 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=173039 
State-Changed-From-To: open->analyzed 
State-Changed-By: eadler 
State-Changed-When: Thu Oct 25 23:36:44 UTC 2012 
State-Changed-Why:  
awaiting approval or review prior to commit (no action needed from 
submitter) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=173039 
State-Changed-From-To: analyzed->patched 
State-Changed-By: eadler 
State-Changed-When: Thu Nov 15 18:34:34 UTC 2012 
State-Changed-Why:  
committed 

http://www.freebsd.org/cgi/query-pr.cgi?pr=173039 
State-Changed-From-To: patched->closed 
State-Changed-By: eadler 
State-Changed-When: Mon Nov 26 05:14:15 UTC 2012 
State-Changed-Why:  
r243557 r243555 r243556  MFC 

http://www.freebsd.org/cgi/query-pr.cgi?pr=173039 
>Unformatted:
