eject -X reports "error while finding CD-ROM name".

Bug #264071 reported by Adam Buchbinder on 2008-09-02
Affects Status Importance Assigned to Milestone
eject (Debian)
Fix Released
eject (Ubuntu)

Bug Description

Binary package hint: eject

eject -X returns status 1 and the message "eject: error while finding CD-ROM name". Adding the -v option shows:

$ eject -Xv
eject: using default device `cdrom'
eject: device name is `cdrom'
eject: expanded name is `/dev/cdrom'
eject: `/dev/cdrom' is a link to `/dev/scd0'
eject: `/dev/scd0' is not mounted
eject: `/dev/scd0' is not a mount point
eject: listing CD-ROM speed
eject: error while finding CD-ROM name

It appears to be complaining because /proc/sys/dev/cdrom/info references 'sr0' rather than 'scd0'. /dev/sr0 is just another symlink to /dev/scd0. I don't know if this is a bug in the kernel (should cdrom.c be reporting 'scd0'?) or in eject (should it be following symlinks of names found in /proc/sys/dev/cdrom/info?); I'm filing it against eject as a guess.

(A workaround note: I recompiled eject telling it to look at a text file rather than in /proc, and changing the name to 'scd0' fixed it.)

I am running eject 2.1.5-6ubuntu1 on Hardy.

Attached find a patch to the original sources which will follow symlinks from the 'device name' line in /proc/sys/dev/cdrom/info.

It assumes that device names listed in the 'drive name' section of /proc/sys/dev/cdrom/info exist in /dev. If this is wrong, then this patch will break portability somewhere.

This allows the -X option to once again work on the current kernel in Hardy.

Changed in eject:
status: New → Confirmed
Kurt Litsch (kurt.litsch) wrote :

Debdiff with Adam's patch applied. Could someone in u-m-s look?

Martin Pitt (pitti) wrote :

Some issues:
 - why does the patch move around the Symlink() function? That's confusing and unnecessary IMHO. If you need it earlier, maybe just add a prototype?
 - calloc/strcat/strcat could be replaced with a single asprintf() to improve readability and robustness
 - resolving symlinks should be done with realpath(3), instead of doing a loop all by yourself
 - can you please report this to upstream?

Changed in eject:
status: Confirmed → Incomplete

Updated patch: moved SymLink() back to where it was; added a prototype before the first function that uses it. Used asprintf() instead of calloc/strcat/strcat, and added a configure check for that function. I used a loop to resolve symlinks because that's what the source does in main(), and I figured I'd use the patterns that the original coder used elsewhere. (SymLink() itself does call realpath().) I wanted to change the existing code style as little as possible.

I've already forwarded this (via email; there's no active upstream bugtracker) along with the initial version of the patch. I'm attaching the revised patch, and I'll also send it upstream.

Thanks for the review, and please let me know if you have any other updates or suggestions.

Martin Pitt (pitti) wrote :

Thanks, Adam. Some more comments:

 - ah, so SymLink() already uses and returns realpath(), so the loop is unnecessary. You'll always get the fully canonicalized file name as a result. This will make the code quite a bit easier.

 - This line

      full_str_name[strlen(full_str_name)-1] = '\0'; // chop trailing \n

   looks fishy. asprintf() does not silently append a line break, so it looks like you'd chop off the last real character? IMHO this like should just go.

 - Indeed you are right wrt. existing code style, the asprintf() configure.in check addition is a bit ugly. But don't worry too much about it, for an Ubuntu patch that's fine. Thanks for sending it upstream, if they know about it, they can change the patch to whichever style they prefer.

Thank you!

The "full_str_name[strlen(full_str_name)-1] = '\0'; // chop trailing \n" is there because str_name was returned with a trailing \n; that is, it looks something like "sr0\n" when it should read "sr0".

Changed in eject:
status: Incomplete → Confirmed
Martin Pitt (pitti) wrote :

Uploaded, now waiting in unapproved queue (will get into intrepid after the beta freeze). Thank you!

Changed in eject:
status: Confirmed → Fix Committed
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package eject - 2.1.5-9ubuntu2

eject (2.1.5-9ubuntu2) intrepid; urgency=low

  * eject.c: Resolve symbolic links when reading CD-ROM names, to fix "eject
    -X" and possibly other modes. Thanks to Adam Buchbinder for the patch!
    (Patch submitted upstream via email) LP: #264071

 -- Martin Pitt <email address hidden> Mon, 29 Sep 2008 08:20:46 +0200

Changed in eject:
status: Fix Committed → Fix Released
Changed in eject:
status: Unknown → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.