-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect whether we are running in containers and act responsively. #2063
base: master
Are you sure you want to change the base?
Changes from 7 commits
d41f484
1ca79e8
520c7f7
5810a19
f9cc651
08a766d
06ebe2f
6328778
dd26bd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -238,10 +238,11 @@ unmount() { | |
# point actually ends with ' (deleted)') | ||
# umount has a bug and may return 0 when many mount points cannot be | ||
# unmounted, so we call it once per mount point ('-n 1') | ||
arg='' | ||
while ! sed "s=\\\\040=//=g" /proc/mounts | cut -d' ' -f2 | filter \ | ||
| sed -e 's=//= =g;s/^\(\(.*\) (deleted)\)$/\1\n\2/' \ | ||
| sort -r | xargs --no-run-if-empty -d ' | ||
' -n 1 umount 2>/dev/null; do | ||
' -n 1 umount "$arg" 2>/dev/null; do | ||
if [ "$ntries" -eq "$TRIES" ]; then | ||
# Send signal to all processes running under the chroot | ||
# ...but confirm first. | ||
|
@@ -267,6 +268,11 @@ unmount() { | |
if [ -z "$printonly" ]; then | ||
echo "Sending SIG$SIGNAL to processes under $CHROOTSRC..." 1>&2 | ||
fi | ||
# If there is no process running under $CHROOTSRC and we cannot | ||
# unmount, then use lazy unmount. | ||
# FIXME: This is a hack for running in containers, since we cannot | ||
# unmount recursive bindmount in it. | ||
arg='-l' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this is a kernel bug. I'll try to reproduce on recent kernels and ask on LKML... |
||
for root in /proc/*/root; do | ||
if [ ! -r "$root" ] \ | ||
|| [ ! "`readlink -f "$root"`" = "$base" ]; then | ||
|
@@ -280,6 +286,7 @@ unmount() { | |
if [ -z "$printonly" ]; then | ||
kill "-$SIGNAL" "$pid" 2>/dev/null || true | ||
fi | ||
arg='' | ||
done | ||
|
||
# Escalate | ||
|
@@ -324,7 +331,9 @@ done | |
if checkusage "$ROOT/media"; then | ||
for usbp in /sys/bus/usb/devices/*/power/persist; do | ||
if [ -e "$usbp" ]; then | ||
echo 0 > "$usbp" | ||
# Don't fail since we don't have permission to write /sys/* if we are in | ||
# container. | ||
echo 0 > "$usbp" || true | ||
fi | ||
done | ||
fi | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,43 @@ undotrap() { | |
settrap "$TRAP" | ||
} | ||
|
||
# Check if we are able to mknod. | ||
capmknod() { | ||
local tmp=`mktemp -d --tmpdir=/tmp 'crouton-mknod.XXX'` | ||
local ret=0 | ||
if ! mknod "$tmp/test-mknod" c 0 0; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2>/dev/null |
||
ret=1 | ||
fi | ||
rm -rf "$tmp" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You leave the directory |
||
return $ret | ||
} | ||
|
||
# Check whether $1 is mounted with options $2. | ||
# We check the options of a mount point by inspecting /proc/mounts. | ||
# For options dev, suid and exec, since they will not show up in /proc/mounts, | ||
# we check whether their opposite options (nodev, nosuid, noexec) exists. | ||
checkmountopt() { | ||
local opt | ||
local opts="$2," | ||
while [ -n "$opts" ]; do | ||
opt=${opts%%,*} | ||
opts=${opts#*,} | ||
case $opt in | ||
dev|suid|exec) | ||
if ! awk -v dir="$1" -v opt="no$opt(,|$)" \ | ||
'$2 == dir && $4 ~ opt { exit 1 }' "/proc/mounts"; then | ||
return 1 | ||
fi;; | ||
*) | ||
if ! awk -v dir="$1" -v opt="$opt(,|$)" \ | ||
'$2 == dir && $4 !~ opt { exit 1 }' "/proc/mounts"; then | ||
return 1 | ||
fi;; | ||
esac | ||
done | ||
return 0 | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
# Works mostly like built-in getopts but silently coalesces positional arguments. | ||
# Does not take parameters. Set getopts_string prior to calling. | ||
# Sets getopts_var and getopts_arg. | ||
|
@@ -156,7 +193,9 @@ release() { | |
# sure the kernel does not panic (this is the default configuration of a vanilla | ||
# kernel). See crbug.com/260955 for details. | ||
disablehungtask() { | ||
echo 0 > /proc/sys/kernel/hung_task_panic | ||
# Don't fail since we do not have permission to write /proc/sys/* if we are | ||
# in container. | ||
echo 0 > /proc/sys/kernel/hung_task_panic || true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2>/dev/null |
||
} | ||
|
||
# Run an awk program, without buffering its output. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2>/dev/null || true
. We probably won't bind mount /var/run/dbus in verified mode.