From: Lennart Poettering Date: Wed, 12 Oct 2011 02:29:11 +0000 (+0200) Subject: Merge branch 'master' into journal X-Git-Tag: v38~144^2~61 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=689b9a22f7fa89686b2b5240b7ee9f449dea5630;p=systemd Merge branch 'master' into journal --- 689b9a22f7fa89686b2b5240b7ee9f449dea5630 diff --cc src/util.c index a3cfe864,e93e6f6c..26c2f22f --- a/src/util.c +++ b/src/util.c @@@ -5883,20 -5704,35 +5886,52 @@@ int strdup_or_null(const char *a, char return 0; } +int prot_from_flags(int flags) { + + switch (flags & O_ACCMODE) { + + case O_RDONLY: + return PROT_READ; + + case O_WRONLY: + return PROT_WRITE; + + case O_RDWR: + return PROT_READ|PROT_WRITE; + + default: + return -EINVAL; + } ++ + 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; } diff --cc src/util.h index 89a7bec6,a71a297e..1db82f83 --- a/src/util.h +++ b/src/util.h @@@ -513,6 -506,6 +513,8 @@@ extern char **saved_argv bool kexec_loaded(void); +int prot_from_flags(int flags); + + unsigned long cap_last_cap(void); + #endif