X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=blobdiff_plain;f=utils%2Fmount%2Fmount.c;h=a2325196160067ef6129fe15da05543cf414558b;hp=a7ad035237b464fd269a2f0b1cf6fb3de968b797;hb=1f1fa09103d71be48287d5393f82ee9a92927b2e;hpb=53a9b4a2ea971d5718ccfcc2f2825ff9af81cd23 diff --git a/utils/mount/mount.c b/utils/mount/mount.c index a7ad035..a232519 100644 --- a/utils/mount/mount.c +++ b/utils/mount/mount.c @@ -49,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' }, @@ -361,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; @@ -492,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);