bring in fixes from beta12:

- better error checking for read/write failures
	- new install/configure/Makefile and support scripts (we don't use)
	- don't allow 0 delay for non-root accounts
XXX: Someone needs to coordinate to feed back our prototype fixes to Jeff!
This commit is contained in:
christos 2001-05-22 15:38:22 +00:00
parent 188e0d6625
commit 3eced62df6
6 changed files with 194 additions and 107 deletions

View File

@ -262,9 +262,16 @@ set delay = `cat .$$`
echo ""
set rand = 0
ypwhich >&/dev/null
if ($status == 0 || -e /etc/passwd.dir || -e /etc/pwd.db) then
set rand = 1
if (-e /etc/nsswitch.conf) then
set rand = `grep '^passwd:.*nis' /etc/nsswitch.conf | wc -l`
if ($rand > 1) then
set rand = 1
endif
else
ypwhich >&/dev/null
if ($status == 0 || -e /etc/passwd.dir || -e /etc/pwd.db) then
set rand = 1
endif
endif
if ($rand == 1) then
@ -299,8 +306,15 @@ if ($status == 0) then
set cnt = `wc -l </tmp/$$.a`
set mapfile = "NIS map"
else
set cnt = `wc -l </etc/passwd`
set mapfile = "file"
rm /tmp/$$.a
niscat passwd.org_dir >&/tmp/$$.a
if ($status == 0) then
set cnt = `wc -l </tmp/$$.a`
set mapfile = "NISPLUS map"
else
set cnt = `wc -l </etc/passwd`
set mapfile = "file"
endif
endif
rm /tmp/$$.a
set double = `expr $cnt \* 2`
@ -341,15 +355,11 @@ set t_owner = root
set t_group = `$ls -d /usr/bin | awk ' { print $4 }'`
if (-e /proc) then
cat <<EOF
Uh oh! I see /proc out there. Some new Unix variants provide the
/proc file system as a mechanism to get to a process's address space.
This directory is typically only accessible by root. However, there
are a few systems (such as DG/UX) on which this directory exists, but
isn't used. I'm going to assume that top needs to run setuid to root,
but you should double check and use mode 2755 (set group id) if top
doesn't really need root access. If you are running SunOS 5.0 - SunOS
5.5.1 then you will need to install top setuid root (owner root and
mode 4711). In SunOS 5.6 top only requires set-gid sys permissions.
I see /proc out there. Many Unix variants provide the /proc file
system as a mechanism to get to a process's address space. This
directory is typically only accessible by root. However, there are a
few systems (such as DG/UX) on which this directory exists, but isn't
used.
EOF
if (-r /proc/0/psinfo) then
@ -357,9 +367,24 @@ EOF
set mode = 2711
set t_group = sys
set group = sys
cat <<EOF
It looks like this system is running Solaris 2.6 or greater. If this
is the case, then top can function just fine installed set group id to
sys. It does not need to be installed set-uid to root.
EOF
else
set t_mode = 4711
set mode = 4711
cat <<EOF
I'm going to assume that top needs to run setuid to root, but you
should double check and use mode 2755 (set group id) if top doesn't
really need root access. If you are running SunOS 5.0 through SunOS
5.5.1 (that's Solaris 2.0 through Solaris 2.5.1) then you will need to
install top setuid root (owner root and mode 4711). In SunOS 5.6
and higher top only requires set group id sys permissions.
EOF
endif
else if (-e /dev/kmem) then
$ls /dev/kmem >/tmp/$$.b
@ -418,13 +443,14 @@ echo "We are done with the questions."
# Some Unix environments are so poor that their csh doesn't even support
# the "eval" builtin. Check for this before relying on its use to save
# the current configuration.
/bin/csh -c "eval echo foo" >&/dev/null
/bin/csh -fc "eval echo foo" >&/dev/null
if ($status == 1) then
echo "Can't save configuration (nonfatal)"
else
echo "Saving configuration..."
# save settings to use as defaults the next time
rm -f .defaults
touch .defaults
foreach v ($vars)
set tmp = `eval echo \$$v`
echo set $v = "'$tmp'" >>.defaults
@ -444,6 +470,7 @@ ln -s machine/m_${module}.c machine.c
set libs = `grep LIBS: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`
set cflgs = `grep CFLAGS: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`
set tcap = `grep TERMCAP: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`
set math = `grep MATH: machine/m_${module}.desc | sed -e 's/^.[^:]*: *//'`
# get osrev defition, if we can
set uname=""
@ -464,6 +491,15 @@ endif
# default for tcap (termcap)
if ("$tcap" == "") then
set tcap="-ltermcap"
else if ("$tcap" == "none") then
set tcap=""
endif
# allow for the module to override or remove -lm
if ("$math" == "") then
set math="-lm"
else if ("$math" == "none") then
set math=""
endif
if ( { grep -s SIGKILL /usr/include/signal.h } ) then
@ -487,6 +523,7 @@ sed -e "s|%topn%|$topn|" \
-e "s|%libs%|$libs|" \
-e "s|%cflgs%|$cflgs|" \
-e "s|%termcap%|$tcap|" \
-e "s|%math%|$math|" \
-e "s|%cdefs%|$cdefs|" \
-e "s|%signal%|$signal|" \
-e "s|%cc%|$Cmdcc|" \
@ -494,7 +531,7 @@ sed -e "s|%topn%|$topn|" \
-e "s|%install%|$Cmdinstall|" \
-e "s|%shell%|$Cmdshell|" \
-e "s|%osrev%|$osrev|" \
Makefile.X > /dev/null
Makefile.X >Makefile
echo "Building top.local.h..."
sed -e "s|%LoadMax%|$LoadMax|" \

View File

@ -53,6 +53,7 @@ OBJS = top.o commands.o display.o screen.o username.o \
CDEFS = %cdefs%
LIBS = %libs%
TERMCAP = %termcap%
MATH = %math%
CFLAGS = %cflgs% $(CDEFS)
LINTFLAGS = -x $(CDEFS)
@ -69,14 +70,14 @@ top.local.h: top.local.H
top: $(OBJS)
rm -f top
$(CC) -o top $(OBJS) $(TERMCAP) -lm $(LIBS)
$(CC) $(CDEFS) -o top $(OBJS) $(TERMCAP) $(MATH) $(LIBS)
lint: sigdesc.h
$(LINT) $(LINTFLAGS) $(CFILES)
# include file dependencies
top.o: boolean.h display.h screen.h top.h top.local.h utils.h machine.h
commands.o: boolean.h sigdesc.h utils.h
commands.o: boolean.h sigdesc.h top.h utils.h
display.o: boolean.h display.h layout.h screen.h top.h top.local.h utils.h
screen.o: boolean.h screen.h
utils.o: top.h
@ -84,7 +85,7 @@ version.o: top.h patchlevel.h
username.o: top.local.h utils.h
# when compiling machine.c, include os revision definition
machine.o: top.h machine.h utils.h
machine.o: machine.c top.h machine.h utils.h
$(CC) "%osrev%" $(CFLAGS) -c machine.c
# automatically built include file

View File

@ -1,90 +1,118 @@
#!/bin/csh -f
set ny = (no yes)
if ($2 == "yesno") then
@ i = $3 + 1
set pmpt = "$1 [$ny[$i]]: "
#!/bin/sh
# getans prompt type default results_filename
# type is one of
# number
# integer
# neginteger
# file default=default filename
# path
# yesno default=0,1 corres yes or no
# string (default)
RAWPMPT=$1
TYP=$2
DFLT=$3
OFNM=$4
ny0="no"; ny1="yes"
if [ ${TYP} = "yesno" ]; then
eval ny=\$ny${DFLT}
pmpt="${RAWPMPT} [$ny]: "
else
if ("$3" == "") then
set pmpt = "${1}"
if [ -z "${DFLT}" ]; then
pmpt="${RAWPMPT}"
else
set pmpt = "$1 [$3]: "
endif
endif
rpt:
echo -n "$pmpt"
if ( "`uname -s`" == SCO_SV ) then
set input = `sh -c 'read word; echo $word'`
pmpt="${RAWPMPT} [${DFLT}]: "
fi
fi
if [ x"`echo -n`" = x-n ]
then
c=\\c
else
set input = $<
endif
switch ($2)
case number:
set tmp = `echo $input | tr -d 0123456789.`
if ("x$tmp" != x) then
n=-n
fi
while :
do
echo $n "$pmpt"$c
read input
case "$TYP" in
number)
tmp=`echo $input | tr -d 0123456789.`
if [ -n "$tmp" ]; then
echo "Invalid number. Please try again."
goto rpt
endif
breaksw
continue
fi
;;
case integer:
set tmp = `echo $input | tr -d 0123456789`
if ("x$tmp" != x) then
integer)
tmp=`echo $input | tr -d 0123456789`
if [ -n "$tmp" ]; then
echo "Invalid integer. Please try again."
goto rpt
endif
breaksw
continue
fi
;;
case neginteger:
if ("x$input" != x-1) then
set tmp = `echo $input | tr -d 0123456789`
if ("x$tmp" != x) then
neginteger)
if [ "x$input" != "x-1" ]; then
tmp=`echo $input | tr -d 0123456789`
if [ -n "$tmp" ]; then
echo "Invalid integer. Please try again."
goto rpt
endif
endif
breaksw
continue
fi
fi
;;
case file:
if ("x$input" == "x") then
set input = $3
endif
if (! -e "$input") then
echo The file $input "does not exist. Please try again."
goto rpt
endif
breaksw
file)
if [ -z "$input" ]; then
input=${DFLT}
fi
if [ ! -f "$input" -a ! -d "$input" ]; then
echo "The file $input does not exist. Please try again."
continue
fi
;;
case path:
if ("x$input" == "x") then
set input = "$3"
endif
if (! -e "$input") then
foreach elt ($path)
if (-e "$elt/$input") breaksw
end
echo The command $input "was not found. Please try again."
goto rpt
endif
breaksw
path)
if [ -z "$input" ]; then
input="${DFLT}"
fi
if [ ! -f "$input" ]; then
path=`echo $PATH | sed -e s'/::/ . /g' -e 's/:/ /g'`
x=
for elt in $path; do
if [ -f "$elt/$input" ]; then x=1; break; fi
done
if [ -z "$x" ] ;then
echo "The command $input was not found. Please try again."
continue
fi
fi
;;
case yesno:
if ("x$input" == xy || "x$input" == xyes) then
set input = 1
else if ("x$input" == xn || "x$input" == xno) then
set input = 0
else if ("x$input" != x) then
echo 'Please answer "yes" or "no".'
goto rpt
endif
breaksw
yesno)
if [ -z "$input" ]; then
input="${DFLT}"
else
case $input in
y | yes)
input=1 ;;
n | no)
input=0 ;;
*)
echo 'Please answer "yes" or "no".'
continue ;;
esac
fi
;;
default:
breaksw
*) ;;
esac
break
done
endsw
if [ -z "$input" ]; then
input="${DFLT}"
fi
if ("x$input" == x) then
set input = "$3"
endif
echo $input > $4
echo $input > ${OFNM}

View File

@ -1,4 +1,4 @@
/* $NetBSD: machine.h,v 1.4 2000/05/29 11:52:36 simonb Exp $ */
/* $NetBSD: machine.h,v 1.5 2001/05/22 15:38:22 christos Exp $ */
/*
* This file defines the interface between top and the machine-dependent
@ -23,12 +23,18 @@ struct statics
* the system_info struct is filled in by a machine dependent routine.
*/
#ifdef p_active /* uw7 define macro p_active */
#define P_ACTIVE p_pactive
#else
#define P_ACTIVE p_active
#endif
struct system_info
{
int last_pid;
double load_avg[NUM_AVERAGES];
int p_total;
int p_active; /* number of procs considered "active" */
int P_ACTIVE; /* number of procs considered "active" */
int *procstates;
int *cpustates;
int *memory;

View File

@ -1,4 +1,4 @@
/* $NetBSD: patchlevel.h,v 1.2 1999/04/12 06:02:26 ross Exp $ */
/* $NetBSD: patchlevel.h,v 1.3 2001/05/22 15:38:22 christos Exp $ */
#define PATCHLEVEL 5
#define BETA "beta9"
#define BETA "beta12"

View File

@ -1,4 +1,4 @@
/* $NetBSD: top.c,v 1.7 2001/04/12 14:10:05 abs Exp $ */
/* $NetBSD: top.c,v 1.8 2001/05/22 15:38:22 christos Exp $ */
char *copyright =
"Copyright (c) 1984 through 1996, William LeFebvre";
@ -269,10 +269,10 @@ char *argv[];
break;
case 's':
if ((delay = atoi(optarg)) < 0)
if ((delay = atoi(optarg)) < 0 || (delay == 0 && getuid() != 0))
{
fprintf(stderr,
"%s: warning: seconds delay should be non-negative -- using default\n",
"%s: warning: seconds delay should be positive -- using default\n",
myname);
delay = Default_DELAY;
warnings++;
@ -544,7 +544,7 @@ Usage: %s [-ISbinqu] [-d x] [-s x] [-o field] [-U username] [number]\n",
/* determine number of processes to actually display */
/* this number will be the smallest of: active processes,
number user requested, number current screen accomodates */
active_procs = system_info.p_active;
active_procs = system_info.P_ACTIVE;
if (active_procs > topn)
{
active_procs = topn;
@ -569,7 +569,13 @@ Usage: %s [-ISbinqu] [-d x] [-s x] [-o field] [-U username] [number]\n",
u_endscreen(i);
/* now, flush the output buffer */
fflush(stdout);
if (fflush(stdout) != 0)
{
new_message(MT_standout, " Write error on stdout");
putchar('\r');
quit(1);
/*NOTREACHED*/
}
/* only do the rest if we have more displays to show */
if (displays)
@ -625,8 +631,14 @@ Usage: %s [-ISbinqu] [-d x] [-s x] [-o field] [-U username] [number]\n",
/* now read it and convert to command strchr */
/* (use "change" as a temporary to hold strchr) */
if (read(0, &ch, 1) < 1)
quit(0);
if (read(0, &ch, 1) != 1)
{
/* read error: either 0 or -1 */
new_message(MT_standout, " Read error on stdin");
putchar('\r');
quit(1);
/*NOTREACHED*/
}
if ((iptr = strchr(command_chars, ch)) == NULL)
{
/* illegal command */
@ -729,7 +741,10 @@ Usage: %s [-ISbinqu] [-d x] [-s x] [-o field] [-U username] [number]\n",
new_message(MT_standout, "Seconds to delay: ");
if ((i = readline(tempbuf1, 8, Yes)) > -1)
{
delay = i;
if ((delay = i) == 0 && getuid() != 0)
{
delay = 1;
}
}
clear_message();
break;