On 01/03/2013 02:12 PM, Jim Meyering wrote:
bool all_errors = !x->data_copy_required || x->require_preserve_context;
bool some_errors = !all_errors && !x->reduce_diagnostics;
However, both of these declarations belong inside the if {...} body.
What exactly do you mean? Moving the declarations deeper would put
them out of the else {...} body's scope.
Also, please change the name and meaning of s/con_eq/context_change/
Done.
On 01/03/2013 02:15 PM, Pádraig Brady wrote:
This makes sense. It might be worth a news entry,
especially if you quantified the perf benefit.
Done.
The code looks a bit fishy, mixing security_context_t and char*.
Yes, I wasn't very happy about using security_context_t in this way
either, but it seemed like the most straightforward solution.
Thanks,
Ondrej
From b13e7f2fa6a24ae7ad03fc4a6376b2fc2b3c819d Mon Sep 17 00:00:00 2001
From: Ondrej Oprala <[email protected]>
Date: Mon, 17 Dec 2012 16:35:29 +0100
Subject: [PATCH] cp: cache security context
*NEWS: Mention the change.
*src/copy.c (copy_internal): Add a condition to only
call setfscreatecon if the security context has changed.
---
NEWS | 4 ++++
src/copy.c | 10 +++++++++-
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/NEWS b/NEWS
index 5eb8ef3..51e136e 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,10 @@
GNU coreutils NEWS -*- outline -*-
* Noteworthy changes in release ?.? (????-??-??) [?]
+** Improved performance
+
+ cp is now optimized to cache the SELinux context when copying multiple files,
+ resulting in an approximately 27% instruction count decrease.
** New features
diff --git a/src/copy.c b/src/copy.c
index 60322b7..8460076 100644
--- a/src/copy.c
+++ b/src/copy.c
@@ -2201,11 +2201,19 @@ copy_internal (char const *src_name, char const
*dst_name,
{
bool all_errors = !x->data_copy_required || x->require_preserve_context;
bool some_errors = !all_errors && !x->reduce_diagnostics;
+ bool context_change = 0;
security_context_t con;
+ static security_context_t old_con;
if (0 <= lgetfilecon (src_name, &con))
{
- if (setfscreatecon (con) < 0)
+ context_change = !old_con || !STREQ (con, old_con);
+ if (context_change)
+ {
+ free (old_con);
+ old_con = xstrdup (con);
+ }
+ if (context_change && setfscreatecon (con) < 0)
{
if (all_errors || (some_errors && !errno_unsupported (errno)))
error (0, errno,
--
1.7.11.7