* - Moved to nfs-utils/utils/mount from util-linux/mount.
*/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
#include <rpc/auth.h>
#include <rpc/rpc.h>
+
#ifdef HAVE_RPCSVC_NFS_PROT_H
#include <rpcsvc/nfs_prot.h>
#else
#include "pseudoflavors.h"
#include "nls.h"
-#include "conn.h"
#include "xcommon.h"
+#include "mount.h"
#include "mount_constants.h"
#include "nfs4_mount.h"
#include "nfs_mount.h"
#include "error.h"
+#include "network.h"
#if defined(VAR_LOCK_DIR)
#define DEFAULT_DIR VAR_LOCK_DIR
#define DEFAULT_DIR "/var/lock/subsys"
#endif
+extern char *progname;
extern int verbose;
extern int sloppy;
if (access(GSSDLCK, F_OK)) { \
printf(_("Warning: rpc.gssd appears not to be running.\n")); \
} \
-} while(0);
+} while(0);
#ifndef NFS_PORT
#define NFS_PORT 2049
for (sec = strtok(sec, ":"); sec; sec = strtok(NULL, ":")) {
if (num_flavour >= MAX_USER_FLAVOUR) {
- fprintf(stderr,
- _("mount: maximum number of security flavors "
- "exceeded\n"));
+ nfs_error(_("%s: maximum number of security flavors "
+ "exceeded"), progname);
return 0;
}
for (i = 0; i < flav_map_size; i++) {
}
}
if (i == flav_map_size) {
- fprintf(stderr,
- _("mount: unknown security type %s\n"), sec);
+ nfs_error(_("%s: unknown security type %s\n"),
+ progname, sec);
return 0;
}
}
if (!num_flavour)
- fprintf(stderr,
- _("mount: no security flavors passed to sec= option\n"));
+ nfs_error(_("%s: no security flavors passed to sec= option"),
+ progname);
return num_flavour;
}
char *s;
if (!(s = strchr(hostdir, ':'))) {
- fprintf(stderr,
- _("mount: "
- "directory to mount not in host:dir format\n"));
+ nfs_error(_("%s: directory to mount not in host:dir format"),
+ progname);
return -1;
}
*hostname = hostdir;
until they can be fully supported. (mack@sgi.com) */
if ((s = strchr(hostdir, ','))) {
*s = '\0';
- fprintf(stderr,
- _("mount: warning: "
- "multiple hostnames not supported\n"));
+ nfs_error(_("%s: warning: multiple hostnames not supported"),
+ progname);
}
return 0;
}
if (inet_aton(hostname, &addr->sin_addr))
return 0;
if ((hp = gethostbyname(hostname)) == NULL) {
- fprintf(stderr, _("mount: can't get address for %s\n"),
- hostname);
+ nfs_error(_("%s: can't get address for %s\n"),
+ progname, hostname);
return -1;
}
- if (hp->h_length > sizeof(struct in_addr)) {
- fprintf(stderr,
- _("mount: got bad hp->h_length\n"));
+ if (hp->h_length > (int)sizeof(struct in_addr)) {
+ nfs_error(_("%s: got bad hp->h_length"), progname);
hp->h_length = sizeof(struct in_addr);
}
memcpy(&addr->sin_addr, hp->h_addr, hp->h_length);
struct sockaddr_in myaddr;
if (gethostname(myname, sizeof(myname))) {
- fprintf(stderr, _("mount: can't determine client address\n"));
+ nfs_error(_("%s: can't determine client address\n"),
+ progname);
return -1;
}
if (fill_ipv4_sockaddr(myname, &myaddr))
}
int nfs4mount(const char *spec, const char *node, int flags,
- char **extra_opts, int fake)
+ char **extra_opts, int fake, int running_bg)
{
static struct nfs4_mount_data data;
static char hostdir[1024];
int bg, soft, intr;
int nocto, noac, unshared;
int retry;
- int retval;
+ int retval = EX_FAIL;
time_t timeout, t;
- retval = EX_FAIL;
if (strlen(spec) >= sizeof(hostdir)) {
- fprintf(stderr, _("mount: "
- "excessively long host:dir argument\n"));
+ nfs_error(_("%s: excessively long host:dir argument\n"),
+ progname);
goto fail;
}
strcpy(hostdir, spec);
if (!old_opts)
old_opts = "";
if (strlen(old_opts) + strlen(s) + 10 >= sizeof(new_opts)) {
- fprintf(stderr, _("mount: "
- "excessively long option argument\n"));
+ nfs_error(_("%s: excessively long option argument\n"),
+ progname);
goto fail;
}
- snprintf(new_opts, sizeof(new_opts), "%s%saddr=%s",
- old_opts, *old_opts ? "," : "", s);
+ if (running_bg)
+ strncpy(new_opts, old_opts, sizeof(new_opts));
+ else
+ snprintf(new_opts, sizeof(new_opts), "%s%saddr=%s",
+ old_opts, *old_opts ? "," : "", s);
*extra_opts = xstrdup(new_opts);
/* Set default options.
nocto = 0;
noac = 0;
unshared = 0;
- retry = 10000; /* 10000 minutes ~ 1 week */
+ retry = -1;
/*
* NFSv4 specifies that the default port should be 2049
val = 0;
opt += 2;
}
- if (!strcmp(opt, "bg"))
+ if (!strcmp(opt, "bg"))
bg = val;
- else if (!strcmp(opt, "fg"))
+ else if (!strcmp(opt, "fg"))
bg = !val;
else if (!strcmp(opt, "soft"))
soft = val;
else if (!strcmp(opt, "sharecache"))
unshared = !val;
else if (!sloppy) {
- printf(_("unknown nfs mount option: "
- "%s%s\n"), val ? "" : "no", opt);
+ printf(_("unknown nfs mount option: %s%s\n"),
+ val ? "" : "no", opt);
goto fail;
}
}
}
+ /* if retry is still -1, then it wasn't set via an option */
+ if (retry == -1) {
+ if (bg)
+ retry = 10000; /* 10000 mins == ~1 week */
+ else
+ retry = 2; /* 2 min default on fg mounts */
+ }
+
data.flags = (soft ? NFS4_MOUNT_SOFT : 0)
| (intr ? NFS4_MOUNT_INTR : 0)
| (nocto ? NFS4_MOUNT_NOCTO : 0)
data.host_addrlen = sizeof(server_addr);
#ifdef NFS_MOUNT_DEBUG
- printf("rsize = %d, wsize = %d, timeo = %d, retrans = %d\n",
+ printf(_("rsize = %d, wsize = %d, timeo = %d, retrans = %d\n"),
data.rsize, data.wsize, data.timeo, data.retrans);
- printf("acreg (min, max) = (%d, %d), acdir (min, max) = (%d, %d)\n",
+ printf(_("acreg (min, max) = (%d, %d), acdir (min, max) = (%d, %d)\n"),
data.acregmin, data.acregmax, data.acdirmin, data.acdirmax);
- printf("port = %d, bg = %d, retry = %d, flags = %.8x\n",
+ printf(_("port = %d, bg = %d, retry = %d, flags = %.8x\n"),
ntohs(server_addr.sin_port), bg, retry, data.flags);
- printf("soft = %d, intr = %d, nocto = %d, noac = %d, "
- "nosharecache = %d\n",
+ printf(_("soft = %d, intr = %d, nocto = %d, noac = %d, "
+ "nosharecache = %d\n"),
(data.flags & NFS4_MOUNT_SOFT) != 0,
(data.flags & NFS4_MOUNT_INTR) != 0,
(data.flags & NFS4_MOUNT_NOCTO) != 0,
if (num_flavour > 0) {
int pf_cnt, i;
- printf("sec = ");
+ printf(_("sec = "));
for (pf_cnt = 0; pf_cnt < num_flavour; pf_cnt++) {
for (i = 0; i < flav_map_size; i++) {
if (flav_map[i].fnum == pseudoflavour[pf_cnt]) {
printf("%s", (pf_cnt < num_flavour-1) ? ":" : "\n");
}
}
- printf("proto = %s\n", (data.proto == IPPROTO_TCP) ? "tcp" : "udp");
+ printf(_("proto = %s\n"), (data.proto == IPPROTO_TCP) ? _("tcp") : _("udp"));
#endif
timeout = time(NULL) + 60 * retry;
data.version = NFS4_MOUNT_VERSION;
for (;;) {
if (verbose) {
- fprintf(stderr,
- "mount: pinging: prog %d vers %d prot %s port %d\n",
- NFS_PROGRAM, 4, data.proto == IPPROTO_UDP ? "udp" : "tcp",
+ printf(_("%s: pinging: prog %d vers %d prot %s port %d\n"),
+ progname, NFS_PROGRAM, 4,
+ data.proto == IPPROTO_UDP ? "udp" : "tcp",
ntohs(server_addr.sin_port));
}
client_addr.sin_family = 0;
break;
}
- switch(rpc_createerr.cf_stat){
- case RPC_TIMEDOUT:
- break;
- case RPC_SYSTEMERROR:
- if (errno == ETIMEDOUT)
+ if (!bg) {
+ switch(rpc_createerr.cf_stat) {
+ case RPC_TIMEDOUT:
break;
- default:
- mount_errors(hostname, 0, bg);
+ case RPC_SYSTEMERROR:
+ if (errno == ETIMEDOUT)
+ break;
+ default:
+ rpc_mount_errors(hostname, 0, bg);
+ goto fail;
+ }
+ }
+
+ if (bg && !running_bg) {
+ if (retry > 0)
+ retval = EX_BG;
goto fail;
}
+
t = time(NULL);
if (t >= timeout) {
- mount_errors(hostname, 0, bg);
+ rpc_mount_errors(hostname, 0, bg);
goto fail;
}
- mount_errors(hostname, 1, bg);
+ rpc_mount_errors(hostname, 1, bg);
continue;
}
}
}
- return 0;
+ return EX_SUCCESS;
fail:
return retval;