[Reproducible-commits] [dpkg] 52/61: Ensure deterministic file order in data.tar.* files

Jérémy Bobbio lunar at moszumanska.debian.org
Mon Sep 21 09:57:43 UTC 2015


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch pu/reproducible_builds
in repository dpkg.

commit 9ce88fdc74830496e5f98058ba6aeee67a4810dd
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Tue Aug 27 18:10:15 2013 +0200

    Ensure deterministic file order in data.tar.* files
    
    Address: #719845
---
 dpkg-deb/build.c | 42 ++++++++++++++++++++++++++++++------------
 lib/dpkg/dpkg.h  |  1 +
 2 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/dpkg-deb/build.c b/dpkg-deb/build.c
index ea3d861..3e028fd 100644
--- a/dpkg-deb/build.c
+++ b/dpkg-deb/build.c
@@ -168,19 +168,36 @@ file_info_list_free(struct file_info *fi)
 static void
 file_treewalk_feed(const char *dir, int fd_out)
 {
-  int pipefd[2];
-  pid_t pid;
+  int sort_pipefd[2], find_pipefd[2];
+  pid_t sort_pid, find_pid;
   struct file_info *fi;
   struct file_info *symlist = NULL;
   struct file_info *symlist_end = NULL;
 
-  m_pipe(pipefd);
+  m_pipe(find_pipefd);
+  m_pipe(sort_pipefd);
+
+  sort_pid = subproc_fork();
+  if (sort_pid == 0) {
+    m_dup2(find_pipefd[0], 0);
+    close(find_pipefd[0]);
+    close(find_pipefd[1]);
+    m_dup2(sort_pipefd[1], 1);
+    close(sort_pipefd[0]);
+    close(sort_pipefd[1]);
+    if (setenv("LC_ALL", "C", 1 /* overwrite */))
+        ohshite(_("unable to setenv"));
+    execlp(SORT, "sort", "--zero-terminated", NULL);
+    ohshite(_("unable to execute %s (%s)"), "sort", SORT);
+  }
+  close(find_pipefd[0]);
+  close(sort_pipefd[1]);
 
-  pid = subproc_fork();
-  if (pid == 0) {
-    m_dup2(pipefd[1], 1);
-    close(pipefd[0]);
-    close(pipefd[1]);
+  find_pid = subproc_fork();
+  if (find_pid == 0) {
+    m_dup2(find_pipefd[1], 1);
+    close(find_pipefd[0]);
+    close(find_pipefd[1]);
 
     if (chdir(dir))
       ohshite(_("failed to chdir to '%.255s'"), dir);
@@ -189,11 +206,11 @@ file_treewalk_feed(const char *dir, int fd_out)
            "-print0", NULL);
     ohshite(_("unable to execute %s (%s)"), "find", FIND);
   }
-  close(pipefd[1]);
+  close(find_pipefd[1]);
 
   /* We need to reorder the files so we can make sure that symlinks
    * will not appear before their target. */
-  while ((fi = file_info_get(dir, pipefd[0])) != NULL) {
+  while ((fi = file_info_get(dir, sort_pipefd[0])) != NULL) {
     if (strchr(fi->fn, '\n'))
       ohshit(_("newline not allowed in pathname '%s'"), fi->fn);
     if (S_ISLNK(fi->st.st_mode)) {
@@ -206,8 +223,9 @@ file_treewalk_feed(const char *dir, int fd_out)
     }
   }
 
-  close(pipefd[0]);
-  subproc_reap(pid, "find", 0);
+  close(sort_pipefd[0]);
+  subproc_reap(find_pid, "find", 0);
+  subproc_reap(sort_pid, "sort", 0);
 
   for (fi = symlist; fi; fi = fi->next)
     if (fd_write(fd_out, fi->fn, strlen(fi->fn) + 1) < 0)
diff --git a/lib/dpkg/dpkg.h b/lib/dpkg/dpkg.h
index 23b3dd3..0cfa340 100644
--- a/lib/dpkg/dpkg.h
+++ b/lib/dpkg/dpkg.h
@@ -110,6 +110,7 @@ DPKG_BEGIN_DECLS
 #define CAT		"cat"
 #define FIND		"find"
 #define DIFF		"diff"
+#define SORT		"sort"
 
 #define FIND_EXPRSTARTCHARS "-(),!"
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list