summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-10-11 22:30:31 +0200
committerLennart Poettering <lennart@poettering.net>2011-10-11 22:30:31 +0200
commit64685e0cea62b4937f0804e47ce2cb7929f58223 (patch)
treeb33dc0e8922360c9f067591cafa8632f2b26ea58 /src/util.c
parentd2134abdd5a21bb7e4b307f403d890901628fcf9 (diff)
util: properly detect what the last capability is
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index e46606dabb..e93e6f6cf5 100644
--- a/src/util.c
+++ b/src/util.c
@@ -5703,3 +5703,36 @@ int strdup_or_null(const char *a, char **b) {
*b = c;
return 0;
}
+
+unsigned long cap_last_cap(void) {
+ static __thread unsigned long saved;
+ static __thread bool valid = false;
+ unsigned long p;
+
+ if (valid)
+ return saved;
+
+ p = (unsigned long) CAP_LAST_CAP;
+
+ if (prctl(PR_CAPBSET_READ, p) < 0) {
+
+ /* Hmm, look downwards, until we find one that
+ * works */
+ for (p--; p > 0; p --)
+ if (prctl(PR_CAPBSET_READ, p) >= 0)
+ break;
+
+ } else {
+
+ /* Hmm, look upwards, until we find one that doesn't
+ * work */
+ for (;; p++)
+ if (prctl(PR_CAPBSET_READ, p+1) < 0)
+ break;
+ }
+
+ saved = p;
+ valid = true;
+
+ return p;
+}