Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1iP4ls-000531-4S for mharc-grub-devel@gnu.org; Mon, 28 Oct 2019 09:09:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57217) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iP4ln-0004uJ-P2 for grub-devel@gnu.org; Mon, 28 Oct 2019 09:09:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iP4lm-0004JS-7D for grub-devel@gnu.org; Mon, 28 Oct 2019 09:09:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37206) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iP4ll-0004JF-Ut for grub-devel@gnu.org; Mon, 28 Oct 2019 09:09:14 -0400 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D096683F3D for ; Mon, 28 Oct 2019 13:09:12 +0000 (UTC) Received: by mail-wm1-f71.google.com with SMTP id k9so4009401wmb.0 for ; Mon, 28 Oct 2019 06:09:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=vqtC4mreT2c0mUIEv4vJvoQ1zQbuu8XUUg2BXdxGjio=; b=q4mMRZ/sk244U8K7v1wtcJsx6jOAHCAl6Ex3GrG0hagf35N4uJR7GawtoEBkdu6KP8 ikNfo26DW2WpVB+LDhYyWTwgJ9FSYoGTc50mj8WzYztt2dZ6mpYpvpqpjD0IsCCfCG2n LHSlWgOAdnftJcSS+FU4DXIHs1OLEFLYbzBMmVptnUgaq4JpCEJ7BxF+kZZQSWMyk3hh nneFN0cWuz0XJyHed0BLTS/nfPMspR4W+OsBB1i6bml6yLO8gZmkcN81rcHh8ms75RDW 3V6lLRRF/kB5TbcTGO2zouF0rdjGhQ84qJsJfGojq1pjoNnA35OUzNxMYjHAYwNd/Jpa qglA== X-Gm-Message-State: APjAAAVdn6iIVr9FtNKjN4qEB2q6+pfD/Q60nJcBSZItGwHkRluQhGLV c19IzHUvxGT+gcUkwGFcbweUM4gjJb2gmnCmAtIKKLcHH56QFJjYUbt8H6AfCXQ7hiHxit5V7tu VNfbbiqe2vTQ= X-Received: by 2002:a5d:4a8a:: with SMTP id o10mr15211184wrq.101.1572268151509; Mon, 28 Oct 2019 06:09:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqy42pMSZmRObG5mdmn/2gl4rwRXIZaI3Iu4qQt+97FD/13ruCQxK01fNoieBpi/kUGqZxrbCg== X-Received: by 2002:a5d:4a8a:: with SMTP id o10mr15211167wrq.101.1572268151228; Mon, 28 Oct 2019 06:09:11 -0700 (PDT) Received: from [192.168.1.13] ([90.168.169.92]) by smtp.gmail.com with ESMTPSA id i71sm11610581wri.68.2019.10.28.06.09.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 28 Oct 2019 06:09:10 -0700 (PDT) Subject: Re: [PATCH 2/2] Make editenv chase symlinks including those across devices. To: Daniel Kiper Cc: grub-devel@gnu.org, Peter Jones , Adam Jackson References: <20191018124221.15934-1-javierm@redhat.com> <20191018124221.15934-2-javierm@redhat.com> <20191023094235.5zh42wgu4uvacjag@tomti.i.net-space.pl> From: Javier Martinez Canillas Message-ID: <5efef3c7-2aef-ce89-40b3-9f0306266347@redhat.com> Date: Mon, 28 Oct 2019 14:09:09 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.0 MIME-Version: 1.0 In-Reply-To: <20191023094235.5zh42wgu4uvacjag@tomti.i.net-space.pl> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Oct 2019 13:09:18 -0000 On 10/23/19 11:42 AM, Daniel Kiper wrote: > On Fri, Oct 18, 2019 at 02:42:21PM +0200, Javier Martinez Canillas wrote: >> From: Peter Jones >> >> This lets us make /boot/grub2/grubenv a symlink to > > Who or what creates that link? > That symlink is created by the Fedora grub2-efi package. On legacy BIOS installs is just a regular file from the grub2-pc package. That way for both EFI and legacy BIOS installs the /boot/grub2/grubenv is always used, even when for EFI the grubenv is in the ESP. In both cases is the installer (Anaconda) the component that creates and sets the values of the actual grubenv file. >> /boot/efi/EFI/fedora/grubenv even though they're different mount points, >> which allows /usr/bin/grub2-editenv to be the same across platforms >> (i.e. UEFI vs BIOS). >> >> Signed-off-by: Peter Jones >> Reviewed-by: Adam Jackson >> Signed-off-by: Javier Martinez Canillas >> --- >> >> Makefile.util.def | 11 +++++++++++ >> util/editenv.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- >> 2 files changed, 55 insertions(+), 2 deletions(-) >> >> diff --git a/Makefile.util.def b/Makefile.util.def >> index 969d32f0097..733a397cb2b 100644 >> --- a/Makefile.util.def >> +++ b/Makefile.util.def >> @@ -240,8 +240,19 @@ program = { >> >> common = util/grub-editenv.c; >> common = util/editenv.c; >> + common = util/grub-install-common.c; >> common = grub-core/osdep/init.c; >> + common = grub-core/osdep/compress.c; >> + extra_dist = grub-core/osdep/unix/compress.c; >> + extra_dist = grub-core/osdep/basic/compress.c; >> + common = util/mkimage.c; >> + common = util/grub-mkimage32.c; >> + common = util/grub-mkimage64.c; >> + common = grub-core/osdep/config.c; >> + common = util/config.c; >> + common = util/resolve.c; >> >> + ldadd = '$(LIBLZMA)'; > > Hmmm... Why do we need that change? Does not it belong to different patch? > That's needed due a dependency. The patch uses grub_install_copy_file() from util/grub-install-common.c and that uses grub_install_generate_image() that is defined in util/mkimage.c, which in turn uses lzma_stream_encoder(). So all the files added to common for grub-editenv are due dependencies pulled by grub-editenv now using the grub_install_copy_file() function. >> ldadd = libgrubmods.a; >> ldadd = libgrubgcry.a; >> ldadd = libgrubkern.a; >> diff --git a/util/editenv.c b/util/editenv.c >> index eb2d0c03a98..e61dc1283a4 100644 >> --- a/util/editenv.c >> +++ b/util/editenv.c >> @@ -37,6 +37,7 @@ grub_util_create_envblk_file (const char *name) >> FILE *fp; >> char *buf; >> char *namenew; >> + char *rename_target = xstrdup(name); >> >> buf = xmalloc (DEFAULT_ENVBLK_SIZE); >> >> @@ -60,7 +61,48 @@ grub_util_create_envblk_file (const char *name) >> free (buf); >> fclose (fp); >> >> - if (grub_util_rename (namenew, name) < 0) >> - grub_util_error (_("cannot rename the file %s to %s"), namenew, name); >> + ssize_t size = 1; > > I do not like variables declarations mixed with the code in that way. > Please move it to the beginning of the function. > Ok. >> + while (1) >> + { >> + char *linkbuf; >> + ssize_t retsize; > > ...but I am OK with that... Hmmm... And it seems to me that size > can be moved here. > It can't be moved inside the while loop because the initial condition has to be set outside the loop. I'll move it at the beginning of the function as you suggested. >> + >> + linkbuf = xmalloc(size+1); > > linkbuf = xmalloc (size + 1); Missing spaces... > Ok. >> + retsize = grub_util_readlink (rename_target, linkbuf, size); >> + if (retsize < 0 && (errno == ENOENT || errno == EINVAL)) >> + { >> + free (linkbuf); >> + break; >> + } >> + else if (retsize < 0) >> + { >> + grub_util_error (_("cannot rename the file %s to %s: %m"), namenew, name); >> + free (linkbuf); >> + free (namenew); >> + return; >> + } >> + else if (retsize == size) >> + { >> + free(linkbuf); > > free (linkbuf); > Ok. >> + size += 128; >> + continue; >> + } >> + >> + free (rename_target); >> + linkbuf[retsize] = '\0'; >> + rename_target = linkbuf; >> + } >> + >> + int rc = grub_util_rename (namenew, rename_target); > > Please move this variable declaration to the beginning of function. > Ok. > Daniel > Best regards, -- Javier Martinez Canillas Software Engineer - Desktop Hardware Enablement Red Hat