summaryrefslogtreecommitdiff
path: root/usr.bin/cdio/cdio.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1998-12-20 23:53:36 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1998-12-20 23:53:36 +0000
commit9fa174d4c8e9a0e575ccd0484e10e5778bbc1edd (patch)
treee70726f1e5fb1aafec58cd1cb1d33dc895d66a16 /usr.bin/cdio/cdio.c
parent69669d0e56a41b937b60f9c0844ffc9f87cf335c (diff)
If open of device fails, try up to 10 times. Useful for CD changers that take a while to switch between logical units
Diffstat (limited to 'usr.bin/cdio/cdio.c')
-rw-r--r--usr.bin/cdio/cdio.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/usr.bin/cdio/cdio.c b/usr.bin/cdio/cdio.c
index 1a275d5aa61..3e3c6c8804d 100644
--- a/usr.bin/cdio/cdio.c
+++ b/usr.bin/cdio/cdio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cdio.c,v 1.11 1998/07/09 20:10:26 csapuntz Exp $ */
+/* $OpenBSD: cdio.c,v 1.12 1998/12/20 23:53:35 millert Exp $ */
/*
* Compact Disc Control Utility by Serge V. Vakulenko <vak@cronyx.ru>.
* Based on the non-X based CD player by Jean-Marc Zucconi and
@@ -1164,19 +1164,30 @@ int open_cd (dev)
char *dev;
{
char *realdev;
+ int tries;
if (fd > -1)
return (1);
- fd = opendev(dev, O_RDONLY, OPENDEV_PART, &realdev);
- if (fd < 0) {
- if ((errno == ENXIO) || (errno == EIO)) {
- /* ENXIO has an overloaded meaning here.
- * The original "Device not configured" should
- * be interpreted as "No disc in drive %s". */
- warnx ("No disc in drive %s.", realdev);
- return (0);
+ for (tries = 0; fd < 0 && tries < 10; tries++) {
+ fd = opendev(dev, O_RDONLY, OPENDEV_PART, &realdev);
+ if (fd < 0) {
+ if (errno == ENXIO) {
+ /* ENXIO has an overloaded meaning here.
+ * The original "Device not configured" should
+ * be interpreted as "No disc in drive %s". */
+ warnx ("No disc in drive %s.", realdev);
+ return (0);
+ } else if (errno != EIO) {
+ /* EIO may simply mean the device is not ready
+ * yet which is common with CD changers. */
+ warn ("Can't open %s", realdev);
+ return (0);
+ }
}
+ sleep (1);
+ }
+ if (fd < 0) {
warn ("Can't open %s", realdev);
return (0);
}