Skip to content

Instantly share code, notes, and snippets.

@leoh0
Last active July 4, 2019 13:07
Show Gist options
  • Save leoh0/8711d3ee486220137a3cb0a8aedc80bf to your computer and use it in GitHub Desktop.
Save leoh0/8711d3ee486220137a3cb0a8aedc80bf to your computer and use it in GitHub Desktop.
sample
#!/bin/bash
function ensure_privileged_or_exit() {
grep -xq $'CapBnd:\t0000003fffffffff' /proc/self/status || \
(echo -e "[ERROR] Run with --privileged option." ; exit 1)
}
### Main
ensure_privileged_or_exit
#!/bin/bash
set -e
set -o pipefail
function ensure_privileged_or_exit() {
local i=0
local n=0
# make bitmask (1111...111)
s=$(printf "%-$(($(cat /proc/sys/kernel/cap_last_cap) + 1))s" "1")
str="${s// /1}"
# translate to decimal number (n)
while [ $i -lt ${#str} ]; do
n=$(( 2*n + ${str:$i:1} ))
i=$((i+1))
done
# check process status
grep -xq "$(printf 'CapBnd:\t%.16x' $n)" /proc/self/status || \
(echo -e "[ERROR] Run with --privileged option." ; exit 1)
}
### Main
ensure_privileged_or_exit
@kujyp
Copy link

kujyp commented Jul 4, 2019

감사합니다. 덕분에 유용하게 쓰고있습니다

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment