X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fmount%2Fnfsumount.c;h=b1927de92f156186b3099385ad383c3bfe2b2fad;hp=78ebd4aa0363839c91e816ab03f180cfb562d1a7;hb=1ee10ef034cbca86da4df271ac4097a948e7ab59;hpb=4f15bd6e3ebfebef16c1db61b28a98863c36cb81 diff --git a/utils/mount/nfsumount.c b/utils/mount/nfsumount.c index 78ebd4a..b1927de 100644 --- a/utils/mount/nfsumount.c +++ b/utils/mount/nfsumount.c @@ -31,6 +31,7 @@ #include "nls.h" #include "mount_constants.h" +#include "nfs_mount.h" #include "mount.h" #include "error.h" #include "network.h" @@ -109,7 +110,7 @@ static int del_mtab(const char *spec, const char *node) res = try_remount(spec, node); if (res) goto writemtab; - return 0; + return EX_SUCCESS; } else umnt_err = errno; } @@ -127,7 +128,7 @@ static int del_mtab(const char *spec, const char *node) } if (res >= 0) - return 0; + return EX_SUCCESS; if (umnt_err) umount_error(umnt_err, node); @@ -169,12 +170,22 @@ out: static int nfs_umount_do_umnt(struct mount_options *options, char **hostname, char **dirname) { - struct sockaddr_storage address; - struct sockaddr *sap = (struct sockaddr *)&address; + union { + struct sockaddr sa; + struct sockaddr_in s4; + struct sockaddr_in6 s6; + } address; + struct sockaddr *sap = &address.sa; socklen_t salen = sizeof(address); struct pmap nfs_pmap, mnt_pmap; + sa_family_t family; + + if (!nfs_options2pmap(options, &nfs_pmap, &mnt_pmap)) + return EX_FAIL; - nfs_options2pmap(options, &nfs_pmap, &mnt_pmap); + /* Skip UMNT call for vers=4 mounts */ + if (nfs_pmap.pm_vers == 4) + return EX_SUCCESS; *hostname = nfs_umount_hostname(options, *hostname); if (!*hostname) { @@ -182,14 +193,17 @@ static int nfs_umount_do_umnt(struct mount_options *options, return EX_FAIL; } - if (nfs_name_to_address(*hostname, AF_UNSPEC, sap, &salen)) { - if (nfs_advise_umount(sap, salen, &mnt_pmap, dirname) != 0) - return EX_SUCCESS; - else - nfs_error(_("%s: Server failed to unmount '%s:%s'"), - progname, *hostname, *dirname); - } - return EX_FAIL; + if (!nfs_mount_proto_family(options, &family)) + return 0; + if (!nfs_lookup(*hostname, family, sap, &salen)) + /* nfs_lookup reports any errors */ + return EX_FAIL; + + if (nfs_advise_umount(sap, salen, &mnt_pmap, dirname) == 0) + /* nfs_advise_umount reports any errors */ + return EX_FAIL; + + return EX_SUCCESS; } /* @@ -332,7 +346,7 @@ int nfsumount(int argc, char *argv[]) char *opt = hasmntopt(&mc->m, "user"); struct passwd *pw; char *comma; - int len; + size_t len; if (!opt) goto only_root; if (opt[4] != '=') @@ -349,7 +363,7 @@ int nfsumount(int argc, char *argv[]) } } - ret = 0; + ret = EX_SUCCESS; if (mc) { if (!lazy && strcmp(mc->m.mnt_type, "nfs4") != 0) /* We ignore the error from nfs_umount23. @@ -358,7 +372,7 @@ int nfsumount(int argc, char *argv[]) * could cause /sbin/mount to retry! */ nfs_umount23(mc->m.mnt_fsname, mc->m.mnt_opts); - ret = del_mtab(mc->m.mnt_fsname, mc->m.mnt_dir) ?: ret; + ret = del_mtab(mc->m.mnt_fsname, mc->m.mnt_dir); } else if (*spec != '/') { if (!lazy) ret = nfs_umount23(spec, "tcp,v3");