Plan 9 from Bell Labs’s /usr/web/sources/patch/applied/getflags-script-changes/leak.new

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc

rfork e

flagfmt='s,b res width,f binary'
argv0=leak
args='proc || pid'

if(~ $#* 0) {
	aux/usage
	exit usage
}
bifs=$ifs
ifs=''
if(! eval `{aux/getflags $*}) {
	aux/usage
	exit usage
}
ifs=$bifs;

if(~ $#flags 1)
	sflag=($sflag -s)
if(~ $#flagf 1)
	sflag=($sflag -f $flagf)
if(! ~ $#flagb 0)
	xflag=(-b -r $flagb(1) -x $flagb(2))

if(~ $#sflag 1 && ! ~ $#flagb 0) {
	echo 'cannot use both -s and -b' >[1=2]
	exit usage
}
if(~ $#* 0) {
	aux/usage
	exit usage
}

if(! test -d /proc/$1) {
	# x=`{psu | awk '$NF=="'$1'" {print $2}'}
	x=`{psu | grep ' '$1'$' | sed 's/^[^ ]+ +([0-9]+).*/\1/'}
	if(~ $#x 0) {
		echo 'no processes named '$1 >[1=2]
		exit usage
	}
	if(! ~ $#flagb 0)
		xflag=(-b $flagb(1) $flagb(2))
	x=($sflag $xflag $x)
	echo leak $"x
	exit
}

x=`{echo $"* | tr ' ' ,}

echo 'leakdump({'$x'})' | acid -lpool -lleak $1 $flagf | aux/acidleak $xflag $flagf |
{
	if(~ $#flags 1)
		awk '{print $4}' |
			sort | uniq -c | sort -nr |
			sed 's! *(.*) (0x.*)!src(\2); // \1!'
	if not
		cat
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.