]> git.wh0rd.org Git - patches.git/blob - util-linux-mount-bg-fstab.patch
scummvm random work
[patches.git] / util-linux-mount-bg-fstab.patch
1 --- util-linux-2.13-pre6/mount/mount.c  2005-08-14 11:16:33.000000000 -0400
2 +++ util-linux-2.13-pre6-new/mount/mount.c      2006-03-18 00:25:50.000000000 -0500
3 @@ -100,9 +100,10 @@ struct opt_map {
4  #define MS_GROUP       0x08000000
5  #define MS_COMMENT     0x00020000
6  #define MS_LOOP                0x00010000
7 +#define MS_BG          0x04000000
8  
9  /* Options that we keep the mount system call from seeing.  */
10 -#define MS_NOSYS       (MS_NOAUTO|MS_USERS|MS_USER|MS_COMMENT|MS_LOOP)
11 +#define MS_NOSYS       (MS_NOAUTO|MS_USERS|MS_USER|MS_COMMENT|MS_LOOP|MS_BG)
12  
13  /* Options that we keep from appearing in the options field in the mtab.  */
14  #define MS_NOMTAB      (MS_REMOUNT|MS_NOAUTO|MS_USERS|MS_USER)
15 @@ -143,6 +144,7 @@ static const struct opt_map opt_map[] = 
16    { "comment", 0, 0, MS_COMMENT},      /* fstab comment only (kudzu,_netdev)*/
17  
18    /* add new options here */
19 +  { "bg",      1, 0, MS_BG     },      /* fork this mount into the background */
20  #ifdef MS_NOSUB
21    { "sub",     0, 1, MS_NOSUB  },      /* allow submounts */
22    { "nosub",   0, 0, MS_NOSUB  },      /* don't allow submounts */
23 @@ -791,6 +793,7 @@ try_mount_one (const char *spec0, const 
24    const char *loopdev = 0, *loopfile = 0;
25    struct stat statbuf;
26    int nfs_mount_version = 0;   /* any version */
27 +  pid_t pid = -1;
28  
29    /* copies for freeing on exit */
30    const char *opts1, *spec1, *node1, *types1, *extra_opts1;
31 @@ -850,28 +853,41 @@ retry_nfs:
32  
33    block_signals (SIG_BLOCK);
34  
35 -  if (!fake)
36 -    mnt5_res = guess_fstype_and_mount (spec, node, &types, flags & ~MS_NOSYS,
37 -                                      mount_opts);
38 +  if (!fake) {
39 +    /* Don't bother checking if fork failed because if it does, we will just
40 +     * act as if MS_BG was not specified in the first place */
41 +    if (flags & MS_BG)
42 +      pid = fork();
43 +    if (pid == -1 || pid == 0)
44 +      mnt5_res = guess_fstype_and_mount (spec, node, &types, flags & ~MS_NOSYS,
45 +                                        mount_opts);
46 +  }
47  
48    if (fake || mnt5_res == 0) {
49        /* Mount succeeded, report this (if verbose) and write mtab entry.  */
50        if (loop)
51           opt_loopdev = loopdev;
52  
53 -      update_mtab_entry(loop ? loopfile : spec,
54 +      if (pid == -1 || pid == 0) {
55 +        update_mtab_entry(loop ? loopfile : spec,
56                         node,
57                         types ? types : "unknown",
58                         fix_opts_string (flags & ~MS_NOMTAB, extra_opts, user),
59                         flags,
60                         freq,
61                         pass);
62 +        if (pid == 0)
63 +          exit(mnt5_res);
64 +      }
65  
66        block_signals (SIG_UNBLOCK);
67        res = 0;
68        goto out;
69    }
70  
71 +  if (pid == 0)
72 +    exit(mnt5_res);
73 +
74    mnt_err = errno;
75  
76    if (loop)
77 @@ -1335,9 +1351,8 @@ do_mount_all (char *types, char *options
78                 if (optfork) {
79                         p = fork();
80                         if (p == -1) {
81 -                               int errsv = errno;
82                                 error(_("mount: cannot fork: %s"),
83 -                                     strerror (errsv));
84 +                                     strerror (errno));
85                         }
86                         else if (p != 0)
87                                 cp->pid = p;
88 @@ -1368,7 +1383,8 @@ do_mount_all (char *types, char *options
89                         if(waitpid(cp->pid, &ret, 0) == -1) {
90                                 if (errno == EINTR)
91                                         goto keep_waiting;
92 -                               perror("waitpid");
93 +                               error(_("mount: cannot waitpid: %s"),
94 +                                     strerror (errno));
95                         } else if (WIFEXITED(ret))
96                                 status |= WEXITSTATUS(ret);
97                         else