From patchwork Tue Aug 16 00:50:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Amiantov X-Patchwork-Id: 9282449 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 375556086A for ; Tue, 16 Aug 2016 00:58:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2968D28ED3 for ; Tue, 16 Aug 2016 00:58:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B05C28ED8; Tue, 16 Aug 2016 00:58:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 91A9328ED6 for ; Tue, 16 Aug 2016 00:58:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750796AbcHPA6P (ORCPT ); Mon, 15 Aug 2016 20:58:15 -0400 Received: from fmap.me ([91.92.66.84]:33934 "EHLO smtp.fmap.me" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752258AbcHPA6O (ORCPT ); Mon, 15 Aug 2016 20:58:14 -0400 From: Nikolay Amiantov DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fmap.me; s=mail; t=1471308640; bh=ssV9uXVGjRvLWvFIIcfvQnUxr46wkUra3UcvMWJ6eZ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PAMZka3OhpogNeX9o3DoGA4FXpkMDNECOMbEmvafeSRGYi5NeZffOht99sMOdysan 6PhoeCH/j+j2nzNkNw+S0ACBtobC6SXX5fTdull4Ruot4ndVrt+Go9rBOu97M8txzK 7PXGceEZuJkyqi7P/Ai3BXn07T8aPf2o+q44SLJ0= To: linux-modules@vger.kernel.org Cc: Shea Levy Subject: [PATCH 1/4] libkmod: add MODULE_DIR to override kernel modules directory Date: Tue, 16 Aug 2016 03:50:29 +0300 Message-Id: <20160816005032.28881-2-ab@fmap.me> In-Reply-To: <20160816005032.28881-1-ab@fmap.me> References: <20160816005032.28881-1-ab@fmap.me> Sender: owner-linux-modules@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Shea Levy It is used as a path if this environment variable is set, and `uname -r` is appended to the end. Otherwise, default /lib/modules/`uname -r` is used as usual. --- libkmod/libkmod.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c index 69fe431..7b0247f 100644 --- a/libkmod/libkmod.c +++ b/libkmod/libkmod.c @@ -211,7 +211,7 @@ static const char *dirname_default_prefix = "/lib/modules"; static char *get_kernel_release(const char *dirname) { struct utsname u; - char *p; + char *p, *dirname_prefix; if (dirname != NULL) return path_make_absolute_cwd(dirname); @@ -219,7 +219,10 @@ static char *get_kernel_release(const char *dirname) if (uname(&u) < 0) return NULL; - if (asprintf(&p, "%s/%s", dirname_default_prefix, u.release) < 0) + if ((dirname_prefix = getenv("MODULE_DIR")) == NULL) + dirname_prefix = dirname_default_prefix; + + if (asprintf(&p, "%s/%s", dirname_prefix, u.release) < 0) return NULL; return p;