From owner-freebsd-bugs@FreeBSD.ORG Wed Oct 24 21:20:02 2012 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 0779AEED for ; Wed, 24 Oct 2012 21:20:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.FreeBSD.org [8.8.178.135]) by mx1.freebsd.org (Postfix) with ESMTP id D35FE8FC14 for ; Wed, 24 Oct 2012 21:20:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q9OLK1c0070288 for ; Wed, 24 Oct 2012 21:20:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q9OLK10N070287; Wed, 24 Oct 2012 21:20:01 GMT (envelope-from gnats) Resent-Date: Wed, 24 Oct 2012 21:20:01 GMT Resent-Message-Id: <201210242120.q9OLK10N070287@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Mark Johnston Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 9A212ED2 for ; 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 ; 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 ; 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 To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Subject: bin/173039: [mv][patch] don't prompt the user if stdin isn't a TTY X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Oct 2012 21:20:02 -0000 >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: