diff options
author | Rob Landley <rob@landley.net> | 2006-06-21 03:53:33 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2006-06-21 03:53:33 +0000 |
commit | 0cc2c2c2894a840b0bca24da42f4154f33b5af0a (patch) | |
tree | 3962abfafeb61e7418cba020651cc3a49339dedd /util-linux/mount.c | |
parent | dbfb5a3cb7fd8b7e0abed669efe65d689bccbd38 (diff) | |
download | busybox-w32-0cc2c2c2894a840b0bca24da42f4154f33b5af0a.tar.gz busybox-w32-0cc2c2c2894a840b0bca24da42f4154f33b5af0a.tar.bz2 busybox-w32-0cc2c2c2894a840b0bca24da42f4154f33b5af0a.zip |
Patch from Paul Fox to improve mount's error handling behavior, which I beat
on a bit.
Diffstat (limited to 'util-linux/mount.c')
-rw-r--r-- | util-linux/mount.c | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/util-linux/mount.c b/util-linux/mount.c index fecf81606..c64c3f438 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -256,9 +256,9 @@ static int mount_it_now(struct mntent *mp, int vfsflags, char *filteropts) | |||
256 | // Mount one directory. Handles NFS, loopback, autobind, and filesystem type | 256 | // Mount one directory. Handles NFS, loopback, autobind, and filesystem type |
257 | // detection. Returns 0 for success, nonzero for failure. | 257 | // detection. Returns 0 for success, nonzero for failure. |
258 | 258 | ||
259 | static int singlemount(struct mntent *mp) | 259 | static int singlemount(struct mntent *mp, int ignore_busy) |
260 | { | 260 | { |
261 | int rc = 1, vfsflags; | 261 | int rc = -1, vfsflags; |
262 | char *loopFile = 0, *filteropts = 0; | 262 | char *loopFile = 0, *filteropts = 0; |
263 | llist_t *fl = 0; | 263 | llist_t *fl = 0; |
264 | struct stat st; | 264 | struct stat st; |
@@ -277,14 +277,14 @@ static int singlemount(struct mntent *mp) | |||
277 | { | 277 | { |
278 | if (nfsmount(mp->mnt_fsname, mp->mnt_dir, &vfsflags, &filteropts, 1)) { | 278 | if (nfsmount(mp->mnt_fsname, mp->mnt_dir, &vfsflags, &filteropts, 1)) { |
279 | bb_perror_msg("nfsmount failed"); | 279 | bb_perror_msg("nfsmount failed"); |
280 | return 1; | 280 | goto report_error; |
281 | } else { | 281 | } else { |
282 | // Strangely enough, nfsmount() doesn't actually mount() anything. | 282 | // Strangely enough, nfsmount() doesn't actually mount() anything. |
283 | mp->mnt_type = "nfs"; | 283 | mp->mnt_type = "nfs"; |
284 | rc = mount_it_now(mp, vfsflags, filteropts); | 284 | rc = mount_it_now(mp, vfsflags, filteropts); |
285 | if (ENABLE_FEATURE_CLEAN_UP) free(filteropts); | 285 | if (ENABLE_FEATURE_CLEAN_UP) free(filteropts); |
286 | 286 | ||
287 | return rc; | 287 | goto report_error; |
288 | } | 288 | } |
289 | } | 289 | } |
290 | 290 | ||
@@ -354,10 +354,14 @@ static int singlemount(struct mntent *mp) | |||
354 | free(mp->mnt_fsname); | 354 | free(mp->mnt_fsname); |
355 | } | 355 | } |
356 | } | 356 | } |
357 | report_error: | ||
358 | if (rc && errno == EBUSY && ignore_busy) rc = 0; | ||
359 | if (rc < 0) | ||
360 | bb_perror_msg("Mounting %s on %s failed", mp->mnt_fsname, mp->mnt_dir); | ||
361 | |||
357 | return rc; | 362 | return rc; |
358 | } | 363 | } |
359 | 364 | ||
360 | |||
361 | // Parse options, if necessary parse fstab/mtab, and call singlemount for | 365 | // Parse options, if necessary parse fstab/mtab, and call singlemount for |
362 | // each directory to be mounted. | 366 | // each directory to be mounted. |
363 | 367 | ||
@@ -365,7 +369,7 @@ int mount_main(int argc, char **argv) | |||
365 | { | 369 | { |
366 | char *cmdopts = bb_xstrdup(""), *fstabname, *fstype=0, *storage_path=0; | 370 | char *cmdopts = bb_xstrdup(""), *fstabname, *fstype=0, *storage_path=0; |
367 | FILE *fstab; | 371 | FILE *fstab; |
368 | int i, opt, all = FALSE, rc = 1; | 372 | int i, opt, all = FALSE, rc = 0; |
369 | struct mntent mtpair[2], *mtcur = mtpair; | 373 | struct mntent mtpair[2], *mtcur = mtpair; |
370 | 374 | ||
371 | /* parse long options, like --bind and --move. Note that -o option | 375 | /* parse long options, like --bind and --move. Note that -o option |
@@ -447,7 +451,7 @@ int mount_main(int argc, char **argv) | |||
447 | mtpair->mnt_dir = argv[optind+1]; | 451 | mtpair->mnt_dir = argv[optind+1]; |
448 | mtpair->mnt_type = fstype; | 452 | mtpair->mnt_type = fstype; |
449 | mtpair->mnt_opts = cmdopts; | 453 | mtpair->mnt_opts = cmdopts; |
450 | rc = singlemount(mtpair); | 454 | rc = singlemount(mtpair, 0); |
451 | goto clean_up; | 455 | goto clean_up; |
452 | } | 456 | } |
453 | 457 | ||
@@ -491,10 +495,10 @@ int mount_main(int argc, char **argv) | |||
491 | mtcur = mtnext; | 495 | mtcur = mtnext; |
492 | mtcur->mnt_opts=bb_xstrdup(mtcur->mnt_opts); | 496 | mtcur->mnt_opts=bb_xstrdup(mtcur->mnt_opts); |
493 | append_mount_options(&(mtcur->mnt_opts),cmdopts); | 497 | append_mount_options(&(mtcur->mnt_opts),cmdopts); |
494 | rc = singlemount(mtcur); | 498 | rc = singlemount(mtcur, 0); |
495 | free(mtcur->mnt_opts); | 499 | free(mtcur->mnt_opts); |
496 | } | 500 | } |
497 | break; | 501 | goto clean_up; |
498 | } | 502 | } |
499 | 503 | ||
500 | /* If we're trying to mount something specific and this isn't it, | 504 | /* If we're trying to mount something specific and this isn't it, |
@@ -529,14 +533,9 @@ int mount_main(int argc, char **argv) | |||
529 | 533 | ||
530 | // Mount this thing. | 534 | // Mount this thing. |
531 | 535 | ||
532 | rc = singlemount(mtcur); | 536 | if (singlemount(mtcur, 1)) { |
533 | if(rc) { | 537 | /* Count number of failed mounts */ |
534 | // Don't whine about already mounted fs when mounting all. | 538 | rc++; |
535 | // Note: we should probably change return value to indicate | ||
536 | // failure, without causing a duplicate error message. | ||
537 | if (errno != EBUSY) bb_perror_msg("Mounting %s on %s failed", | ||
538 | mtcur->mnt_fsname, mtcur->mnt_dir); | ||
539 | rc = 0; | ||
540 | } | 539 | } |
541 | } | 540 | } |
542 | } | 541 | } |
@@ -549,9 +548,5 @@ clean_up: | |||
549 | free(cmdopts); | 548 | free(cmdopts); |
550 | } | 549 | } |
551 | 550 | ||
552 | if(rc) | ||
553 | bb_perror_msg("Mounting %s on %s failed", | ||
554 | mtcur->mnt_fsname, mtcur->mnt_dir); | ||
555 | |||
556 | return rc; | 551 | return rc; |
557 | } | 552 | } |