char *disk = NULL;
char *mountpoint = NULL;
int worked = 0; /* set to 1 when successfully ejected */
- struct eject_control ctl = { NULL };
+ struct eject_control ctl = { .fd = -1 };
setlocale(LC_ALL,"");
bindtextdomain(PACKAGE, LOCALEDIR);
if (ctl.n_option) {
info(_("device is `%s'"), ctl.device);
verbose(&ctl, _("exiting due to -n/--noop option"));
- return EXIT_SUCCESS;
+ goto done;
}
/* handle -i option */
if (ctl.i_option) {
open_device(&ctl);
manual_eject(&ctl);
- return EXIT_SUCCESS;
+ goto done;
}
/* handle -a option */
verbose(&ctl, _("%s: disabling auto-eject mode"), ctl.device);
open_device(&ctl);
auto_eject(&ctl);
- return EXIT_SUCCESS;
+ goto done;
}
/* handle -t option */
open_device(&ctl);
close_tray(ctl.fd);
set_device_speed(&ctl);
- return EXIT_SUCCESS;
+ goto done;
}
/* handle -T option */
open_device(&ctl);
toggle_tray(ctl.fd);
set_device_speed(&ctl);
- return EXIT_SUCCESS;
+ goto done;
}
/* handle -X option */
verbose(&ctl, _("%s: listing CD-ROM speed"), ctl.device);
open_device(&ctl);
list_speeds(&ctl);
- return EXIT_SUCCESS;
+ goto done;
}
/* handle -x option only */
open_device(&ctl);
changer_select(&ctl);
set_device_speed(&ctl);
- return EXIT_SUCCESS;
+ goto done;
}
/* if user did not specify type of eject, try all four methods */
if (!worked)
errx(EXIT_FAILURE, _("unable to eject"));
+done:
/* cleanup */
- close(ctl.fd);
+ if (ctl.fd >= 0)
+ close(ctl.fd);
+
free(ctl.device);
free(mountpoint);