umount: do not try to close FILE* which is NULL.

This commit is contained in:
Denis Vlasenko 2006-09-14 16:40:46 +00:00
parent be507170eb
commit af9854b81a

View File

@ -59,8 +59,9 @@ int umount_main(int argc, char **argv)
if (!(fp = setmntent(bb_path_mtab_file, "r"))) { if (!(fp = setmntent(bb_path_mtab_file, "r"))) {
if (opt & OPT_ALL) if (opt & OPT_ALL)
bb_error_msg_and_die("Cannot open %s", bb_path_mtab_file); bb_error_msg_and_die("cannot open %s", bb_path_mtab_file);
} else while (getmntent_r(fp,&me,path,sizeof(path))) { } else {
while (getmntent_r(fp,&me,path,sizeof(path))) {
m = xmalloc(sizeof(struct mtab_list)); m = xmalloc(sizeof(struct mtab_list));
m->next = mtl; m->next = mtl;
m->device = xstrdup(me.mnt_fsname); m->device = xstrdup(me.mnt_fsname);
@ -68,6 +69,7 @@ int umount_main(int argc, char **argv)
mtl = m; mtl = m;
} }
endmntent(fp); endmntent(fp);
}
/* If we're not mounting all, we need at least one argument. */ /* If we're not mounting all, we need at least one argument. */
if (!(opt & OPT_ALL)) { if (!(opt & OPT_ALL)) {
@ -111,13 +113,13 @@ int umount_main(int argc, char **argv)
// If still can't umount, maybe remount read-only? // If still can't umount, maybe remount read-only?
if (curstat && (opt & OPT_REMOUNT) && errno == EBUSY && m) { if (curstat && (opt & OPT_REMOUNT) && errno == EBUSY && m) {
curstat = mount(m->device, zapit, NULL, MS_REMOUNT|MS_RDONLY, NULL); curstat = mount(m->device, zapit, NULL, MS_REMOUNT|MS_RDONLY, NULL);
bb_error_msg(curstat ? "Cannot remount %s read-only" : bb_error_msg(curstat ? "cannot remount %s read-only" :
"%s busy - remounted read-only", m->device); "%s busy - remounted read-only", m->device);
} }
if (curstat) { if (curstat) {
status = EXIT_FAILURE; status = EXIT_FAILURE;
bb_perror_msg("Couldn't umount %s", zapit); bb_perror_msg("cannot umount %s", zapit);
} else { } else {
/* De-allocate the loop device. This ioctl should be ignored on /* De-allocate the loop device. This ioctl should be ignored on
* any non-loop block devices. */ * any non-loop block devices. */