forked from mirrored-repos/manjaro-tools
lib: nove lock functions to util-msg
This commit is contained in:
parent
c6bd1d3a5e
commit
f3bbc3b96f
2 changed files with 61 additions and 71 deletions
|
@ -72,6 +72,35 @@ stat_done() {
|
|||
printf "${BOLD}done${ALL_OFF}\n" >&2
|
||||
}
|
||||
|
||||
lock_close() {
|
||||
local fd=$1
|
||||
exec {fd}>&-
|
||||
}
|
||||
|
||||
lock() {
|
||||
if ! [[ "/dev/fd/$1" -ef "$2" ]]; then
|
||||
mkdir -p -- "$(dirname -- "$2")"
|
||||
eval "exec $1>"'"$2"'
|
||||
fi
|
||||
if ! flock -n $1; then
|
||||
stat_busy "$3"
|
||||
flock $1
|
||||
stat_done
|
||||
fi
|
||||
}
|
||||
|
||||
slock() {
|
||||
if ! [[ "/dev/fd/$1" -ef "$2" ]]; then
|
||||
mkdir -p -- "$(dirname -- "$2")"
|
||||
eval "exec $1>"'"$2"'
|
||||
fi
|
||||
if ! flock -sn $1; then
|
||||
stat_busy "$3"
|
||||
flock -s $1
|
||||
stat_done
|
||||
fi
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
exit ${1:-0}
|
||||
}
|
||||
|
|
85
lib/util.sh
85
lib/util.sh
|
@ -123,7 +123,6 @@ get_timer(){
|
|||
echo $(date +%s)
|
||||
}
|
||||
|
||||
|
||||
# $1: start timer
|
||||
elapsed_time(){
|
||||
echo $(echo $1 $(get_timer) | awk '{ printf "%0.2f",($2-$1)/60 }')
|
||||
|
@ -133,35 +132,6 @@ show_elapsed_time(){
|
|||
info "Time %s: %s minutes" "$1" "$(elapsed_time $2)"
|
||||
}
|
||||
|
||||
lock_close() {
|
||||
local fd=$1
|
||||
exec {fd}>&-
|
||||
}
|
||||
|
||||
lock() {
|
||||
if ! [[ "/dev/fd/$1" -ef "$2" ]]; then
|
||||
mkdir -p -- "$(dirname -- "$2")"
|
||||
eval "exec $1>"'"$2"'
|
||||
fi
|
||||
if ! flock -n $1; then
|
||||
stat_busy "$3"
|
||||
flock $1
|
||||
stat_done
|
||||
fi
|
||||
}
|
||||
|
||||
slock() {
|
||||
if ! [[ "/dev/fd/$1" -ef "$2" ]]; then
|
||||
mkdir -p -- "$(dirname -- "$2")"
|
||||
eval "exec $1>"'"$2"'
|
||||
fi
|
||||
if ! flock -sn $1; then
|
||||
stat_busy "$3"
|
||||
flock -s $1
|
||||
stat_done
|
||||
fi
|
||||
}
|
||||
|
||||
copy_mirrorlist(){
|
||||
cp -a /etc/pacman.d/mirrorlist "$1/etc/pacman.d/"
|
||||
}
|
||||
|
@ -692,29 +662,6 @@ show_config(){
|
|||
fi
|
||||
}
|
||||
|
||||
# $1: chroot
|
||||
# kill_chroot_process(){
|
||||
# # enable to have more debug info
|
||||
# #msg "machine-id (etc): $(cat $1/etc/machine-id)"
|
||||
# #[[ -e $1/var/lib/dbus/machine-id ]] && msg "machine-id (lib): $(cat $1/var/lib/dbus/machine-id)"
|
||||
# #msg "running processes: "
|
||||
# #lsof | grep $1
|
||||
#
|
||||
# local prefix="$1" flink pid name
|
||||
# for root_dir in /proc/*/root; do
|
||||
# flink=$(readlink $root_dir)
|
||||
# if [ "x$flink" != "x" ]; then
|
||||
# if [ "x${flink:0:${#prefix}}" = "x$prefix" ]; then
|
||||
# # this process is in the chroot...
|
||||
# pid=$(basename $(dirname "$root_dir"))
|
||||
# name=$(ps -p $pid -o comm=)
|
||||
# info "Killing chroot process: %s (%s)" "$name" "$pid"
|
||||
# kill -9 "$pid"
|
||||
# fi
|
||||
# fi
|
||||
# done
|
||||
# }
|
||||
|
||||
create_min_fs(){
|
||||
msg "Creating install root at %s" "$1"
|
||||
mkdir -m 0755 -p $1/var/{cache/pacman/pkg,lib/pacman,log} $1/{dev,run,etc}
|
||||
|
@ -769,19 +716,10 @@ check_root() {
|
|||
fi
|
||||
}
|
||||
|
||||
##
|
||||
# usage : is_btrfs( $path )
|
||||
# return : whether $path is on a btrfs
|
||||
##
|
||||
is_btrfs() {
|
||||
[[ -e "$1" && "$(stat -f -c %T "$1")" == btrfs ]]
|
||||
}
|
||||
|
||||
##
|
||||
# usage : subvolume_delete_recursive( $path )
|
||||
#
|
||||
# Find all btrfs subvolumes under and including $path and delete them.
|
||||
##
|
||||
subvolume_delete_recursive() {
|
||||
local subvol
|
||||
|
||||
|
@ -796,3 +734,26 @@ subvolume_delete_recursive() {
|
|||
|
||||
return 0
|
||||
}
|
||||
|
||||
# $1: chroot
|
||||
# kill_chroot_process(){
|
||||
# # enable to have more debug info
|
||||
# #msg "machine-id (etc): $(cat $1/etc/machine-id)"
|
||||
# #[[ -e $1/var/lib/dbus/machine-id ]] && msg "machine-id (lib): $(cat $1/var/lib/dbus/machine-id)"
|
||||
# #msg "running processes: "
|
||||
# #lsof | grep $1
|
||||
#
|
||||
# local prefix="$1" flink pid name
|
||||
# for root_dir in /proc/*/root; do
|
||||
# flink=$(readlink $root_dir)
|
||||
# if [ "x$flink" != "x" ]; then
|
||||
# if [ "x${flink:0:${#prefix}}" = "x$prefix" ]; then
|
||||
# # this process is in the chroot...
|
||||
# pid=$(basename $(dirname "$root_dir"))
|
||||
# name=$(ps -p $pid -o comm=)
|
||||
# info "Killing chroot process: %s (%s)" "$name" "$pid"
|
||||
# kill -9 "$pid"
|
||||
# fi
|
||||
# fi
|
||||
# done
|
||||
# }
|
||||
|
|
Loading…
Reference in a new issue