ports/51008: making sysutils/eject understand cdrom argument

The Anarcat anarcat at anarcat.ath.cx
Tue Apr 15 22:30:18 UTC 2003


>Number:         51008
>Category:       ports
>Synopsis:       making sysutils/eject understand cdrom argument
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Apr 15 15:30:16 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator:     The Anarcat
>Release:        FreeBSD 5.0-RELEASE i386
>Organization:
>Environment:
System: FreeBSD lenny.anarcat.ath.cx 5.0-RELEASE FreeBSD 5.0-RELEASE #3: Mon Mar 24 15:39:05 EST 2003 anarcat at lenny.anarcat.ath.cx:/usr/src/sys/i386/compile/LENNII i386


	
>Description:

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.

>How-To-Repeat:

try to umount cdrom or umount cdr

>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;
 }



>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-ports-bugs mailing list