From 958c0aac6eeb44c4c0061408bb7b5bd8a945c904 Mon Sep 17 00:00:00 2001 From: christos Date: Mon, 1 Jul 2013 15:16:33 +0000 Subject: [PATCH] Instead of borrowing the mount code to get the nfs arguments, just use the system call directly. It is shorter and works... --- sbin/umount/Makefile | 8 ++++---- sbin/umount/umount.c | 35 +++++++++++++---------------------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/sbin/umount/Makefile b/sbin/umount/Makefile index 47b435d44ac5..12e9c3a8b019 100644 --- a/sbin/umount/Makefile +++ b/sbin/umount/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.17 2013/06/29 22:53:04 christos Exp $ +# $NetBSD: Makefile,v 1.18 2013/07/01 15:16:33 christos Exp $ # @(#)Makefile 8.4 (Berkeley) 6/22/95 .include @@ -11,9 +11,9 @@ MAN= umount.8 CPPFLAGS+= -DSMALL .else MOUNT= ${NETBSDSRCDIR}/sbin/mount -CPPFLAGS+= -I${MOUNT} -I${MOUNT}_nfs -.PATH: ${MOUNT} ${MOUNT}_nfs -SRCS+= vfslist.c getnfsargs.c +CPPFLAGS+= -I${MOUNT} +.PATH: ${MOUNT} +SRCS+= vfslist.c .endif .include diff --git a/sbin/umount/umount.c b/sbin/umount/umount.c index 160be5c1a13d..66b8a8cb738a 100644 --- a/sbin/umount/umount.c +++ b/sbin/umount/umount.c @@ -1,4 +1,4 @@ -/* $NetBSD: umount.c,v 1.45 2013/06/29 23:06:29 christos Exp $ */ +/* $NetBSD: umount.c,v 1.46 2013/07/01 15:16:33 christos Exp $ */ /*- * Copyright (c) 1980, 1989, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1989, 1993\ #if 0 static char sccsid[] = "@(#)umount.c 8.8 (Berkeley) 5/8/95"; #else -__RCSID("$NetBSD: umount.c,v 1.45 2013/06/29 23:06:29 christos Exp $"); +__RCSID("$NetBSD: umount.c,v 1.46 2013/07/01 15:16:33 christos Exp $"); #endif #endif /* not lint */ @@ -55,6 +55,7 @@ __RCSID("$NetBSD: umount.c,v 1.45 2013/06/29 23:06:29 christos Exp $"); #include #include #include +#include #endif /* !SMALL */ #include @@ -67,7 +68,6 @@ __RCSID("$NetBSD: umount.c,v 1.45 2013/06/29 23:06:29 christos Exp $"); typedef enum { MNTANY, MNTON, MNTFROM } mntwhat; #ifndef SMALL -#include "mount_nfs.h" #include "mountprog.h" static int fake, verbose; @@ -186,6 +186,7 @@ umountfs(const char *name, const char **typelist, int raw) #endif /* !SMALL */ const char *mntpt; char *type, rname[MAXPATHLEN]; + const char *proto = NULL; mntwhat what; struct stat sb; @@ -243,6 +244,7 @@ umountfs(const char *name, const char **typelist, int raw) if (!strncmp(type, MOUNT_NFS, sizeof(((struct statvfs *)NULL)->f_fstypename))) { char *delimp; + proto = getmntproto(mntpt); /* look for host:mountpoint */ if ((delimp = strrchr(name, ':')) != NULL) { int len = delimp - name; @@ -275,8 +277,7 @@ umountfs(const char *name, const char **typelist, int raw) #ifndef SMALL if (ai != NULL && !(fflag & MNT_FORCE)) { - clp = clnt_create(hostp, RPCPROG_MNT, RPCMNT_VER1, - getmntproto(mntpt)); + clp = clnt_create(hostp, RPCPROG_MNT, RPCMNT_VER1, proto); if (clp == NULL) { clnt_pcreateerror("Cannot MNT PRC"); return 1; @@ -386,26 +387,16 @@ xdr_dir(XDR *xdrsp, char *dirp) } static const char * -getmntproto(const char *mntpt) +getmntproto(const char *name) { struct nfs_args nfsargs; - struct sockaddr_storage sa; - int proto; - char *name; + struct sockaddr_storage ss; - memset(&sa, 0, sizeof(sa)); - nfsargs.addr = (struct sockaddr *)&sa; - nfsargs.addrlen = sizeof(sa); - if ((name = strdup(mntpt)) == NULL) - err(EXIT_FAILURE, "strdup"); - if (!getnfsargs(name, &nfsargs)) - proto = IPPROTO_UDP; - else - proto = nfsargs.proto; - free(name); - - // XXX: Return udp6/tcp6 too? - return proto == IPPROTO_UDP ? "udp" : "tcp"; + nfsargs.sotype = SOCK_DGRAM; + nfsargs.addr = (struct sockaddr *)&ss; + nfsargs.addrlen = sizeof(ss); + (void)mount("nfs", name, MNT_GETARGS, &nfsargs, sizeof(nfsargs)); + return nfsargs.sotype == SOCK_STREAM ? "tcp" : "udp"; } #endif /* !SMALL */