mount.cifs: implement the "nofail" option
authorJeff Layton <jlayton@samba.org>
Mon, 8 Oct 2012 10:44:49 +0000 (06:44 -0400)
committerJeff Layton <jlayton@samba.org>
Mon, 8 Oct 2012 10:44:49 +0000 (06:44 -0400)
The mount(8) manpage lists this as a fs-independent option:

    nofail: Do not report errors for this device if it does not exist.

Implement that in mount.cifs by not returning an error if we were unable
to find a suitable address for the mount attempt.

Reported-by: Peter Trenholme <PTrenholme@gmail.com>
Signed-off-by: Jeff Layton <jlayton@samba.org>
mount.cifs.c

index 7ee859bd004d4b1e51b8371911c9424069adeba6..756fce2453ca67d93ef9c77dab4f20c17f84dc72 100644 (file)
 #define OPT_CRUID      29
 #define OPT_BKUPUID    30
 #define OPT_BKUPGID    31
+#define OPT_NOFAIL     32
 
 #define MNT_TMP_FILE "/.mtab.cifs.XXXXXX"
 
@@ -178,6 +179,7 @@ struct parsed_mount_info {
        unsigned int fakemnt:1;
        unsigned int nomtab:1;
        unsigned int verboseflag:1;
+       unsigned int nofail:1;
 };
 
 const char *thisprogram;
@@ -805,6 +807,8 @@ static int parse_opt_token(const char *token)
                return OPT_BKUPUID;
        if (strncmp(token, "backupgid", 9) == 0)
                return OPT_BKUPGID;
+       if (strncmp(token, "nofail", 6) == 0)
+               return OPT_NOFAIL;
 
        return OPT_ERROR;
 }
@@ -1177,6 +1181,9 @@ parse_options(const char *data, struct parsed_mount_info *parsed_info)
 
                        bkupgid = gr->gr_gid;
                        goto nocopy;
+               case OPT_NOFAIL:
+                       parsed_info->nofail = 1;
+                       goto nocopy;
                }
 
                /* check size before copying option to buffer */
@@ -2119,7 +2126,7 @@ int main(int argc, char **argv)
 mount_retry:
        if (!currentaddress) {
                fprintf(stderr, "Unable to find suitable address.\n");
-               rc = EX_FAIL;
+               rc = parsed_info->nofail ? 0 : EX_FAIL;
                goto mount_exit;
        }
        strlcpy(options, "ip=", options_size);