Bug 51008 - making sysutils/eject understand cdrom argument
Summary: making sysutils/eject understand cdrom argument
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-ports-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-04-15 23:30 UTC by Antoine Beaupre
Modified: 2003-09-29 15:19 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Antoine Beaupre 2003-04-15 23:30:16 UTC
The sysutils/eject port is quite useful to eject those cdroms and
other removeable media. However, you need to know the "real" name of
the device in order to eject it.

Indeed, eject(1), given a "arg" argument tries to eject from the
"/dev/argc" device, which is good, but could be better.

The attached patch makes it look around a bit more, first in /dev/arg,
then /dev/argc and just plain ./arg.

Also, if the file found is a symlink, the patch makes eject unfold the
link to find what device is behind it so it can umount it correctly.

Fix: 

Attach the following patch to the ports infrastructure. 

I tried to contact the author of the original software: no response.

--- eject.c	2003/04/04 04:55:07	1.1
+++ eject.c	2003/04/06 22:09:37	1.3
@@ -104,6 +104,15 @@
     if (sts < 0) {
 	perror(program);
 	exit(1);
+    } else {
+         int c;
+         char *dev_bak = malloc(MAXPATHLEN);
+         if (c = readlink(device, dev_bak, MAXPATHLEN)) {
+              dev_bak[c] = '\0';
+              name = dev_bak;
+         } else {
+              free(dev_bak);
+         }
     }
 
     sts = unmount_fs(name, &err);
@@ -130,15 +139,23 @@
     char *name;
     char **device;
 {
-    int sts;
+    int sts, i;
     struct stat sb;
-
-    if (asprintf(device, "/dev/%sc", name) == -1)
-	return sts;
-    if (vflag || nflag) {
-	printf("%s: using device %s\n", program, *device);
+    const char* dev_list[] = { "/dev/%sc", "/dev/%s", "%s" };
+    for (i = 0; i < 2; i++) {
+         if (asprintf(device, dev_list[i], name) == -1)
+              return sts;
+         if (vflag || nflag) {
+              printf("%s: trying device %s\n", program, *device);
+         }
+         sts = stat(*device, &sb);
+         if (sts) { /* stat failed, try next */
+              free(*device);
+              continue;
+         } else {
+              break;
+         }
     }
-    sts = stat(*device, &sb);
 
     return sts;
 }
How-To-Repeat: 
try to umount cdrom or umount cdr
Comment 1 Edwin Groothuis freebsd_committer freebsd_triage 2003-09-29 15:19:21 UTC
State Changed
From-To: open->closed

Commited, thanks!