chiark / gitweb /
Merge branch 'master' into journal
authorLennart Poettering <lennart@poettering.net>
Wed, 12 Oct 2011 02:29:11 +0000 (04:29 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 12 Oct 2011 02:29:11 +0000 (04:29 +0200)
1  2 
Makefile.am
src/util.c
src/util.h

diff --cc Makefile.am
Simple merge
diff --cc 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
@@@ -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