public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Anthony G. Basile" <blueness@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/elfix:master commit in: misc/install.wrapper.c/
Date: Sat, 18 Jan 2014 20:06:06 +0000 (UTC)	[thread overview]
Message-ID: <1390075588.822fd7c4b762ad375ec8e95480f39306943b9dc6.blueness@gentoo> (raw)

commit:     822fd7c4b762ad375ec8e95480f39306943b9dc6
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Jan 18 20:06:28 2014 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Sat Jan 18 20:06:28 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=822fd7c4

misc/install.wrapper.c: address bug #465000, most of comment #52

---
 misc/install.wrapper.c/.gitignore        | 14 ++++++
 misc/install.wrapper.c/Makefile.am       |  4 +-
 misc/install.wrapper.c/checkcopyattrs.sh |  4 ++
 misc/install.wrapper.c/install.wrapper.c | 81 ++++++++++++++++----------------
 4 files changed, 61 insertions(+), 42 deletions(-)

diff --git a/misc/install.wrapper.c/.gitignore b/misc/install.wrapper.c/.gitignore
new file mode 100644
index 0000000..a0bcfaa
--- /dev/null
+++ b/misc/install.wrapper.c/.gitignore
@@ -0,0 +1,14 @@
+a
+b
+c
+d/a
+d/b
+d/c
+e/a
+e/b
+e/c
+f/a
+install-xattr
+x
+y
+z

diff --git a/misc/install.wrapper.c/Makefile.am b/misc/install.wrapper.c/Makefile.am
index b047805..0792121 100644
--- a/misc/install.wrapper.c/Makefile.am
+++ b/misc/install.wrapper.c/Makefile.am
@@ -10,7 +10,7 @@ checkcopyattrs:
 	$(srcdir)/checkcopyattrs.sh
 
 EXTRA_DIST = checkcopyattrs.sh
-CLEANFILES = a b c x y z d/* e/*
+CLEANFILES = a b c x y z d/* e/* f/*
 
 clean-local:
-	-rm -rf d e
+	-rm -rf d e f

diff --git a/misc/install.wrapper.c/checkcopyattrs.sh b/misc/install.wrapper.c/checkcopyattrs.sh
index 4b3e7f3..584970a 100755
--- a/misc/install.wrapper.c/checkcopyattrs.sh
+++ b/misc/install.wrapper.c/checkcopyattrs.sh
@@ -30,3 +30,7 @@ setfattr -n user.pax.flags -v "r" c
 [ "$(getfattr --only-values -n user.pax.flags e/a)" == "mr" ]
 [ "$(getfattr --only-values -n user.pax.flags e/b)" == "p" ]
 [ "$(getfattr --only-values -n user.pax.flags e/c)" == "r" ]
+
+./install-xattr a -D f/a
+[ "$(getfattr --only-values -n user.foo f/a)" == "bar" ]
+[ "$(getfattr --only-values -n user.pax.flags f/a)" == "mr" ]

diff --git a/misc/install.wrapper.c/install.wrapper.c b/misc/install.wrapper.c/install.wrapper.c
index bcea5cf..de15f8e 100644
--- a/misc/install.wrapper.c/install.wrapper.c
+++ b/misc/install.wrapper.c/install.wrapper.c
@@ -23,8 +23,8 @@
 static void *
 xmalloc(size_t size)
 {
-	char *ret = malloc(size);
-	if (ret < 0)
+	void *ret = malloc(size);
+	if (ret == NULL)
 		err(1, "malloc() failed");
 	return ret;
 }
@@ -63,7 +63,7 @@ xgetxattr(const char *path, char *list, char *value, size_t size)
 }
 
 static ssize_t
-xsetxattr(const char *path, char *list, char *value , size_t size)
+xsetxattr(const char *path, char *list, char *value, size_t size)
 {
 	ssize_t ret = setxattr(path, list, value, size, 0);
 	if (ret < 0)
@@ -71,34 +71,20 @@ xsetxattr(const char *path, char *list, char *value , size_t size)
 	return ret;
 }
 
+char *exclude;      /* strings of excluded xattr names              */
+size_t len_exclude; /* length of the string of excluded xattr names */
+
 static void
 copyxattr(const char *source, const char *target)
 {
-	char *exclude, *portage_xattr_exclude;  /* strings of excluded xattr names              */
-	size_t i, j;                            /* counters to walk through strings             */
-	size_t len;                             /* length of the string of excluded xattr names */
-	ssize_t lsize, xsize;   /* size in bytes of the list of xattrs and the values           */
-	char *lxattr, *value;   /* string of xattr names and the values                         */
+	ssize_t i, j;           /* counters to walk through strings                   */
+	ssize_t lsize, xsize;   /* size in bytes of the list of xattrs and the values */
+	char *lxattr, *value;   /* string of xattr names and the values               */
 
-	lsize = xlistxattr(source, 0, 0);
+	lsize = xlistxattr(source, NULL, 0);
 	lxattr = xmalloc(lsize);
 	xlistxattr(source, lxattr, lsize);
 
-	portage_xattr_exclude = getenv("PORTAGE_XATTR_EXCLUDE");
-	if (portage_xattr_exclude == NULL)
-		exclude = strdup("security.* system.nfs4_acl");
-	else
-		exclude = strdup(portage_xattr_exclude);
-
-	len = strlen(exclude);
-
-	/* We convert exclude[] to an array of concatenated null
-	 * terminated strings.  lxattr[] is already such an array.
-         */
-	for (i = 0; i < len; i++)
-		if (isspace(exclude[i]))
-			exclude[i] = 0;
-
 	i = 0;
 	while (1) {
 		while (lxattr[i++] == 0)
@@ -110,13 +96,13 @@ copyxattr(const char *source, const char *target)
 		while (1) {
 			while (exclude[j++] == 0)
 				continue;
-			if (j >= len)
+			if (j >= len_exclude)
 				break;
-			if (!fnmatch(&exclude[j-1], &lxattr[i-1], 0))
+			if (!fnmatch(&exclude[j - 1], &lxattr[i - 1], 0))
 				goto skip;
 			while (exclude[j++] != 0)
 				continue;
-			if (j >= len)
+			if (j >= len_exclude)
 				break;
 		}
 
@@ -130,13 +116,13 @@ copyxattr(const char *source, const char *target)
 		}
 
  skip:
-		while (lxattr[i++] != 0);
+		while (lxattr[i++] != 0)
+			continue;
 		if (i >= lsize)
 			break;
 	}
 
 	free(lxattr);
-	free(exclude);
 }
 
 
@@ -151,8 +137,7 @@ which(const char *mydir)
 		size_t len = confstr(_CS_PATH, 0, 0);
 		path = xmalloc(len);
 		confstr(_CS_PATH, path, len);
-	}
-	else
+	} else
 		path = strdup(env_path);
 
 	char *dir;       /* one directory in the $PATH string */
@@ -167,14 +152,14 @@ which(const char *mydir)
 	while (dir) {
 		candir = realpath(dir, NULL);
 
-		/* ignore invalid paths that cannot be cannoicalized */
+		/* ignore invalid paths that cannot be canonicalized */
 		if (!candir)
 			goto skip;
 
 		/* If argv[0]'s canonical dirname == the path's canonical dirname, then we
 		 * skip this path otheriwise we get into an infinite self-invocation.
-                 */
-		if (!fnmatch(mycandir, candir, 0))
+		 */
+		if (!strcmp(mycandir, candir))
 			goto skip;
 
 		file = path_join(candir, "install");
@@ -183,11 +168,11 @@ which(const char *mydir)
 		 * assume we found the system's install.
                  */
 		if (stat(file, &s) == 0)
-			if (S_ISREG(s.st_mode) || S_ISLNK(s.st_mode)) {
+			if (S_ISREG(s.st_mode)) {
 				free(candir);
 				free(mycandir);
 				free(path);
-				return strdup(file);
+				return file;
 			}
 
 		free(file);
@@ -203,7 +188,7 @@ which(const char *mydir)
 
 
 int
-main(int argc, char* argv[], char* envp[])
+main(int argc, char* argv[])
 {
 	int i;
 	int status;                    /* exit status of child "install" process                       */
@@ -219,6 +204,22 @@ main(int argc, char* argv[], char* envp[])
 
 	struct stat s;                 /* test if a file is a regular file or a directory              */
 
+	char *portage_xattr_exclude;  /* strings of excluded xattr names from $PORTAGE_XATTR_EXCLUDE   */
+
+	portage_xattr_exclude = getenv("PORTAGE_XATTR_EXCLUDE");
+	if (portage_xattr_exclude == NULL)
+		exclude = strdup("security.* system.nfs4_acl");
+	else
+		exclude = strdup(portage_xattr_exclude);
+
+	len_exclude = strlen(exclude);
+
+	/* We convert exclude[] to an array of concatenated NUL terminated
+	 * strings.  Also, no need to free(exclude) before we exit().
+	 */
+	char *p = exclude;
+	while ((p = strchr(p, ' ')))
+		*p++ = '\0';
 
 	opterr = 0; /* we skip many legitimate flags, so silence any warning */
 
@@ -265,9 +266,9 @@ main(int argc, char* argv[], char* envp[])
 
 		case 0:
 			install = which(dirname(argv[0]));
-			argv[0] = "install";         /* so coreutils' lib/program.c behaves */
-			execve(install, argv, envp); /* The kernel will free(install).      */
-			err(1, "execve() failed");
+			argv[0] = install;    /* so coreutils' lib/program.c behaves */
+			execv(install, argv); /* The kernel will free(install).      */
+			err(1, "execv() failed");
 
 		default:
 			wait(&status);


             reply	other threads:[~2014-01-18 20:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-18 20:06 Anthony G. Basile [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-02-07 18:10 [gentoo-commits] proj/elfix:master commit in: misc/install.wrapper.c/ Anthony G. Basile
2014-02-07 18:10 Anthony G. Basile
2014-01-20 19:02 Anthony G. Basile
2014-01-18 23:39 Anthony G. Basile
2014-01-18 23:25 Anthony G. Basile
2014-01-18 20:57 Anthony G. Basile
2014-01-18 20:30 Anthony G. Basile
2014-01-18 20:23 Anthony G. Basile
2014-01-18 13:18 Anthony G. Basile
2014-01-18 13:18 Anthony G. Basile

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1390075588.822fd7c4b762ad375ec8e95480f39306943b9dc6.blueness@gentoo \
    --to=blueness@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox