* [PATCH] eject: return proper 0/1 from eject_cdrom()
@ 2012-08-06 15:16 Dave Reisner
2012-08-13 13:48 ` Karel Zak
0 siblings, 1 reply; 3+ messages in thread
From: Dave Reisner @ 2012-08-06 15:16 UTC (permalink / raw)
To: util-linux; +Cc: 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
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
---
sys-utils/eject.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sys-utils/eject.c b/sys-utils/eject.c
index 08af08e..84bd342 100644
--- a/sys-utils/eject.c
+++ b/sys-utils/eject.c
@@ -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;
--
1.7.11.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] eject: return proper 0/1 from eject_cdrom()
2012-08-06 15:16 [PATCH] eject: return proper 0/1 from eject_cdrom() Dave Reisner
@ 2012-08-13 13:48 ` Karel Zak
2012-08-13 14:44 ` Dave Reisner
0 siblings, 1 reply; 3+ messages in thread
From: Karel Zak @ 2012-08-13 13:48 UTC (permalink / raw)
To: Dave Reisner; +Cc: util-linux
On Mon, Aug 06, 2012 at 11:16:12AM -0400, Dave Reisner wrote:
> 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
>
> Signed-off-by: Dave Reisner <dreisner@archlinux.org>
> ---
> sys-utils/eject.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/sys-utils/eject.c b/sys-utils/eject.c
> index 08af08e..84bd342 100644
> --- a/sys-utils/eject.c
> +++ b/sys-utils/eject.c
> @@ -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;
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 <dreisner@archlinux.org>
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
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
diff --git a/sys-utils/eject.c b/sys-utils/eject.c
index 08af08e..2097961 100644
--- a/sys-utils/eject.c
+++ b/sys-utils/eject.c
@@ -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
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] eject: return proper 0/1 from eject_cdrom()
2012-08-13 13:48 ` Karel Zak
@ 2012-08-13 14:44 ` Dave Reisner
0 siblings, 0 replies; 3+ messages in thread
From: Dave Reisner @ 2012-08-13 14:44 UTC (permalink / raw)
To: Karel Zak; +Cc: Dave Reisner, util-linux
On Mon, Aug 13, 2012 at 03:48:58PM +0200, Karel Zak wrote:
> On Mon, Aug 06, 2012 at 11:16:12AM -0400, Dave Reisner wrote:
> > 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
> >
> > Signed-off-by: Dave Reisner <dreisner@archlinux.org>
> > ---
> > sys-utils/eject.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/sys-utils/eject.c b/sys-utils/eject.c
> > index 08af08e..84bd342 100644
> > --- a/sys-utils/eject.c
> > +++ b/sys-utils/eject.c
> > @@ -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;
>
> Good idea, but did you read the code where eject_cdrom() is called
> (e.g. toggle_tray()) ? I have applied the patch below.
>
> Karel
>
Ahh, good catch. Thanks!
> commit 3514cc3a8f14cc39589fee3edefaa161ac1bd0a6
> Author: Dave Reisner <dreisner@archlinux.org>
> 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
>
> Signed-off-by: Dave Reisner <dreisner@archlinux.org>
> Signed-off-by: Karel Zak <kzak@redhat.com>
>
> diff --git a/sys-utils/eject.c b/sys-utils/eject.c
> index 08af08e..2097961 100644
> --- a/sys-utils/eject.c
> +++ b/sys-utils/eject.c
> @@ -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
>
>
>
> --
> Karel Zak <kzak@redhat.com>
> http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-08-13 14:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-06 15:16 [PATCH] eject: return proper 0/1 from eject_cdrom() Dave Reisner
2012-08-13 13:48 ` Karel Zak
2012-08-13 14:44 ` Dave Reisner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).