From owner-freebsd-bugs@FreeBSD.ORG Thu Mar 18 11:00:35 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7662716A4D7 for ; Thu, 18 Mar 2004 11:00:35 -0800 (PST) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3072A43D5A for ; Thu, 18 Mar 2004 11:00:29 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) i2IJ0Tbv098084 for ; Thu, 18 Mar 2004 11:00:29 -0800 (PST) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.10/8.12.10/Submit) id i2IJ0T0r098079; Thu, 18 Mar 2004 11:00:29 -0800 (PST) (envelope-from gnats) Resent-Date: Thu, 18 Mar 2004 11:00:29 -0800 (PST) Resent-Message-Id: <200403181900.i2IJ0T0r098079@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, Samuel Tardieu Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4063F16A4CE for ; Thu, 18 Mar 2004 10:54:00 -0800 (PST) Received: from mail.rfc1149.net (marvin.enst.fr [137.194.161.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id B529243D2D for ; Thu, 18 Mar 2004 10:53:59 -0800 (PST) (envelope-from sam@beeblebrox.rfc1149.net) Received: from beeblebrox.rfc1149.net (beeblebrox-tun.enst.fr [137.194.161.40]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (verified OK)) by mail.rfc1149.net (Postfix) with ESMTP id 5888CA8010 for ; Thu, 18 Mar 2004 19:53:58 +0100 (CET) Received: by beeblebrox.rfc1149.net (Postfix, from userid 1000) id 554EB2F1; Thu, 18 Mar 2004 19:53:55 +0100 (CET) Message-Id: <20040318185355.554EB2F1@beeblebrox.rfc1149.net> Date: Thu, 18 Mar 2004 19:53:55 +0100 (CET) From: Samuel Tardieu To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/64430: Bug in mv(1) X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Samuel Tardieu List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Mar 2004 19:00:36 -0000 >Number: 64430 >Category: bin >Synopsis: Bug in mv(1) >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Mar 18 11:00:28 PST 2004 >Closed-Date: >Last-Modified: >Originator: Samuel Tardieu >Release: FreeBSD 4.9-STABLE i386 >Organization: Avian Carrier & Friends >Environment: System: FreeBSD beeblebrox 4.9-STABLE FreeBSD 4.9-STABLE #6: Mon Mar 15 21:54:41 CET 2004 root@willow:/usr/obj/usr/src/sys/BEEBLEBROX i386 >Description: In some cases, mv is unable to move files. Four conditions must be met to have it fail as far as I can see: 1) The source must be a symlink 2) The target must be a symlink 3) The target must point onto a mounting point 4) The source and target must not be on the same filesystem In this case, mv will issue an inappropriate "cannot rename a mounting point" error. >How-To-Repeat: If /tmp is a mounting point and you are not in the /tmp filesystem, the following sequence reproduces the bug: % ln -s /tmp bbb1 % ln -s /tmp bbb2 % mv bbb1 bbb2 mv: cannot rename a mount point The expected behaviour would be to move the bbb1 symlink into /tmp, target of the bbb2 symlink, as is done for any other kind of source or destination. >Fix: The following patch fixes that. --- mv-old/mv.c 2004-03-18 19:44:53.000000000 +0100 +++ mv-new/mv.c 2004-03-18 19:44:53.000000000 +0100 @@ -212,6 +212,30 @@ struct statfs sfs; char path[PATH_MAX]; + /* If the source is a symbolic link and is on another + * filesystem, it can be recreated at the destination. + */ + if (lstat(from, &sb) == -1) { + warn("%s",from); + return (1); + } + if (S_ISLNK(sb.st_mode)) { + bzero(path, PATH_MAX); + if (readlink(from, path, PATH_MAX) == -1) { + warn("%s", from); + return (1); + } + if (symlink(path,to)==-1) { + warn("%s", to); + return (1); + } + if (unlink(from) == -1) { + warn("%s", from); + return (1); + } + return (0); + } + /* Can't mv(1) a mount point. */ if (realpath(from, path) == NULL) { warnx("cannot resolve %s: %s", from, path); >Release-Note: >Audit-Trail: >Unformatted: