mount.nfs: Replace fork() with daemon() for backgrounding mounts
authorChuck Lever <chuck.lever@oracle.com>
Tue, 21 Aug 2007 16:19:08 +0000 (12:19 -0400)
committerNeil Brown <neilb@suse.de>
Fri, 24 Aug 2007 03:15:02 +0000 (13:15 +1000)
Neil recommended this change to address a problem with background mount
processes handling signals properly during an init level change.  It is
also useful for preventing background mount processes from reporting
progress on the parent's tty, which is generally just annoying noise.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Neil Brown <neilb@suse.de>
utils/mount/mount.c

index 4b78021..2513943 100644 (file)
@@ -550,14 +550,19 @@ int main(int argc, char *argv[])
        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);
+               printf(_("%s: backgrounding \"%s\"\n"),
+                       progname, spec);
                fflush(stdout);
 
                /*
                 * Parent exits immediately with success.
                 */
-               if (fork() > 0)
-                       exit(0);
+               if (daemon(0, 0)) {
+                       nfs_error(_("%s: failed to start "
+                                       "background process: %s\n"),
+                                               progname, strerror(errno));
+                       exit(EX_FAIL);
+               }
 
                mnt_err = try_mount(spec, mount_point, flags, fs_type,
                                        &extra_opts, mount_opts, fake,