From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1XVjnw-0000wG-Nr for mharc-grub-devel@gnu.org; Sun, 21 Sep 2014 12:16:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37398) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVjnm-0000vf-4w for grub-devel@gnu.org; Sun, 21 Sep 2014 12:16:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XVjnZ-00084t-F5 for grub-devel@gnu.org; Sun, 21 Sep 2014 12:15:54 -0400 Received: from mail-we0-x234.google.com ([2a00:1450:400c:c03::234]:42217) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XVjnZ-00084E-4E for grub-devel@gnu.org; Sun, 21 Sep 2014 12:15:41 -0400 Received: by mail-we0-f180.google.com with SMTP id u56so1781918wes.39 for ; Sun, 21 Sep 2014 09:15:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; bh=ha90zyrZuLn02neY7w2wXYq0o5UScFQuM5R5H6Xu+CE=; b=ZGIS3f5QbuKTYLXGIdn5mDyHxDAJc+4NieiWQPcvAcaP0dORIZB064elKZ06z/OP9U u/07RQqrMPfIccC5SfA9UENb8V8MYcpf8E3goZ6kCm1U5bTAUMKBZQLG7mFe/LL0lXj1 z9dLzG+kREzO8uuvQNrno2TGMiJEiKkENnFPQW55tQxHAq/OxUQHE2eHHG9+ru9nB6iH p8s3UaZW2FoODYOsyKK2taoKXFw9fjdOaeH1EIOu+7sofAdUSsGXb90728a6lrqEsd5B Y1+a+6ddlJlm9q5eE7s0IMPaEVSqAytTdxj4KzwKialj4rSEmu7++yXCBRAJGTf7bNCE fGpw== X-Received: by 10.194.243.161 with SMTP id wz1mr15263289wjc.0.1411316135382; Sun, 21 Sep 2014 09:15:35 -0700 (PDT) Received: from [192.168.42.4] (160-228.197-178.cust.bluewin.ch. [178.197.228.160]) by mx.google.com with ESMTPSA id i5sm9371654wjz.0.2014.09.21.09.15.33 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Sep 2014 09:15:34 -0700 (PDT) Message-ID: <541EF9A3.60409@gmail.com> Date: Sun, 21 Sep 2014 18:15:31 +0200 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.0 MIME-Version: 1.0 To: The development of GNU GRUB Subject: Re: [PATCH 2/2] Make editenv chase symlinks including those across devices. References: <1409845015-16778-1-git-send-email-pjones@redhat.com> <1409845015-16778-3-git-send-email-pjones@redhat.com> In-Reply-To: <1409845015-16778-3-git-send-email-pjones@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="MU79PphgxS5E6OGg7hqRMkis7NfJ2VKIn" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c03::234 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Sep 2014 16:16:03 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --MU79PphgxS5E6OGg7hqRMkis7NfJ2VKIn Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 04.09.2014 17:36, Peter Jones wrote: > This lets us make /boot/grub2/grubenv a symlink to > /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). >=20 > Signed-off-by: Peter Jones > Reviewed-by: Adam Jackson > --- > Makefile.util.def | 9 +++++++++ > util/editenv.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- > 2 files changed, 53 insertions(+), 2 deletions(-) >=20 > diff --git a/Makefile.util.def b/Makefile.util.def > index 8f40e78..87029a1 100644 > --- a/Makefile.util.def > +++ b/Makefile.util.def > @@ -228,8 +228,17 @@ program =3D { > =20 > common =3D util/grub-editenv.c; > common =3D util/editenv.c; > + common =3D util/grub-install-common.c; > common =3D grub-core/osdep/init.c; > + common =3D grub-core/osdep/compress.c; > + extra_dist =3D grub-core/osdep/unix/compress.c; > + extra_dist =3D grub-core/osdep/basic/compress.c; > + common =3D util/mkimage.c; > + common =3D grub-core/osdep/config.c; > + common =3D util/config.c; > + common =3D util/resolve.c; > =20 > + ldadd =3D '$(LIBLZMA)'; > ldadd =3D libgrubmods.a; > ldadd =3D libgrubgcry.a; > ldadd =3D libgrubkern.a; > diff --git a/util/editenv.c b/util/editenv.c > index c6f8d22..d8d1dad 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 =3D xstrdup(name); > =20 > buf =3D xmalloc (DEFAULT_ENVBLK_SIZE); > =20 > @@ -59,7 +60,48 @@ grub_util_create_envblk_file (const char *name) > free (buf); > fclose (fp); > =20 > - if (grub_util_rename (namenew, name) < 0) > - grub_util_error (_("cannot rename the file %s to %s"), namenew, na= me); > + ssize_t size =3D 1; > + while (1) > + { > + char *linkbuf; > + ssize_t retsize; > + > + linkbuf =3D xmalloc(size+1); > + retsize =3D grub_util_readlink (rename_target, linkbuf, size); If I get this code correctly you essentially canonicalize the link manually. Why not use already available canonicalization functions? > + if (retsize < 0 && (errno =3D=3D ENOENT || errno =3D=3D 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 =3D=3D size) > + { > + free(linkbuf); > + size +=3D 128; > + continue; > + } > + > + free (rename_target); > + linkbuf[retsize] =3D '\0'; > + rename_target =3D linkbuf; > + } > + > + int rc =3D grub_util_rename (namenew, rename_target); > + if (rc < 0 && errno =3D=3D EXDEV) > + { > + rc =3D grub_install_copy_file (namenew, rename_target, 1); > + grub_util_unlink (namenew); > + } > + > + if (rc < 0) > + grub_util_error (_("cannot rename the file %s to %s: %m"), namenew= , name); > + > free (namenew); > + free (rename_target); > } >=20 --MU79PphgxS5E6OGg7hqRMkis7NfJ2VKIn Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iF4EAREKAAYFAlQe+aMACgkQmBXlbbo5nOvYEAD+O6LMjHYP/gQ1BfH52onZFEIT ahtrDtsoDtvsflEVaIoA/jGZhqJ9Qi6UumVyF8czGLBnHA9JtKwsaFwPrpSOmfVV =43fe -----END PGP SIGNATURE----- --MU79PphgxS5E6OGg7hqRMkis7NfJ2VKIn--