diff options
author | Lennart Poettering <lennart@poettering.net> | 2011-10-12 04:29:11 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2011-10-12 04:29:11 +0200 |
commit | 689b9a22f7fa89686b2b5240b7ee9f449dea5630 (patch) | |
tree | 47d44e0bdb73c40808a5150e081a286df38a055e /src/util.c | |
parent | cec736d21ff86c4ac81b4d306ddba2120333818c (diff) | |
parent | 64685e0cea62b4937f0804e47ce2cb7929f58223 (diff) |
Merge branch 'master' into journal
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/src/util.c b/src/util.c index a3cfe864b6..26c2f22ff0 100644 --- a/src/util.c +++ b/src/util.c @@ -2336,8 +2336,10 @@ int chvt(int vt) { 0 }; - if (ioctl(fd, TIOCLINUX, tiocl) < 0) - return -errno; + if (ioctl(fd, TIOCLINUX, tiocl) < 0) { + r = -errno; + goto fail; + } vt = tiocl[0] <= 0 ? 1 : tiocl[0]; } @@ -2345,7 +2347,8 @@ int chvt(int vt) { if (ioctl(fd, VT_ACTIVATE, vt) < 0) r = -errno; - close_nointr_nofail(r); +fail: + close_nointr_nofail(fd); return r; } @@ -5899,4 +5902,36 @@ int prot_from_flags(int flags) { 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; } |