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