Date: Tue, 19 Mar 2002 00:10:03 -0800 (PST) From: "Tim J. Robbins" <tim@robbins.dropbear.id.au> To: freebsd-standards@FreeBSD.org Subject: Re: standards/36076: Implementation of POSIX fuser command Message-ID: <200203190810.g2J8A3761846@freefall.freebsd.org>
index | next in thread | raw e-mail
The following reply was made to PR standards/36076; it has been noted by GNATS.
From: "Tim J. Robbins" <tim@robbins.dropbear.id.au>
To: Garrett Wollman <wollman@lcs.mit.edu>
Cc: freebsd-gnats-submit@FreeBSD.ORG
Subject: Re: standards/36076: Implementation of POSIX fuser command
Date: Tue, 19 Mar 2002 19:02:54 +1100
On Mon, Mar 18, 2002 at 10:38:42PM -0500, Garrett Wollman wrote:
> This script breaks when the argument to -M contains shell field
> separators.
Thanks for the info; here is an updated version of the script that
fixes this problem, as well as a problem in the output format caused
by my misreading of the standard (the output is the same as Solaris now,
except that it seems to use tabs where I use spaces).
#!/bin/sh
#
# Copyright (c) 2002 Tim J. Robbins.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# fuser - list process IDs of all processes that have one or more files open
# This is a wrapper script around fstat(1).
#
# $FreeBSD$
# $Id: fuser.sh,v 1.4 2002/03/19 07:58:05 tim Exp $
#
cflag=0
fflag=0
uflag=0
opt_M=""
opt_N=""
opt_m=""
while getopts M:N:cfmu ch; do
case $ch in
M) # Choose memory file
opt_M="$OPTARG"
;;
N) # Choose kernel file
opt_N="$OPTARG"
;;
c) # Treat as mount point
cflag=1
;;
f) # Show open block devices
fflag=1
;;
m) # Show memory mapped files
opt_m="-m"
;;
u) # Print user names
uflag=1
;;
esac
done
shift $(($OPTIND - 1))
if [ $# -eq 0 -o \( $cflag -eq 1 -a $fflag -eq 1 \) ]; then
echo "usage: fuser [-c|-f] [-mu] [-M core] [-N system] file..." >&2
exit 64
fi
for f in $*; do
echo -n "$f: " >&2
if [ $cflag -eq 1 ]; then
fstat ${opt_M:+"-M${opt_M}"} ${opt_N:+"-N${opt_N}"} \
$opt_m -f -- "$f"
else
mtpt=`mount | awk '$1 == "'"$f"'" { print $3; }'`
if [ "$mtpt" != "" -a $fflag -ne 1 ]; then
fstat ${opt_M:+"-M${opt_M}"} ${opt_N:+"-N${opt_N}"} \
$opt_m -f -- "$mtpt"
else
fstat ${opt_M:+"-M${opt_M}"} ${opt_N:+"-N${opt_N}"} \
$opt_m -- "$f"
fi
fi | tail -n +2 | while read user cmd pid fd junk; do
echo -n "$pid"
case $fd in
wd)
echo -n c >&2
;;
root)
echo -n r >&2
;;
text)
echo -n x >&2
;;
tr)
echo -n t >&2
;;
mmap)
echo -n m >&2
;;
esac
if [ $uflag -eq 1 ]; then
echo -n "($user)" >&2
fi
echo -n " "
done
echo >&2
done
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-standards" in the body of the message
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200203190810.g2J8A3761846>
