aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/unix
diff options
context:
space:
mode:
authorHsieh Chin Fan <typebrook@gmail.com>2022-04-15 12:54:20 +0800
committerHsieh Chin Fan <typebrook@gmail.com>2022-04-15 12:54:20 +0800
commit7bc48f847670293d1acb70c7dcbceaf55fef1e40 (patch)
treedd442139c2e85c8d74faca2cde02a2c359c87082 /tools/unix
parent5f94532c5a7603e8b79d0d755de95220185aed38 (diff)
Update
Diffstat (limited to 'tools/unix')
-rwxr-xr-xtools/unix/fdswap35
1 files changed, 35 insertions, 0 deletions
diff --git a/tools/unix/fdswap b/tools/unix/fdswap
new file mode 100755
index 0000000..8b7d0bd
--- /dev/null
+++ b/tools/unix/fdswap
@@ -0,0 +1,35 @@
1#!/bin/bash
2#
3# fdswap
4#
5if [ "$2" = "" ]; then
6 echo "
7 Usage: $0 /path/to/oldfile /path/to/newfile [pids]
8 Example: $0 /var/log/daemon.log /var/log/newvolume/daemon.log 1234
9 Example: $0 /dev/pts/53 /dev/null 2345"; exit 0
10fi
11
12if gdb --version > /dev/null 2>&1; then true
13else echo "Unable to find gdb."; exit 1
14fi
15
16src="$1"; dst="$2"; shift; shift
17pids=$*
18
19for pid in ${pids:=$( /sbin/fuser $src | cut -d ':' -f 2 )};
20do
21 echo "src=$src, dst=$dst"
22 echo "$src has $pid using it"
23 cmd=$(mktemp)
24 {
25 echo "attach $pid"
26 echo 'call (int)open("'$dst'", 66, 0666)'
27 for ufd in $(LANG=C ls -l /proc/$pid/fd | \
28 grep "$src"\$ | awk ' { print $9; } ');
29 do echo 'call (int)dup2($1,'"$ufd"')'; done
30 echo 'call (int)close($1)'
31 echo 'detach'; echo 'quit'
32 sleep 5
33 } | tee /dev/tty >$cmd
34 gdb -x $cmd
35done