Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oQsqk-0003q9-3d for mharc-grub-devel@gnu.org; Wed, 24 Aug 2022 12:03:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56044) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oQsqh-0003nk-Jp for grub-devel@gnu.org; Wed, 24 Aug 2022 12:03:24 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:56306) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oQsqf-00044O-Cy for grub-devel@gnu.org; Wed, 24 Aug 2022 12:03:22 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 91DAF22B91; Wed, 24 Aug 2022 16:03:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1661356998; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MM5Nl3R2lRkxfQyMon8fmawZJ2X3GsF2Nv+uoGRhAIk=; b=A/ohq9uh0Wgsz4i4AIfCGSvYhsfgSwBsRf0c2TtrSik99v3xzKDWthoVuNznBcHyox3qzx LbhJgX4bYUQr88Z92JBJk2Wr9TTvt61B/gqesWVfPR+n8rHJh7ws3R/QxyQbj2U9eJyqzO 7cT/OhizB3gVO7fG6+e+NTqy+uMnjXU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1661356998; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MM5Nl3R2lRkxfQyMon8fmawZJ2X3GsF2Nv+uoGRhAIk=; b=CnHntCtzyZDG4yYdJ5he/1jyf6zvBSHwwfOTt5ys3iZ1AZsOfpB6HUicImlW1a0yiCAxCQ LO8lMR52uyOYAQBg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 737B013780; Wed, 24 Aug 2022 16:03:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id i9tVGcZLBmPSLQAAMHmgww (envelope-from ); Wed, 24 Aug 2022 16:03:18 +0000 From: Ismael Luceno To: grub-devel@gnu.org Cc: Ismael Luceno Subject: [PATCH 1/2] Add helper to load linux kmods Date: Wed, 24 Aug 2022 18:03:10 +0200 Message-Id: <20220824160311.21160-2-iluceno@suse.de> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220824160311.21160-1-iluceno@suse.de> References: <20220824160311.21160-1-iluceno@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=195.135.220.28; envelope-from=iluceno@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Aug 2022 16:03:24 -0000 The function checks for already loaded (incl. built-in) modules first at /sys/module/, then tries to load it. Abort when unable to load efivarfs/efivars. Signed-off-by: Ismael Luceno --- grub-core/osdep/unix/platform.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/grub-core/osdep/unix/platform.c b/grub-core/osdep/unix/platform.c index de712211cf09..a5bf064b7cf5 100644 --- a/grub-core/osdep/unix/platform.c +++ b/grub-core/osdep/unix/platform.c @@ -26,8 +26,25 @@ #include #include #include +#include #include #include +#include + +static int +linux_kmod_load (const char *name) +{ +#ifdef __linux__ + char path[64]; + if (snprintf (path, sizeof(path), "/sys/module/%s", name) >= sizeof(path)) + grub_util_error (_("module name `%s' too long"), name); + if (!access (path, F_OK)) + return 0; + return grub_util_exec ((const char * []){ "modprobe", "-q", name, NULL }); +#else + return 0; +#endif +} static char * get_ofpathname (const char *dev) @@ -149,10 +166,9 @@ grub_install_register_efi (grub_device_t efidir_grub_dev, grub_util_error (_("%s: not found"), "efibootmgr"); } - /* On Linux, we need the efivars kernel modules. */ -#ifdef __linux__ - grub_util_exec ((const char * []){ "modprobe", "-q", "efivars", NULL }); -#endif + /* On Linux, we need efivarfs (or the legacy efivars). */ + linux_kmod_load ("efivars"); + /* Delete old entries from the same distributor. */ ret = grub_install_remove_efi_entries_by_distributor (efi_distributor); if (ret) -- 2.37.1