From patchwork Tue Feb 3 14:44:12 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shirish Pargaonkar X-Patchwork-Id: 5243 Received: from lists.samba.org (mail.samba.org [66.70.73.150]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n13EoDDp014444 for ; Tue, 3 Feb 2009 14:50:13 GMT Received: from dp.samba.org (localhost [127.0.0.1]) by lists.samba.org (Postfix) with ESMTP id 4C577163C53 for ; Tue, 3 Feb 2009 14:50:01 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) on dp.samba.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.8 tests=AWL,BAYES_00, DNS_FROM_RFC_POST,SPF_PASS autolearn=no version=3.1.7 X-Original-To: linux-cifs-client@lists.samba.org Delivered-To: linux-cifs-client@lists.samba.org Received: from yw-out-1718.google.com (yw-out-1718.google.com [74.125.46.155]) by lists.samba.org (Postfix) with ESMTP id C9C8F163CD4 for ; Tue, 3 Feb 2009 14:49:28 +0000 (GMT) Received: by yw-out-1718.google.com with SMTP id 6so694528ywa.80 for ; Tue, 03 Feb 2009 06:49:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=Mze6QFAtXsJ+6UWGkRdsgwuYIGvSYawf8SKk4UxJtIU=; b=WrynECVqB0dcqzHa2/I3h4Dyw6rqH1d5vxpYS3snYWyZAcJchARSm2UNWPSomXVAQz k09/f4AU6emNQEm2PP5LdOSMVdvdXJuXWI4b8u4M4houuycY/e5Noh3pBg4oN1pKprpi BbskPbSoQH3gh5rn513UUJVzGXVKyXg0HaMY0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=UPM6t7YEjRFXZIHWgp53kGE+PE1TxhBWhG9WCtXtmcuk72McVNHx6s+Le/zszGXqId CxwOwcHlsgJr/Qr6bjiLFrqKHM8xMCYNSrHhcH/sussjmkyupOqi4VAGiSdVzvOx1ncl SoP1I8rrWFuiMDmNxdQUDugbq6tZRWgYwXs14= MIME-Version: 1.0 Received: by 10.231.20.1 with SMTP id d1mr279125ibb.17.1233672252315; Tue, 03 Feb 2009 06:44:12 -0800 (PST) In-Reply-To: <4a4634330902020852s729a613fp1890ecd045bc82b8@mail.gmail.com> References: <4a4634330902020852s729a613fp1890ecd045bc82b8@mail.gmail.com> Date: Tue, 3 Feb 2009 08:44:12 -0600 Message-ID: <4a4634330902030644k319feb09v20b639320912b229@mail.gmail.com> Subject: Re: [patch][linux-cifs-client] clean-up entries in /etc/mtab after unmounting a cifs filesystem From: Shirish Pargaonkar To: "linux-cifs-client@lists.samba.org" X-BeenThere: linux-cifs-client@lists.samba.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: The Linux CIFS VFS client List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-cifs-client-bounces+patchwork-cifs-client=patchwork.kernel.org@lists.samba.org Errors-To: linux-cifs-client-bounces+patchwork-cifs-client=patchwork.kernel.org@lists.samba.org On Mon, Feb 2, 2009 at 10:52 AM, Shirish Pargaonkar wrote: > Two different patches for the same functionality, to remove the > remaining entry in /etc/mtab > after a filesystem is unmounted by canonicalizing the supplied > mountpoint on the command line. > > Please refer to bug 4370 in samba bugzilla. > > Regards, > > Shirish > version of the patch after making a change suggested by Jeff Layton. --- client.orig/umount.cifs.c 2009-02-02 04:35:20.000000000 -0600 +++ client/umount.cifs.c 2009-02-03 03:28:32.000000000 -0600 @@ -33,6 +33,7 @@ #include #include #include +#include #include "mount.h" #define UNMOUNT_CIFS_VERSION_MAJOR "0" @@ -231,6 +232,37 @@ static int remove_from_mtab(char * mount return rc; } +/* Make a canonical pathname from PATH. Returns a freshly malloced string. + It is up the *caller* to ensure that the PATH is sensible. i.e. + canonicalize ("/dev/fd0/.") returns "/dev/fd0" even though ``/dev/fd0/.'' + is not a legal pathname for ``/dev/fd0'' Anything we cannot parse + we return unmodified. */ +static char * +canonicalize(char *path) +{ + char *canonical = malloc (PATH_MAX + 1); + + if (!canonical) { + fprintf(stderr, "Error! Not enough memory!\n"); + return NULL; + } + + if (strlen(path) > PATH_MAX) { + fprintf(stderr, "Mount point string too long\n"); + return NULL; + } + + if (path == NULL) + return NULL; + + if (realpath (path, canonical)) + return canonical; + + strncpy (canonical, path, PATH_MAX); + canonical[PATH_MAX] = '\0'; + return canonical; +} + int main(int argc, char ** argv) { int c; @@ -304,7 +336,7 @@ int main(int argc, char ** argv) argv += optind; argc -= optind; - mountpoint = argv[0]; + mountpoint = canonicalize(argv[0]); if((argc < 1) || (argv[0] == NULL)) { printf("\nMissing name of unmount directory\n");