From nobody Wed Feb 16 07:53:13 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id BC80719C9516; Wed, 16 Feb 2022 07:53:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Jz9Dn4xzlz4X4L; Wed, 16 Feb 2022 07:53:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644997993; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qOEMzDgD+VMxkQyZA6o3dwSiRT6Zu4WGFXMHCukvmbY=; b=hUb923yk9JLnlUl5j21bVBFaPivWJSTWZ4Gk8IhwftPC6CBXBP8gA+Lra73q7L/Q0cpXYC x0QbjHd3xdLpQC9U/Zpspi+eqC75VCePlFxEu9BV/dgrq3jfuecHEUDBrfgQnEl40EPeju 1q7rcUWU+I4d1bW+KrvAfUCanZ+NHoQNz17ob6NvGYgzqOGdpHPG6VfLsqBJbBe/8zH3Rt Bmv9W02o+9WXJYAu3bAEKFAVxGge5Mor/uNM3qAci/nwkZh7cWn8jl2svnLQ/1vq6yiCY3 6d4K2mJB4U4L7xf6/mnqC4KR6iPgvPBwwiwMpl9ZCfJThr3SU174JumNxEhNRQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 89A9212925; Wed, 16 Feb 2022 07:53:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 21G7rDMQ046321; Wed, 16 Feb 2022 07:53:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21G7rD9q046320; Wed, 16 Feb 2022 07:53:13 GMT (envelope-from git) Date: Wed, 16 Feb 2022 07:53:13 GMT Message-Id: <202202160753.21G7rD9q046320@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Andriy Gapon Subject: git: e32acf95ea25 - stable/13 - cam_get_device: resolve path links before parsing device name List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: avg X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: e32acf95ea25ca2f6faf92fff2acfba298dfa378 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644997993; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qOEMzDgD+VMxkQyZA6o3dwSiRT6Zu4WGFXMHCukvmbY=; b=jQ2+TPZ4ePVunTqqMIWZFQE+dbTryIv0hsqNW5RMCn8f/Lfj/Cil3Zm9+32tLs5HUm9Bu/ ZJNqnugr5t9p/N/UKXhpqxuasEJA8qOuk7PJGlVq8CBLTKS+f8ajgcbfTInhesiwiJNUBg w51IU7GtBAJmgbPOdUqIq/H1tlyN1EbbtLxNJDtDzDbnnONw/q7OhL38Fmh6i0s95pX1SH LKPTW3RalIaZgMt6WXm4vI2eBrgRKZAoEeWYfLYysWFukc/OJZ+AWmKMJ9bjHHQaTy4zWL bEyqQTQSUxcqAbTeExFgYeSWQt7ofFtSumgN1Ozbs0HLpHKpTF73ho5HnQJPFg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1644997993; a=rsa-sha256; cv=none; b=MRtY12iXf82xaxNUvVrHkW16d9wkrMkmyFgQBOYry547s8zas7KFoQ3iBgKszIxNcRvtOz vRxLAhrQSPIIp6YN2v9O/X5La+R6LCg4UleiDnhHg/GFmFr+GNVm89NY6eTfz6DAnFGIsW ZXKe5vv+iguHZFYs9CS3i14tGnEyIa9wYz2XFtmMtRmwdg/yFWW6Cu/ihLUuUNr6ugxJp+ M32bM4QgDKE8Oy8mO6fl6e/2KmwnxSdOpWv9RPHhByTqcLCa8bAR+6YHbC1hSJimbRFTgE 125YBqnaaNRvnrmTtYxPYkIejH6JyLRCtOj2g+1/zDZ6yOaMpyFlxuPWpRp4Dg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=e32acf95ea25ca2f6faf92fff2acfba298dfa378 commit e32acf95ea25ca2f6faf92fff2acfba298dfa378 Author: Andriy Gapon AuthorDate: 2021-11-27 18:49:08 +0000 Commit: Andriy Gapon CommitDate: 2022-02-16 07:52:53 +0000 cam_get_device: resolve path links before parsing device name The CAM subsystem uses bus:taget:lun tuple to address peripherals. But for convenience many userland programs such as camcontrol accept devices names such as da0. There is a libcam function, cam_open_device, to support that. It first calls cam_get_device() to parse the device name as a driver name and a unit (and handle some special device name prefixes) and then uses cam_lookup_pass() to find a matching pass device. This change extends cam_get_device() to apply realpath(3) to the device name before parsing it. This will allow to use tools such as camcontrol and smartctl with symbolic links that could be friendlier (more distinguished) names for devices. Relnotes: maybe (cherry picked from commit 1abf1e8c6b13f50eed08fef6fb1ade280894f1e4) --- lib/libcam/camlib.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/libcam/camlib.c b/lib/libcam/camlib.c index 438b0e502fe0..6ebdb30ab82b 100644 --- a/lib/libcam/camlib.c +++ b/lib/libcam/camlib.c @@ -128,10 +128,13 @@ cam_get_device(const char *path, char *dev_name, int devnamelen, int *unit) } /* - * We can be rather destructive to the path string. Make a copy of - * it so we don't hose the user's string. + * Resolve the given path to a real device path in case we are given + * an alias or other symbolic link. If the path cannot be resolved + * then try to parse it as is. */ - newpath = (char *)strdup(path); + newpath = realpath(path, NULL); + if (newpath == NULL) + newpath = strdup(path); if (newpath == NULL) return (-1);