teknoraver / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone

Blame 0018-Make-sure-to-reset-file-attributes-for-generated-bui.patch

Igor Gnatenko 082d5d
From 651264c51dfb13bf78bb969a429719f301497631 Mon Sep 17 00:00:00 2001
Igor Gnatenko 082d5d
From: Mark Wielaard <mark@klomp.org>
Igor Gnatenko 082d5d
Date: Wed, 15 Mar 2017 20:07:29 +0100
Igor Gnatenko 082d5d
Subject: [PATCH 18/49] Make sure to reset file attributes for generated
Igor Gnatenko 082d5d
 build-id directories.
Mark Wielaard 117a78
Igor Gnatenko 082d5d
[Note this patch is currently being tested in Fedora. See bug below.]
Mark Wielaard 117a78
Igor Gnatenko 082d5d
When creating the build-id directories we should reset the file attributes
Igor Gnatenko 082d5d
to the defaults. Otherwise if the file list contained an %attr or %defattr
Igor Gnatenko 082d5d
the directories would come out with the wrong mode.
Mark Wielaard 117a78
Igor Gnatenko 082d5d
Includes a testcase based on a spec by Igor Gnatenko that fails before
Igor Gnatenko 082d5d
and Check that build-id directories are created with the right permissions
Igor Gnatenko 082d5d
even if the spec file sets attrs explicitly.
Igor Gnatenko 082d5d
Igor Gnatenko 082d5d
https://bugzilla.redhat.com/show_bug.cgi?id=1432372
Igor Gnatenko 082d5d
Igor Gnatenko 082d5d
Signed-off-by: Mark Wielaard <mark@klomp.org>
Igor Gnatenko 082d5d
(cherry picked from commit b91dc6106e360f13ff365dfac247191942039152)
Igor Gnatenko 082d5d
---
Igor Gnatenko 082d5d
 build/files.c                            | 21 +++++++++++++++++++
Igor Gnatenko 082d5d
 tests/Makefile.am                        |  2 ++
Igor Gnatenko 082d5d
 tests/data/SOURCES/hello.c               |  8 +++++++
Igor Gnatenko 082d5d
 tests/data/SPECS/hello-attr-buildid.spec | 27 ++++++++++++++++++++++++
Igor Gnatenko 082d5d
 tests/rpmbuildid.at                      | 36 ++++++++++++++++++++++++++++++++
Igor Gnatenko 082d5d
 5 files changed, 94 insertions(+)
Igor Gnatenko 082d5d
 create mode 100644 tests/data/SOURCES/hello.c
Igor Gnatenko 082d5d
 create mode 100644 tests/data/SPECS/hello-attr-buildid.spec
Igor Gnatenko 082d5d
Igor Gnatenko 082d5d
diff --git a/build/files.c b/build/files.c
Igor Gnatenko 082d5d
index fef0c6960..728a44ba2 100644
Igor Gnatenko 082d5d
--- a/build/files.c
Igor Gnatenko 082d5d
+++ b/build/files.c
Igor Gnatenko 082d5d
@@ -1770,6 +1770,7 @@ static int generateBuildIDs(FileList fl)
Igor Gnatenko 082d5d
 	char *mainiddir = NULL;
Igor Gnatenko 082d5d
 	char *debugiddir = NULL;
Igor Gnatenko 082d5d
 	if (rc == 0) {
Igor Gnatenko 082d5d
+	    char *attrstr;
Igor Gnatenko 082d5d
 	    /* Add .build-id directories to hold the subdirs/symlinks.  */
Igor Gnatenko 082d5d
             #define BUILD_ID_DIR "/usr/lib/.build-id"
Igor Gnatenko 082d5d
             #define DEBUG_ID_DIR "/usr/lib/debug/.build-id"
Igor Gnatenko 082d5d
@@ -1777,6 +1778,18 @@ static int generateBuildIDs(FileList fl)
Igor Gnatenko 082d5d
 	    mainiddir = rpmGetPath(fl->buildRoot, BUILD_ID_DIR, NULL);
Igor Gnatenko 082d5d
 	    debugiddir = rpmGetPath(fl->buildRoot, DEBUG_ID_DIR, NULL);
Igor Gnatenko 082d5d
 
Igor Gnatenko 082d5d
+	    /* Make sure to reset all file flags to defaults.
Igor Gnatenko 082d5d
+	       Uses parseForAttr to reset ar, arFlags, and specdFlags.
Igor Gnatenko 082d5d
+	       Note that parseForAttr pokes at the attrstr, so we cannot
Igor Gnatenko 082d5d
+	       just pass a static string. */
Igor Gnatenko 082d5d
+	    fl->def.verifyFlags = RPMVERIFY_ALL;
Igor Gnatenko 082d5d
+	    fl->cur.verifyFlags = RPMVERIFY_ALL;
Igor Gnatenko 082d5d
+	    fl->def.specdFlags |= SPECD_VERIFY;
Igor Gnatenko 082d5d
+	    fl->cur.specdFlags |= SPECD_VERIFY;
Igor Gnatenko 082d5d
+	    attrstr = xstrdup ("%defattr(-,root,root)");
Igor Gnatenko 082d5d
+	    parseForAttr(fl->pool, attrstr, 1, &fl->def);
Igor Gnatenko 082d5d
+	    free (attrstr);
Igor Gnatenko 082d5d
+
Igor Gnatenko 082d5d
 	    /* Supported, but questionable.  */
Igor Gnatenko 082d5d
 	    if (needMain && needDbg)
Igor Gnatenko 082d5d
 		rpmlog(RPMLOG_WARNING,
Igor Gnatenko 082d5d
@@ -1786,8 +1799,12 @@ static int generateBuildIDs(FileList fl)
Igor Gnatenko 082d5d
 		if ((rc = rpmioMkpath(mainiddir, 0755, -1, -1)) != 0) {
Igor Gnatenko 082d5d
 		    rpmlog(RPMLOG_ERR, "%s %s: %m\n", errdir, mainiddir);
Igor Gnatenko 082d5d
 		} else {
Igor Gnatenko 082d5d
+		    rasprintf (&attrstr, "%s %s", "%attr(-,root,root) ",
Igor Gnatenko 082d5d
+			       mainiddir);
Igor Gnatenko 082d5d
+		    parseForAttr(fl->pool, attrstr, 0, &fl->cur);
Igor Gnatenko 082d5d
 		    fl->cur.isDir = 1;
Igor Gnatenko 082d5d
 		    rc = addFile(fl, mainiddir, NULL);
Igor Gnatenko 082d5d
+		    free (attrstr);
Igor Gnatenko 082d5d
 		}
Igor Gnatenko 082d5d
 	    }
Igor Gnatenko 082d5d
 
Igor Gnatenko 082d5d
@@ -1795,8 +1812,12 @@ static int generateBuildIDs(FileList fl)
Igor Gnatenko 082d5d
 		if ((rc = rpmioMkpath(debugiddir, 0755, -1, -1)) != 0) {
Igor Gnatenko 082d5d
 		    rpmlog(RPMLOG_ERR, "%s %s: %m\n", errdir, debugiddir);
Igor Gnatenko 082d5d
 		} else {
Igor Gnatenko 082d5d
+		    rasprintf (&attrstr, "%s %s", "%attr(-,root,root) ",
Igor Gnatenko 082d5d
+			       debugiddir);
Igor Gnatenko 082d5d
+		    parseForAttr(fl->pool, attrstr, 0, &fl->cur);
Igor Gnatenko 082d5d
 		    fl->cur.isDir = 1;
Igor Gnatenko 082d5d
 		    rc = addFile(fl, debugiddir, NULL);
Igor Gnatenko 082d5d
+		    free (attrstr);
Igor Gnatenko 082d5d
 		}
Igor Gnatenko 082d5d
 	    }
Igor Gnatenko 082d5d
 	}
Mark Wielaard 117a78
diff --git a/tests/Makefile.am b/tests/Makefile.am
Igor Gnatenko 082d5d
index 10555ce9a..d9586da1d 100644
Mark Wielaard 117a78
--- a/tests/Makefile.am
Mark Wielaard 117a78
+++ b/tests/Makefile.am
Igor Gnatenko 082d5d
@@ -68,6 +68,8 @@ EXTRA_DIST += data/RPMS/hello-2.0-1.i686.rpm
Mark Wielaard 117a78
 EXTRA_DIST += data/RPMS/hello-2.0-1.x86_64.rpm
Mark Wielaard 117a78
 EXTRA_DIST += data/SRPMS/foo-1.0-1.src.rpm
Mark Wielaard 117a78
 EXTRA_DIST += data/SRPMS/hello-1.0-1.src.rpm
Mark Wielaard 117a78
+EXTRA_DIST += data/SOURCES/hello.c
Mark Wielaard 117a78
+EXTRA_DIST += data/SPECS/hello-attr-buildid.spec
Mark Wielaard 117a78
 
Mark Wielaard 117a78
 # testsuite voodoo
Mark Wielaard 117a78
 AUTOTEST = $(AUTOM4TE) --language=autotest
Mark Wielaard 117a78
diff --git a/tests/data/SOURCES/hello.c b/tests/data/SOURCES/hello.c
Mark Wielaard 117a78
new file mode 100644
Igor Gnatenko 082d5d
index 000000000..020484eed
Mark Wielaard 117a78
--- /dev/null
Mark Wielaard 117a78
+++ b/tests/data/SOURCES/hello.c
Mark Wielaard 117a78
@@ -0,0 +1,8 @@
Mark Wielaard 117a78
+#include <stdio.h>
Mark Wielaard 117a78
+
Mark Wielaard 117a78
+int
Mark Wielaard 117a78
+main (void)
Mark Wielaard 117a78
+{
Mark Wielaard 117a78
+  printf ("Hello, world!\n");
Mark Wielaard 117a78
+  return 0;
Mark Wielaard 117a78
+}
Mark Wielaard 117a78
diff --git a/tests/data/SPECS/hello-attr-buildid.spec b/tests/data/SPECS/hello-attr-buildid.spec
Mark Wielaard 117a78
new file mode 100644
Igor Gnatenko 082d5d
index 000000000..cdab95fff
Mark Wielaard 117a78
--- /dev/null
Mark Wielaard 117a78
+++ b/tests/data/SPECS/hello-attr-buildid.spec
Mark Wielaard 117a78
@@ -0,0 +1,27 @@
Mark Wielaard 117a78
+Name:           test
Mark Wielaard 117a78
+Version:        1.0
Mark Wielaard 117a78
+Release:        1
Mark Wielaard 117a78
+Summary:        Test
Mark Wielaard 117a78
+
Mark Wielaard 117a78
+License:        Public Domain
Mark Wielaard 117a78
+URL:            https://fedoraproject.org
Mark Wielaard 117a78
+Source:         hello.c
Mark Wielaard 117a78
+
Mark Wielaard 117a78
+%description
Mark Wielaard 117a78
+%{summary}.
Mark Wielaard 117a78
+
Mark Wielaard 117a78
+%prep
Mark Wielaard 117a78
+%autosetup -c -D -T
Mark Wielaard 117a78
+cp -a %{S:0} .
Mark Wielaard 117a78
+
Mark Wielaard 117a78
+%build
Mark Wielaard 117a78
+gcc -g hello.c -o hello
Mark Wielaard 117a78
+
Mark Wielaard 117a78
+%install
Mark Wielaard 117a78
+mkdir -p %{buildroot}%{_bindir}
Mark Wielaard 117a78
+install -D -p -m 0755 -t %{buildroot}%{_bindir} hello
Mark Wielaard 117a78
+
Mark Wielaard 117a78
+%files
Mark Wielaard 117a78
+%attr(644,root,root) %{_bindir}/hello
Mark Wielaard 117a78
+
Mark Wielaard 117a78
+%changelog
Mark Wielaard 117a78
diff --git a/tests/rpmbuildid.at b/tests/rpmbuildid.at
Igor Gnatenko 082d5d
index 15c06202f..1cae26dbf 100644
Mark Wielaard 117a78
--- a/tests/rpmbuildid.at
Mark Wielaard 117a78
+++ b/tests/rpmbuildid.at
Mark Wielaard 117a78
@@ -1166,3 +1166,39 @@ if test "$id1" == "$id2"; then echo "equal"; else echo "unequal $id1 $id2"; fi
Mark Wielaard 117a78
 ],
Mark Wielaard 117a78
 [ignore])
Mark Wielaard 117a78
 AT_CLEANUP
Mark Wielaard 117a78
+
Mark Wielaard 117a78
+# ------------------------------
Mark Wielaard 117a78
+# Check that build-id directories are created with the right permissions
Mark Wielaard 117a78
+# even if the spec file sets attrs explicitly.
Mark Wielaard 117a78
+AT_SETUP([rpmbuild buildid attrs])
Mark Wielaard 117a78
+AT_KEYWORDS([build] [debuginfo] [buildid])
Mark Wielaard 117a78
+AT_CHECK([
Mark Wielaard 117a78
+rm -rf ${TOPDIR}
Mark Wielaard 117a78
+AS_MKDIR_P(${TOPDIR}/SOURCES)
Mark Wielaard 117a78
+
Mark Wielaard 117a78
+# Setup sources
Mark Wielaard 117a78
+cp "${abs_srcdir}"/data/SOURCES/hello.c ${TOPDIR}/SOURCES
Mark Wielaard 117a78
+
Mark Wielaard 117a78
+# Build, contains one ELF which should have a buildid.
Mark Wielaard 117a78
+run rpmbuild \
Mark Wielaard 117a78
+  --macros=${abs_top_builddir}/macros:${abs_top_builddir}/tests/testing/usr/local/lib/rpm/platform/%{_target_cpu}-%{_target_os}/macros:${top_srcdir}/macros.debug \
Mark Wielaard 117a78
+  --rcfile=${abs_top_builddir}/rpmrc \
Mark Wielaard 117a78
+  --define="_build_id_links compat" \
Mark Wielaard 117a78
+  --define "_unique_debug_names 1" \
Mark Wielaard 117a78
+  --define "_unique_debug_srcs 1" \
Mark Wielaard 117a78
+  --quiet -ba "${abs_srcdir}"/data/SPECS/hello-attr-buildid.spec
Mark Wielaard 117a78
+
Mark Wielaard 117a78
+run rpm -qp --qf "[[%{filenames} %{filemodes:perms}\n]]" \
Mark Wielaard 117a78
+        ${abs_builddir}/testing/build/RPMS/*/test-1.0-1*rpm \
Mark Wielaard 117a78
+	| grep "build-id d"
Mark Wielaard 117a78
+
Mark Wielaard 117a78
+run rpm -qp --qf "[[%{filenames} %{filemodes:perms}\n]]" \
Mark Wielaard 117a78
+        ${abs_builddir}/testing/build/RPMS/*/test-debuginfo-1.0-1*rpm \
Mark Wielaard 117a78
+	| grep "build-id d"
Mark Wielaard 117a78
+],
Mark Wielaard 117a78
+[0],
Mark Wielaard 117a78
+[/usr/lib/.build-id drwxr-xr-x
Mark Wielaard 117a78
+/usr/lib/debug/.build-id drwxr-xr-x
Mark Wielaard 117a78
+],
Mark Wielaard 117a78
+[ignore])
Mark Wielaard 117a78
+AT_CLEANUP
Igor Gnatenko 082d5d
-- 
Igor Gnatenko 082d5d
2.13.2
Mark Wielaard 117a78