]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/mount/nfsmount.c
Automatically start statd when mounting an nfs filesystem.
[nfs-utils.git] / utils / mount / nfsmount.c
index b78daadec7f1563930cf23f4fb08c8674cdda7fe..0188caa2a7b8612d6fe5a2a175d7af922ddfd22d 100644 (file)
@@ -306,7 +306,7 @@ getport(
        enum clnt_stat stat;
 
        saddr->sin_port = htons (PMAPPORT);
-       socket = get_socket(saddr, prot, FALSE);
+       socket = get_socket(saddr, prot, FALSE, FALSE);
 
        switch (prot) {
        case IPPROTO_UDP:
@@ -818,7 +818,7 @@ nfsmnt_check_compat(const struct pmap *nfs_pmap, const struct pmap *mnt_pmap)
 int
 nfsmount(const char *spec, const char *node, int *flags,
         char **extra_opts, char **mount_opts, int *nfs_mount_vers,
-        int running_bg)
+        int running_bg, int *need_statd)
 {
        static char *prev_bg_host;
        char hostdir[1024];
@@ -835,14 +835,14 @@ nfsmount(const char *spec, const char *node, int *flags,
                     *nfs_pmap = &nfs_server.pmap;
        struct pmap  save_mnt, save_nfs;
 
-       int fsock;
+       int fsock = -1;
 
        mntres_t mntres;
 
        struct stat statbuf;
        char *s;
        int bg, retry;
-       int retval;
+       int retval = EX_FAIL;
        time_t t;
        time_t prevt;
        time_t timeout;
@@ -853,8 +853,6 @@ nfsmount(const char *spec, const char *node, int *flags,
                *nfs_mount_vers = find_kernel_nfs_mount_version();
        nfs_mount_version = *nfs_mount_vers;
 
-       retval = EX_FAIL;
-       fsock = -1;
        if (strlen(spec) >= sizeof(hostdir)) {
                fprintf(stderr, _("mount: "
                                  "excessively long host:dir argument\n"));
@@ -904,7 +902,6 @@ nfsmount(const char *spec, const char *node, int *flags,
 #if NFS_MOUNT_VERSION >= 2
        data.namlen     = NAME_MAX;
 #endif
-       data.pseudoflavor = AUTH_SYS;
 
        bg = 0;
        retry = 10000;          /* 10000 minutes ~ 1 week */
@@ -1092,6 +1089,15 @@ nfsmount(const char *spec, const char *node, int *flags,
 
                flavor = mountres->auth_flavors.auth_flavors_val;
                while (--i >= 0) {
+                       /* If no flavour requested, use first simple
+                        * flavour that is offered.
+                        */
+                       if (! (data.flags & NFS_MOUNT_SECFLAVOUR) &&
+                           (flavor[i] == AUTH_SYS ||
+                            flavor[i] == AUTH_NONE)) {
+                               data.pseudoflavor = flavor[i];
+                               data.flags |= NFS_MOUNT_SECFLAVOUR;
+                       }
                        if (flavor[i] == data.pseudoflavor)
                                yum = 1;
 #ifdef NFS_MOUNT_DEBUG
@@ -1104,7 +1110,7 @@ nfsmount(const char *spec, const char *node, int *flags,
                                "mount: %s:%s failed, "
                                "security flavor not supported\n",
                                hostname, dirname);
-                       /* server has registered us in mtab, send umount */
+                       /* server has registered us in rmtab, send umount */
                        nfs_call_umount(&mnt_server, &dirname);
                        goto fail;
                }
@@ -1122,20 +1128,22 @@ noauth_flavors:
 #endif
        }
 
-       /* create nfs socket for kernel */
-
-       if (nfs_pmap->pm_prot == IPPROTO_TCP)
-               fsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
-       else
-               fsock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
-       if (fsock < 0) {
-               perror(_("nfs socket"));
-               goto fail;
-       }
-       if (bindresvport(fsock, 0) < 0) {
-               perror(_("nfs bindresvport"));
-               goto fail;
+       if (nfs_mount_version == 1) {
+               /* create nfs socket for kernel */
+               if (nfs_pmap->pm_prot == IPPROTO_TCP)
+                       fsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+               else
+                       fsock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+               if (fsock < 0) {
+                       perror(_("nfs socket"));
+                       goto fail;
+               }
+               if (bindresvport(fsock, 0) < 0) {
+                       perror(_("nfs bindresvport"));
+                       goto fail;
+               }
        }
+
 #ifdef NFS_MOUNT_DEBUG
        printf(_("using port %d for nfs deamon\n"), nfs_pmap->pm_port);
 #endif
@@ -1145,7 +1153,7 @@ noauth_flavors:
         * to avoid problems with multihomed hosts.
         * --Swen
         */
-       if (linux_version_code() <= 66314
+       if (linux_version_code() <= 0x01030a && fsock != -1
            && connect(fsock, (struct sockaddr *) nfs_saddr,
                       sizeof (*nfs_saddr)) < 0) {
                perror(_("nfs connect"));
@@ -1177,6 +1185,7 @@ noauth_flavors:
        strcat(new_opts, cbuf);
 
        *extra_opts = xstrdup(new_opts);
+       *need_statd = ! (data.flags & NFS_MOUNT_NONLM);
        return 0;
 
        /* abort */