summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authoriedowse <iedowse@FreeBSD.org>2001-07-22 00:45:29 +0000
committeriedowse <iedowse@FreeBSD.org>2001-07-22 00:45:29 +0000
commit62f1c968bd6708a9d278f1372b42d4497e074882 (patch)
tree64f77f38db3ad0b76bc92fa285753e2e6d30a99f /sbin
parentcc40e9cd2eb43ea484099541fd8a313f6b0244ff (diff)
downloadFreeBSD-src-62f1c968bd6708a9d278f1372b42d4497e074882.zip
FreeBSD-src-62f1c968bd6708a9d278f1372b42d4497e074882.tar.gz
Include the remote hostname in RPC-related warning messages. Exit
immediately if a host specified by the -h flag cannot be parsed instead of attempting to unmount all NFS filesystems, which was bad. Add a missing return statement at the end of checkname(); this could result in a non-zero exit status in some cases even if the unmount succeeded. Group two separate NFS-related operations into one block to make it more obvious that a variable (hostp) is not dereferenced when uninitialised. Initialise it to NULL anyway to avoid a warning. Pass in the read_mtab()'s bogus argument as NULL instead of messing with a local variable to achieve the same effect. A later commit will clean up this mounttab interface.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/umount/umount.c49
1 files changed, 24 insertions, 25 deletions
diff --git a/sbin/umount/umount.c b/sbin/umount/umount.c
index 2a3a337..02ef3ed 100644
--- a/sbin/umount/umount.c
+++ b/sbin/umount/umount.c
@@ -141,10 +141,7 @@ main(int argc, char *argv[])
if (nfshost != NULL) {
memset(&hints, 0, sizeof hints);
error = getaddrinfo(nfshost, NULL, &hints, &nfshost_ai);
- if (error) {
- fprintf(stderr, "ndp: %s: %s\n", nfshost,
- gai_strerror(error));
- }
+ errx(1, "%s: %s", nfshost, gai_strerror(error));
}
switch (all) {
@@ -393,7 +390,7 @@ checkname(char *name, char **typelist)
return (1);
}
free(mntfromnamerev);
- umountfs(mntfromname, mntonname, type);
+ return (umountfs(mntfromname, mntonname, type));
}
/*
@@ -404,19 +401,19 @@ umountfs(char *mntfromname, char *mntonname, char *type)
{
enum clnt_stat clnt_stat;
struct timeval try;
- struct mtablist *mtab;
struct addrinfo *ai, hints;
int do_rpc;
CLIENT *clp;
char *nfsdirname, *orignfsdirname;
char *hostp, *delimp;
- mtab = NULL;
ai = NULL;
+ do_rpc = 0;
+ hostp = NULL;
nfsdirname = delimp = orignfsdirname = NULL;
memset(&hints, 0, sizeof hints);
- if (!strcmp(type, "nfs")) {
+ if (strcmp(type, "nfs") == 0) {
if ((nfsdirname = strdup(mntfromname)) == NULL)
err(1, "strdup");
orignfsdirname = nfsdirname;
@@ -429,19 +426,20 @@ umountfs(char *mntfromname, char *mntonname, char *type)
}
nfsdirname = delimp + 1;
}
+
+ /*
+ * Check if we have to start the rpc-call later.
+ * If there are still identical nfs-names mounted,
+ * we skip the rpc-call. Obviously this has to
+ * happen before unmount(2), but it should happen
+ * after the previous namecheck.
+ * A non-NULL return means that this is the last
+ * mount from mntfromname that is still mounted.
+ */
+ if (getmntname(mntfromname, NULL, NOTHING, &type, COUNT)
+ != NULL)
+ do_rpc = 1;
}
- /*
- * Check if we have to start the rpc-call later.
- * If there are still identical nfs-names mounted,
- * we skip the rpc-call. Obviously this has to
- * happen before unmount(2), but it should happen
- * after the previous namecheck.
- */
- if (strcmp(type, "nfs") == 0 && getmntname(mntfromname, NULL, NOTHING,
- &type, COUNT) != NULL)
- do_rpc = 1;
- else
- do_rpc = 0;
if (!namematch(ai))
return (1);
@@ -458,7 +456,8 @@ umountfs(char *mntfromname, char *mntonname, char *type)
if (ai != NULL && !(fflag & MNT_FORCE) && do_rpc) {
clp = clnt_create(hostp, RPCPROG_MNT, RPCMNT_VER1, "udp");
if (clp == NULL) {
- clnt_pcreateerror("Cannot MNT PRC");
+ warnx("%s: %s", hostp,
+ clnt_spcreateerror("RPCPROG_MNT"));
return (1);
}
clp->cl_auth = authsys_create_default();
@@ -467,17 +466,17 @@ umountfs(char *mntfromname, char *mntonname, char *type)
clnt_stat = clnt_call(clp, RPCMNT_UMOUNT, xdr_dir,
nfsdirname, xdr_void, (caddr_t)0, try);
if (clnt_stat != RPC_SUCCESS) {
- clnt_perror(clp, "Bad MNT RPC");
+ warnx("%s: %s", hostp,
+ clnt_sperror(clp, "RPCMNT_UMOUNT"));
return (1);
}
/*
* Remove the unmounted entry from /var/db/mounttab.
*/
- if (read_mtab(mtab)) {
- mtab = mtabhead;
+ if (read_mtab(NULL)) {
clean_mtab(hostp, nfsdirname);
if(!write_mtab())
- warnx("cannot remove entry %s:%s",
+ warnx("cannot remove mounttab entry %s:%s",
hostp, nfsdirname);
free_mtab();
}
OpenPOWER on IntegriCloud