From 1d41f696ccef3950eedd60f894b1da258a8756ef Mon Sep 17 00:00:00 2001 From: Ole Tange Date: Sun, 29 Dec 2024 20:14:55 +0100 Subject: [PATCH] iothrottle: Clean up /tmp if iothrottle is killed. --- iothrottle/Makefile | 25 +++++++++++++ iothrottle/iothrottle.in | 36 +++++++++++++++---- .../share/vlc/lua/extensions/splitvideo.lua | 4 +-- splitvideo/splitvideo | 2 +- vid/vid | 3 +- 5 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 iothrottle/Makefile diff --git a/iothrottle/Makefile b/iothrottle/Makefile new file mode 100644 index 0000000..1404437 --- /dev/null +++ b/iothrottle/Makefile @@ -0,0 +1,25 @@ +all: iothrottle + true + +iothrottle: iothrottle.hex iothrottle.in + perl -pe 's/hex=.*/"hex=".`cat iothrottle.hex`/e' iothrottle.in > iothrottle + chmod +x iothrottle + +iothrottle.so: iothrottle.c + gcc -O2 -shared -fPIC -o iothrottle.so iothrottle.c -ldl + strip iothrottle.so + +iothrottle.hex: iothrottle.so + hexdump -ve '1/1 "%.2x"' iothrottle.so > iothrottle.hex + LC_ALL=C awk '{for (i=1; i<=length($$0); i+=2) printf "%c", strtonum("0x" substr($$0, i, 2))}' iothrottle.hex > iothrottle.bin + md5sum iothrottle.so iothrottle.bin + +test: iothrottle + seq 10000000 | cat | pv > big + ./iothrottle cat big | pv > /dev/null + ./iothrottle -i 20M cat big | pv > /dev/null + ./iothrottle -o 20000K cat big | pv > /dev/null + rm big + +clean: + rm -f iothrottle.so iothrottle.hex iothrottle.bin iothrottle iothrottle.1 iothrottle~ diff --git a/iothrottle/iothrottle.in b/iothrottle/iothrottle.in index f2e969d..6ad58d0 100755 --- a/iothrottle/iothrottle.in +++ b/iothrottle/iothrottle.in @@ -47,14 +47,26 @@ Copy mydir at 1MB/s: iothrottle -i 1M cp -a mydir/ /other/filesystem/ -=head1 BUGS +=head1 LIMITATIONS + +B intercepts calls to B(2) and B(2). If too +much is read/written it inserts a pause for each call. This means the +speed can go over the limit for a single call. Thus if the limit is +400 bytes/sec, but the call moves 4096 bytes, there will be a pause of +10 secs. Not all program use B(2) and B(2) for I/O. These all use other methods: cp (to same filesystem), seq -File a bug report when you find other programs: -https://git.data.coop/tange/tangetools/issues +Statically linked programs will also not work. + +File a bug report when you find other programs. + + +=head1 BUGS + +File bugs at: https://git.data.coop/tange/tangetools/issues =head1 ENVIRONMENT VARIABLES @@ -106,14 +118,18 @@ B, B _hex() { + # hex encoded iothrottle.so local hex=dummy echo $hex } +_hex_to_bin() { + LC_ALL=C awk '{for (i=1; i<=length($0); i+=2) printf "%c", strtonum("0x" substr($0, i, 2))}' +} + _iothrottle.so() { - local iothrottleso=$(mktemp) - _hex | - LC_ALL=C awk '{for (i=1; i<=length($0); i+=2) printf "%c", strtonum("0x" substr($0, i, 2))}' > "$iothrottleso" + local iothrottleso=$(mktemp -t iotrottle.XXXXX) + _hex | _hex_to_bin > "$iothrottleso" echo "$iothrottleso" } @@ -169,6 +185,12 @@ if [ IOTHROTTLE_DEBUG = 1 ] ; then echo LD_PRELOAD=$_so LD_PRELOAD=$_so "$@" else + cleanup() { + # if parent is dead: remove tmpfile + ppid=$1 + while kill -0 $ppid 2>/dev/null; do sleep 1; done + rm $_so + } + cleanup $$ & LD_PRELOAD=$_so "$@" - rm $_so fi diff --git a/splitvideo/dotlocal/share/vlc/lua/extensions/splitvideo.lua b/splitvideo/dotlocal/share/vlc/lua/extensions/splitvideo.lua index 3833a52..233c30a 100644 --- a/splitvideo/dotlocal/share/vlc/lua/extensions/splitvideo.lua +++ b/splitvideo/dotlocal/share/vlc/lua/extensions/splitvideo.lua @@ -10,7 +10,7 @@ INSTALLATION (create directories if they donot exist): - The extension can then be found in the menu: View > Split video in two - It requires 'splitvideo' from - https://gitlab.com/ole.tange/tangetools/tree/master/splitvideo + https://git.data.coop/tange/tangetools/src/branch/master/splitvideo/splitvideo to be in $PATH ]]-- @@ -24,7 +24,7 @@ function descriptor() description = "

Split Video

" .. "When you're playing a file, use Split Video to " .. "split the file into two files at the current time stamp. " ; - url = "https://gitlab.com/ole.tange/tangetools/tree/master/splitvideo" + url = "https://git.data.coop/tange/tangetools/src/branch/master/splitvideo" } end diff --git a/splitvideo/splitvideo b/splitvideo/splitvideo index e4a4503..0ad454a 100755 --- a/splitvideo/splitvideo +++ b/splitvideo/splitvideo @@ -36,7 +36,7 @@ B can be used on the commandline: splitvideo 3600 myvideo.mp4 It can also be called from VLC by installing B from -https://gitlab.com/ole.tange/tangetools/tree/master/splitvideo in +https://git.data.coop/tange/tangetools/src/branch/master/splitvideo in B<~/.local/share/vlc/lua/extensions/> diff --git a/vid/vid b/vid/vid index 0064450..d4cc708 100755 --- a/vid/vid +++ b/vid/vid @@ -162,7 +162,8 @@ cat_list() { # cat "$vidlist" | grep matching this dir + remove dirs # echo "$vidlist" "$full_path_thisdir" "$full_path_vidlist_dir" = "$subdir" >&2 grep -v '/.waste/' "$vidlist" | - perl -ne 's|^(\./)?\Q'"$subdir"'\E|| and print' + perl -ne 's|^(\./)?\Q'"$subdir"'\E|| and print' | + sort -u } stdin() {