Skip to contentSkip to conversation

eject: return proper 0/1 from eject_cdrom()

PATCH In review Dave Reisner 3 participants 3 messages Aug 6, 2012 – Aug 13, 2012 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eject: return proper 0/1 from eject_cdrom()

main() expects this method to return 0 for failure and 1 for success, as the other eject_*() methods do. Add the missing comparison of ioctl() >= 0

---
 sys-utils/eject.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sys-utils/eject.c +2 -2
index 08af08e..84bd342 100644
@@ -398,9 +398,9 @@ static void close_tray(int fd)
 static int eject_cdrom(int fd)
 {
 #if defined(CDROMEJECT)
-	return ioctl(fd, CDROMEJECT);
+	return ioctl(fd, CDROMEJECT) >= 0;
 #elif defined(CDIOCEJECT)
-	return ioctl(fd, CDIOCEJECT);
+	return ioctl(fd, CDIOCEJECT) >= 0;
 #else
 	warnx(_("CD-ROM eject unsupported"));
 	errno = ENOSYS;
Signature · 1 line
1.7.11.4
maintainer
#1 lore raw
Quoted 14 lines · Dave Reisner

main() expects this method to return 0 for failure and 1 for success, as the other eject_*() methods do. Add the missing comparison of ioctl() >= 0

---
 sys-utils/eject.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sys-utils/eject.c +0 -0
index 08af08e..84bd342 100644
@@ -398,9 +398,9 @@ static void close_tray(int fd)
 static int eject_cdrom(int fd)

sys-utils/eject.c static void close_tray(int fd) · line 406

Quoted 10 lines
sys-utils/eject.c +2 -2
 {
 #if defined(CDROMEJECT)
-	return ioctl(fd, CDROMEJECT);
+	return ioctl(fd, CDROMEJECT) >= 0;
 #elif defined(CDIOCEJECT)
-	return ioctl(fd, CDIOCEJECT);
+	return ioctl(fd, CDIOCEJECT) >= 0;
 #else
 	warnx(_("CD-ROM eject unsupported"));
 	errno = ENOSYS;

Good idea, but did you read the code where eject_cdrom() is called (e.g. toggle_tray()) ? I have applied the patch below.

Karel

commit 3514cc3a8f14cc39589fee3edefaa161ac1bd0a6

Author: Dave Reisner <[email protected]>
Date:   Mon Aug 6 11:16:12 2012 -0400

eject: return proper 0/1 from eject_cdrom()

main() expects this method to return 0 for failure and 1 for success, as the other eject_*() methods do. Add the missing comparison of ioctl() >= 0

sys-utils/eject.c +5 -5
index 08af08e..2097961 100644
@@ -398,13 +398,13 @@ static void close_tray(int fd)
 static int eject_cdrom(int fd)
 {
 #if defined(CDROMEJECT)
-	return ioctl(fd, CDROMEJECT);
+	return ioctl(fd, CDROMEJECT) >= 0;
 #elif defined(CDIOCEJECT)
-	return ioctl(fd, CDIOCEJECT);
+	return ioctl(fd, CDIOCEJECT) >= 0;
 #else
 	warnx(_("CD-ROM eject unsupported"));
 	errno = ENOSYS;
-	return -1;
+	return 0;
 #endif
 }
 
@@ -432,7 +432,7 @@ static void toggle_tray(int fd)
 
 	case CDS_NO_DISC:
 	case CDS_DISC_OK:
-		if (eject_cdrom(fd))
+		if (!eject_cdrom(fd))
 			err(EXIT_FAILURE, _("CD-ROM eject command failed"));
 		return;
 	case CDS_NO_INFO:
@@ -453,7 +453,7 @@ static void toggle_tray(int fd)
 	gettimeofday(&time_start, NULL);
 
 	/* Send the CDROMEJECT command to the device. */
-	if (eject_cdrom(fd) < 0)
+	if (!eject_cdrom(fd))
 		err(EXIT_FAILURE, _("CD-ROM eject command failed"));
 
 	/* Get the second timestamp, to measure the time needed to open
Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#2 lore raw
Quoted 29 lines · Karel Zak
Quoted 14 lines · Dave Reisner

main() expects this method to return 0 for failure and 1 for success, as the other eject_*() methods do. Add the missing comparison of ioctl() >= 0

---
 sys-utils/eject.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
sys-utils/eject.c +0 -0
index 08af08e..84bd342 100644
@@ -398,9 +398,9 @@ static void close_tray(int fd)
 static int eject_cdrom(int fd)

sys-utils/eject.c static void close_tray(int fd) · line 406

Quoted 10 lines
sys-utils/eject.c +2 -2
 {
 #if defined(CDROMEJECT)
-	return ioctl(fd, CDROMEJECT);
+	return ioctl(fd, CDROMEJECT) >= 0;
 #elif defined(CDIOCEJECT)
-	return ioctl(fd, CDIOCEJECT);
+	return ioctl(fd, CDIOCEJECT) >= 0;
 #else
 	warnx(_("CD-ROM eject unsupported"));
 	errno = ENOSYS;

Good idea, but did you read the code where eject_cdrom() is called (e.g. toggle_tray()) ? I have applied the patch below.

Quoted 2 lines

Karel

Ahh, good catch. Thanks!

Quoted 57 lines

commit 3514cc3a8f14cc39589fee3edefaa161ac1bd0a6

Author: Dave Reisner <[email protected]>
Date:   Mon Aug 6 11:16:12 2012 -0400

eject: return proper 0/1 from eject_cdrom()

main() expects this method to return 0 for failure and 1 for success, as the other eject_*() methods do. Add the missing comparison of ioctl() >= 0

sys-utils/eject.c +5 -5
index 08af08e..2097961 100644
@@ -398,13 +398,13 @@ static void close_tray(int fd)
 static int eject_cdrom(int fd)
 {
 #if defined(CDROMEJECT)
-	return ioctl(fd, CDROMEJECT);
+	return ioctl(fd, CDROMEJECT) >= 0;
 #elif defined(CDIOCEJECT)
-	return ioctl(fd, CDIOCEJECT);
+	return ioctl(fd, CDIOCEJECT) >= 0;
 #else
 	warnx(_("CD-ROM eject unsupported"));
 	errno = ENOSYS;
-	return -1;
+	return 0;
 #endif
 }
 
@@ -432,7 +432,7 @@ static void toggle_tray(int fd)
 
 	case CDS_NO_DISC:
 	case CDS_DISC_OK:
-		if (eject_cdrom(fd))
+		if (!eject_cdrom(fd))
 			err(EXIT_FAILURE, _("CD-ROM eject command failed"));
 		return;
 	case CDS_NO_INFO:
@@ -453,7 +453,7 @@ static void toggle_tray(int fd)
 	gettimeofday(&time_start, NULL);
 
 	/* Send the CDROMEJECT command to the device. */
-	if (eject_cdrom(fd) < 0)
+	if (!eject_cdrom(fd))
 		err(EXIT_FAILURE, _("CD-ROM eject command failed"));
 
 	/* Get the second timestamp, to measure the time needed to open
Signature · 3 lines
-- 
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com