From owner-freebsd-ports-bugs@FreeBSD.ORG Tue Apr 15 15:30:18 2003 Return-Path: Delivered-To: freebsd-ports-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4ACA537B401 for ; Tue, 15 Apr 2003 15:30:18 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 262E643FAF for ; Tue, 15 Apr 2003 15:30:17 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id h3FMUGUp090676 for ; Tue, 15 Apr 2003 15:30:16 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h3FMUGx1090675; Tue, 15 Apr 2003 15:30:16 -0700 (PDT) Resent-Date: Tue, 15 Apr 2003 15:30:16 -0700 (PDT) Resent-Message-Id: <200304152230.h3FMUGx1090675@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-ports-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, The Anarcat Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B820D37B401 for ; Tue, 15 Apr 2003 15:22:15 -0700 (PDT) Received: from aeimail.aei.ca (aeimail.aei.ca [206.123.6.14]) by mx1.FreeBSD.org (Postfix) with ESMTP id AFD4B43FCB for ; Tue, 15 Apr 2003 15:22:14 -0700 (PDT) (envelope-from anarcat@anarcat.ath.cx) Received: from shall.anarcat.ath.cx (42bw74i6suig2exw@dsl-133-253.aei.ca [66.36.133.253]) by aeimail.aei.ca (8.11.6/8.10.1) with ESMTP id h3FMME107825 for ; Tue, 15 Apr 2003 18:22:14 -0400 (EDT) Received: from lenny.anarcat.ath.cx (lenny.anarcat.ath.cx [192.168.0.4]) by shall.anarcat.ath.cx (Postfix) with SMTP id 0803A243; Tue, 15 Apr 2003 18:22:12 -0400 (EDT) Received: by lenny.anarcat.ath.cx (sSMTP sendmail emulation); Tue, 15 Apr 2003 18:22:18 -0400 Message-Id: <20030415222213.0803A243@shall.anarcat.ath.cx> Date: Tue, 15 Apr 2003 18:22:18 -0400 From: The Anarcat To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: ports/51008: making sysutils/eject understand cdrom argument X-BeenThere: freebsd-ports-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: The Anarcat List-Id: Ports bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Apr 2003 22:30:18 -0000 >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@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: