File eject-2.1.0-toggle.diff of Package eject
--- eject.c
+++ eject.c
@@ -471,8 +471,23 @@
{
struct timeval time_start, time_stop;
int time_elapsed;
+ int status;
#ifdef CDROMCLOSETRAY
+
+ status = ioctl(fd, CDROM_DRIVE_STATUS);
+
+ if (status == CDS_TRAY_OPEN){
+ CloseTray(fd);
+ return;
+ }
+ else if (status == CDS_NO_DISC || status == CDS_DISC_OK){
+ if (ioctl(fd, CDROMEJECT, 0) < 0) {
+ perror("ioctl");
+ exit(1);
+ }
+ return;
+ }
/* Try to open the CDROM tray and measure the time therefor
* needed. In my experience the function needs less than 0.05