[systemd-devel] [PATCH] util, fileio: do not use get_status_field() for get_process_capeff()

2013-09-19 Thread Shawn Landden
Tt is in the logging hot path and has too many special needs, like
skipping extra '0's.
---
 src/shared/fileio.c | 16 +++-
 src/shared/util.c   | 24 +++-
 2 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/src/shared/fileio.c b/src/shared/fileio.c
index 01b803c..0df5d3f 100644
--- a/src/shared/fileio.c
+++ b/src/shared/fileio.c
@@ -662,6 +662,7 @@ int get_status_field(const char *filename, const char 
*pattern, char **field) {
 
 assert(filename);
 assert(field);
+assert(pattern);
 
 r = read_full_file(filename, status, NULL);
 if (r  0)
@@ -672,20 +673,9 @@ int get_status_field(const char *filename, const char 
*pattern, char **field) {
 return -ENOENT;
 
 t += strlen(pattern);
-/* Also skip zeros, because when this is used for capabilities,
- * we don't want the zeros. This way the same capability set
- * always maps to the same string, irrespective of the total
- * capability set size. For other numbers it shouldn't matter.
- */
-if (*t) {
-t += strspn(t, WHITESPACE 0);
-/* Back off one char if there's nothing but whitespace
-   and zeros */
-if (!*t)
-t --;
-}
+t += strspn(t,  \t);
 
-len = strcspn(t, WHITESPACE);
+len = strcspn(t,  \n);
 
 *field = strndup(t, len);
 if (!*field)
diff --git a/src/shared/util.c b/src/shared/util.c
index bf31511..a81541e 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -695,6 +695,10 @@ int is_kernel_thread(pid_t pid) {
 
 int get_process_capeff(pid_t pid, char **capeff) {
 const char *p;
+_cleanup_free_ char *status = NULL;
+char *t = NULL;
+int r;
+
 
 assert(capeff);
 assert(pid = 0);
@@ -704,7 +708,25 @@ int get_process_capeff(pid_t pid, char **capeff) {
 else
 p = procfs_file_alloca(pid, status);
 
-return get_status_field(p, \nCapEff:, capeff);
+r = read_full_file(p, status, NULL);
+if (r  0)
+return r;
+
+t = strstr(status, \nCapEff:\t);
+if (!t)
+return -ENOENT;
+
+for (t += strlen(\nCapEff:\t); t[0] == '0'; t++)
+continue;
+
+if (t[0] == '\n')
+t--;
+
+*capeff = strndup(t, (char *)rawmemchr(t, '\n') - t);
+if (!*capeff)
+return -ENOMEM;
+
+return 0;
 }
 
 int get_process_exe(pid_t pid, char **name) {
-- 
1.8.4.rc3

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] util, fileio: do not use get_status_field() for get_process_capeff()

2013-09-19 Thread David Strauss
Does this supersede your earlier patch for get_status_field()?
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] util, fileio: do not use get_status_field() for get_process_capeff()

2013-09-19 Thread Shawn Landden
On Thu, Sep 19, 2013 at 11:58 AM, David Strauss 
da...@davidstrauss.net wrote:

Does this supersede your earlier patch for get_status_field()?

Yes. I tried to optimize the previous patch, and realized it is not 
really possible without splitting back out the capeff handling, which 
is the one where performance matters, because it gets called every time 
we log a message.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel