diff --git a/tiny/GNUmakefile b/tiny/GNUmakefile index 8464a8d..e7e6ad9 100644 --- a/tiny/GNUmakefile +++ b/tiny/GNUmakefile @@ -17,6 +17,7 @@ install: \ $(BINDIR)/psg \ $(BINDIR)/save \ $(BINDIR)/savedate \ + $(BINDIR)/findsock \ fnp: fnp.sh fnpa: fnpa.sh diff --git a/tiny/findsock b/tiny/findsock new file mode 100755 index 0000000..fff5a17 --- /dev/null +++ b/tiny/findsock @@ -0,0 +1,19 @@ +#!/bin/sh +# +# Stupid little program to find the socket of stdin of the parent +# of the specified process. Normally this is used for the +# login shell to determine to which of several virtual hosts the +# user connected. + +if [ $# -eq 0 ] +then + echo "Usage: $0 " >&2 + exit 1 +fi + +pid=$1 + +ppid=`ps -ef | awk -v pid=$pid '$2 == pid { print $3 }'` + +sock=`lsof -p $ppid 2>/dev/null | awk '$4 == "0u" && $5 == "inet" { print $9 }'` +echo $sock