X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fmount%2Fmount.c;h=94435c88030c3e91b6123cb4924acf124cfc677a;hp=64a2b75fd68cc949f2e98cc6fb4904b91e497309;hb=aaec79d4e3a1337dde561084445cd4a4e1857da9;hpb=5e30f39229acd1cb9e5e6fa73c6adb34401866d3 diff --git a/utils/mount/mount.c b/utils/mount/mount.c index 64a2b75..94435c8 100644 --- a/utils/mount/mount.c +++ b/utils/mount/mount.c @@ -39,7 +39,6 @@ #include "nfs_mount.h" #include "nfs4_mount.h" -#include "nfsumount.h" #include "mount.h" #include "error.h" #include "network.h" @@ -50,6 +49,9 @@ int nomtab; int verbose; int sloppy; +#define FOREGROUND (0) +#define BACKGROUND (1) + static struct option longopts[] = { { "fake", 0, 0, 'f' }, { "help", 0, 0, 'h' }, @@ -175,14 +177,13 @@ static void discover_nfs_mount_data_version(void) static void print_one(char *spec, char *node, char *type, char *opts) { - if (verbose) { - printf("%s on %s type %s", spec, node, type); - - if (opts != NULL) - printf(" (%s)", opts); + if (!verbose) + return; - printf("\n"); - } + if (opts) + printf(_("%s on %s type %s (%s)\n"), spec, node, type, opts); + else + printf(_("%s on %s type %s\n"), spec, node, type); } /* @@ -269,18 +270,18 @@ fail_unlock: void mount_usage(void) { - printf("usage: %s remotetarget dir [-rvVwfnh] [-o nfsoptions]\n", + printf(_("usage: %s remotetarget dir [-rvVwfnsh] [-o nfsoptions]\n"), progname); - printf("options:\n"); - printf("\t-r\t\tMount file system readonly\n"); - printf("\t-v\t\tVerbose\n"); - printf("\t-V\t\tPrint version\n"); - printf("\t-w\t\tMount file system read-write\n"); - printf("\t-f\t\tFake mount, do not actually mount\n"); - printf("\t-n\t\tDo not update /etc/mtab\n"); - printf("\t-s\t\tTolerate sloppy mount options rather than failing.\n"); - printf("\t-h\t\tPrint this help\n"); - printf("\tnfsoptions\tRefer to mount.nfs(8) or nfs(5)\n\n"); + printf(_("options:\n")); + printf(_("\t-r\t\tMount file system readonly\n")); + printf(_("\t-v\t\tVerbose\n")); + printf(_("\t-V\t\tPrint version\n")); + printf(_("\t-w\t\tMount file system read-write\n")); + printf(_("\t-f\t\tFake mount, do not actually mount\n")); + printf(_("\t-n\t\tDo not update /etc/mtab\n")); + printf(_("\t-s\t\tTolerate sloppy mount options rather than fail\n")); + printf(_("\t-h\t\tPrint this help\n")); + printf(_("\tnfsoptions\tRefer to mount.nfs(8) or nfs(5)\n\n")); } static void parse_opt(const char *opt, int *mask, char *extra_opts, int len) @@ -363,6 +364,31 @@ static int chk_mountpoint(char *mount_point) return 0; } +static int try_mount(char *spec, char *mount_point, int flags, + char *fs_type, char **extra_opts, char *mount_opts, + int fake, int nomtab, int bg) +{ + int ret; + + if (strcmp(fs_type, "nfs4") == 0) + ret = nfs4mount(spec, mount_point, flags, + extra_opts, fake, bg); + else + ret = nfsmount(spec, mount_point, flags, + extra_opts, fake, bg); + + if (ret) + return ret; + + if (!fake) + print_one(spec, mount_point, fs_type, mount_opts); + + if (!nomtab) + ret = add_mtab(spec, mount_point, fs_type, flags, *extra_opts, + 0, 0 /* these are always zero for NFS */ ); + return ret; +} + int main(int argc, char *argv[]) { int c, flags = 0, mnt_err = 1, fake = 0; @@ -494,20 +520,27 @@ int main(int argc, char *argv[]) goto out; } - if (strcmp(fs_type, "nfs4") == 0) - mnt_err = nfs4mount(spec, mount_point, flags, &extra_opts, fake); - else - mnt_err = nfsmount(spec, mount_point, flags, &extra_opts, fake); - - if (mnt_err) - exit(EX_FAIL); - - if (!fake) - print_one(spec, mount_point, fs_type, mount_opts); + mnt_err = try_mount(spec, mount_point, flags, fs_type, &extra_opts, + mount_opts, fake, nomtab, FOREGROUND); + if (mnt_err == EX_BG) { + printf(_("mount: backgrounding \"%s\"\n"), spec); + fflush(stdout); - if (!nomtab) - mnt_err = add_mtab(spec, mount_point, fs_type, flags, extra_opts, - 0, 0 /* these are always zero for NFS */ ); + /* + * Parent exits immediately with success. Make + * sure not to free "mount_point" + */ + if (fork() > 0) + exit(0); + + mnt_err = try_mount(spec, mount_point, flags, fs_type, + &extra_opts, mount_opts, fake, + nomtab, BACKGROUND); + if (verbose && mnt_err) + printf(_("%s: giving up \"%s\"\n"), + progname, spec); + exit(0); + } out: free(mount_point);