From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id B0AB8138247 for ; Sat, 18 Jan 2014 23:25:49 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 47662E0B6A; Sat, 18 Jan 2014 23:25:49 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id C6D56E0B6A for ; Sat, 18 Jan 2014 23:25:48 +0000 (UTC) Received: from spoonbill.gentoo.org (spoonbill.gentoo.org [81.93.255.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 8A15433F8C6 for ; Sat, 18 Jan 2014 23:25:47 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by spoonbill.gentoo.org (Postfix) with ESMTP id 4DD4618096 for ; Sat, 18 Jan 2014 23:25:46 +0000 (UTC) From: "Anthony G. Basile" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Anthony G. Basile" Message-ID: <1390087568.30fe7e70b82961b660892c4f33812303a3d4583a.blueness@gentoo> Subject: [gentoo-commits] proj/elfix:master commit in: misc/install.wrapper.c/ X-VCS-Repository: proj/elfix X-VCS-Files: misc/install.wrapper.c/checkcopyattrs.sh misc/install.wrapper.c/install.wrapper.c X-VCS-Directories: misc/install.wrapper.c/ X-VCS-Committer: blueness X-VCS-Committer-Name: Anthony G. Basile X-VCS-Revision: 30fe7e70b82961b660892c4f33812303a3d4583a X-VCS-Branch: master Date: Sat, 18 Jan 2014 23:25:46 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: f511f024-2fca-419f-85f5-557066c8d1be X-Archives-Hash: 82ba417e315f03668683d404f895419c commit: 30fe7e70b82961b660892c4f33812303a3d4583a Author: Anthony G. Basile gentoo org> AuthorDate: Sat Jan 18 23:26:08 2014 +0000 Commit: Anthony G. Basile gentoo org> CommitDate: Sat Jan 18 23:26:08 2014 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=30fe7e70 misc/install.wrapper.c: speed up memory allocation with realloc --- misc/install.wrapper.c/checkcopyattrs.sh | 5 +++++ misc/install.wrapper.c/install.wrapper.c | 25 +++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/misc/install.wrapper.c/checkcopyattrs.sh b/misc/install.wrapper.c/checkcopyattrs.sh index 584970a..86a6a33 100755 --- a/misc/install.wrapper.c/checkcopyattrs.sh +++ b/misc/install.wrapper.c/checkcopyattrs.sh @@ -4,6 +4,7 @@ set -e touch a b c mkdir -p d e setfattr -n user.foo -v "bar" a +setfattr -n user.bas -v "x" a setfattr -n user.pax.flags -v "mr" a setfattr -n user.pax.flags -v "p" b setfattr -n user.pax.flags -v "r" c @@ -13,6 +14,7 @@ setfattr -n user.pax.flags -v "r" c ./install-xattr c z [ "$(getfattr --only-values -n user.foo x)" == "bar" ] +[ "$(getfattr --only-values -n user.bas x)" == "x" ] [ "$(getfattr --only-values -n user.pax.flags x)" == "mr" ] [ "$(getfattr --only-values -n user.pax.flags y)" == "p" ] [ "$(getfattr --only-values -n user.pax.flags z)" == "r" ] @@ -20,6 +22,7 @@ setfattr -n user.pax.flags -v "r" c ./install-xattr a b c d [ "$(getfattr --only-values -n user.foo d/a)" == "bar" ] +[ "$(getfattr --only-values -n user.bas d/a)" == "x" ] [ "$(getfattr --only-values -n user.pax.flags d/a)" == "mr" ] [ "$(getfattr --only-values -n user.pax.flags d/b)" == "p" ] [ "$(getfattr --only-values -n user.pax.flags d/c)" == "r" ] @@ -27,10 +30,12 @@ setfattr -n user.pax.flags -v "r" c ./install-xattr -t e a b c [ "$(getfattr --only-values -n user.foo e/a)" == "bar" ] +[ "$(getfattr --only-values -n user.bas e/a)" == "x" ] [ "$(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.bas f/a)" == "x" ] [ "$(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 2d588ac..b79d90c 100644 --- a/misc/install.wrapper.c/install.wrapper.c +++ b/misc/install.wrapper.c/install.wrapper.c @@ -38,6 +38,15 @@ xmalloc(size_t size) return ret; } +static void * +xrealloc(void *p, size_t size) +{ + void *ret = realloc(p, size); + if (ret == NULL) + err(1, "realloc() failed"); + return ret; +} + static char * path_join(const char *path, const char *file) { @@ -88,7 +97,9 @@ copyxattr(const char *source, const char *target) { 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 */ + char *lxattr; /* string of xattr names */ + static char *value = NULL ; /* string of an xattr name's value */ + static size_t value_size = 0; /* size of the value string */ lsize = xlistxattr(source, NULL, 0); lxattr = xmalloc(lsize); @@ -116,12 +127,12 @@ copyxattr(const char *source, const char *target) } xsize = xgetxattr(source, &lxattr[i-1], 0, 0); - if (xsize > 0) { - value = xmalloc(xsize); - xgetxattr(source, &lxattr[i-1], value, xsize); - xsetxattr(target, &lxattr[i-1], value, xsize); - free(value); + if (xsize > value_size) { + value_size = xsize; + value = xrealloc(value, value_size); } + xgetxattr(source, &lxattr[i-1], value, xsize); + xsetxattr(target, &lxattr[i-1], value, xsize); skip: while (lxattr[i++] != 0) @@ -130,6 +141,8 @@ copyxattr(const char *source, const char *target) break; } + /* No need to free(value) on return because its static and we */ + /* just keep reusing the same allocated memory on each call. */ free(lxattr); }