[comp.sources.misc] v13i102: u386mon 1.10

wht@gatech.edu@n4hgf.UUCP (Warren Tucker) (07/03/90)

Posting-number: Volume 13, Issue 102
Submitted-by: wht@gatech.edu@n4hgf.UUCP (Warren Tucker)
Archive-name: u386mon/part04

#!/bin/sh
# This is part 04 of u386mon.1.10
if touch 2>&1 | fgrep 'mmdd' > /dev/null
 then TOUCH=touch
 else TOUCH=true
fi
# ============= u386mon.h ==============
echo "x - extracting u386mon.h (Text)"
sed 's/^X//' << 'SHAR_EOF' > u386mon.h &&
X/*+-------------------------------------------------------------------------
X	u386mon.h
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:06-27-1990-01:57-wht@n4hgf-1.10 - incorporate suggestions from alpha testers */
X/*:06-25-1990-04:14-wht@n4hgf-1.02-better error handling */
X/*:06-24-1990-20:53-wht@n4hgf-v1.01-add ISC support thanks to peter@radig.de */
X/*:06-21-1990-14:27-r@n4hgf-version x0.12 seems bug free */
X/*:06-20-1990-03:03-root@n4hgf-trick use_cp into making bright fgnd colors */
X/*:06-19-1990-21:35-wht-get ready for release */
X
X#ifndef M_SYSV	/* for ISC */
X#define u_char unsigned char
X#define u_long unsigned long
X#endif
X
Xchar *getenv();
Xchar *strchr();
Xchar *strrchr();
X#ifdef __STDC__
Xvoid *malloc();
X#else
Xchar *malloc();
X#endif
X
X#define pW(pan) panel_window(pan)
X#define W WINDOW
X#define P PANEL
X
X/* color numbers for EGA/VGA */
X#ifdef COLOR_16_TERMINFO	/* wht 16-color fgnd/bgnd terminfo */
X#define cHIBIT	8
X#define cBLK	0
X#define cBLU	1
X#define cGRN	2
X#define cCYN	3
X#define cRED	4
X#define cMAG	5
X#define cBRN	6
X#define cWHT	7
X#define cGRY	(cBLK | cHIBIT)
X#define cLTB	(cBLU | cHIBIT)
X#define cLTG	(cGRN | cHIBIT)
X#define cLTC	(cCYN | cHIBIT)
X#define cLTR	(cRED | cHIBIT)
X#define cLTM	(cMAG | cHIBIT)
X#define cYEL	(cBRN | cHIBIT)
X#define cHIW	(cWHT | cHIBIT)
X#else
X#define cBLK	COLOR_BLACK
X#define cBLU	COLOR_BLUE
X#define cGRN	COLOR_GREEN
X#define cCYN	COLOR_CYAN
X#define cRED	COLOR_RED
X#define cMAG	COLOR_MAGENTA
X#define cBRN	COLOR_YELLOW
X#define cWHT	COLOR_WHITE
X#define cGRY	COLOR_BLACK
X#define cLTB	COLOR_BLUE
X#define cLTG	COLOR_GREEN
X#define cLTC	COLOR_CYAN
X#define cLTR	COLOR_RED
X#define cLTM	COLOR_MAGENTA
X#define cYEL	COLOR_YELLOW
X#define cHIW	COLOR_WHITE
X#endif
X
X#define sTL		0xDA
X#define sTR		0xBF
X#define sBL		0xC0
X#define sBR		0xD9
X#define sLT		0xC3	/* left hand T */
X#define sRT		0xB4	/* right hand T */
X#define sVR		0xB3	/* vertical rule */
X#define sHR		0xC4	/* horizontal rule */
X
X/* color pairs */
X#ifdef COLOR_16_TERMINFO	/* wht 16-color fgnd/bgnd terminfo */
X#define use_cp(win,cp) wattrset(win,COLOR_PAIR(cp))
X#else
X#define use_cp(win,cp) wattrset(win,COLOR_PAIR(cp) | ((cp >= cpLOW)?A_BOLD:0))
X#endif
X#define cpINFO		1	/* information field */
X#define cpHIGH		2	/* high/brk/pio */
X#define cpREVERSE	3	/* "reverse video" */
X/* color pairs >= cpLOW need A_BOLD when using standard ISO (non-wht) terminfo
X */
X#define cpLOW		4	/* low/user/iop */
X#define cpMED		5	/* medium/kernel/swap */
X#define cpBANNER	6	/* banner */
X#define cpLIT		7	/* field literals */
X
X#define MSG_TLY		(LINES - 2)
X#define CMD_TLY		(LINES - 1)
X#define LVMSG_Y		MSG_TLY
X#define LVMSG_X		0
X
X#define CPUSCALE_TLY		1
X#define CPUSCALE_SX			13
X#define CPUSCALE_WIDTH		50
X
X#define WAITSCALE_TLY		5
X#define WAITSCALE_SX		13
X#define WAITSCALE_WIDTH		50
X
X/* Sysinfo/Minfo per second area */
X#define PER_SEC_TLY			9
X#define PER_SEC1_TLX		0
X#define PER_SEC2_TLX		18
X#define PER_SEC3_TLX		35
X#define PER_SEC4_TLX		51
X#define PER_SEC5_TLX		66
X
X/* extra info area */
X#define EXTRA_TLY			26
X#define EXTRA1_TLX			0
X#define EXTRA2_TLX			18
X#define EXTRA3_TLX			43
X#define EXTRA4_TLX			62
X
X#include "lint_args.h"
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of u386mon.h */
SHAR_EOF
$TOUCH -am 0627015790 u386mon.h &&
chmod 0644 u386mon.h ||
echo "restore of u386mon.h failed"
set `wc -c u386mon.h`;Wc_c=$1
if test "$Wc_c" != "3211"; then
	echo original size 3211, current size $Wc_c
fi
# ============= renice/Makefile ==============
if test ! -d 'renice'; then
    echo "x - creating directory renice"
    mkdir 'renice'
fi
echo "x - extracting renice/Makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > renice/Makefile &&
X#+-------------------------------------------------------------------
X#  Makefile for renice for SCO UNIX V/386
X#  ...!emory!n4hgf!wht
X#--------------------------------------------------------------------
X#+:EDITS:*/
X#:06-25-1990-04:14-wht@n4hgf-1.03-better error handling
X#:06-21-1990-14:27-r@n4hgf-version x0.12 seems bug free
X#:06-19-1990-21:37-wht@n4hgf-get ready for 0.08 release
X
X#------------> CFLAGS 
XCFLAGS = -c -Octl -DLINT_ARGS
X#CFLAGS = -c -O
X
X#------------> BINDIR
XBINDIR = /usr/local/bin
X
X#LDFLAGS = -s
X
X
X#handle Sys V make "feature" of using SHELL
XSHELL = /bin/sh
X
X#FCRC = fcrc -u $*.c ;
X.c.o:;	$(FCRC) $(CC) $(CFLAGS) $*.c 
X
XSRC = \
X	renice.c
X
XRENICE_OBJ =\
X	renice.o\
X	../libnlsym.o\
X	libkmem-w.o
X
Xall: renice
X
X#must run as root
Xinstall: all
X	mv renice $(BINDIR)
X	chmod 4711 $(BINDIR)/renice
X	chown root $(BINDIR)/renice
X	@echo ' ';echo 'csh users rehash before executing'
X
Xrenice: $(RENICE_OBJ)
X	$(CC) $(LDFLAGS) -o $@ $(RENICE_OBJ) $(LIB)
X
Xlibkmem-w.o: ../libkmem.c
X	cc $(CFLAGS) -I .. -DKWRITE_NEEDED ../libkmem.c; mv libkmem.o libkmem-w.o
X
X../libnlsym.o: ../libnlsym.c
X	cd ..;make libnlsym.o
X
Xclean:
X	rm -f renice.o libkmem-w.o core 
X
Xclobber: clean
X	rm -f renice
X
SHAR_EOF
$TOUCH -am 0626155390 renice/Makefile &&
chmod 0644 renice/Makefile ||
echo "restore of renice/Makefile failed"
set `wc -c renice/Makefile`;Wc_c=$1
if test "$Wc_c" != "1186"; then
	echo original size 1186, current size $Wc_c
fi
# ============= renice/renice.c ==============
echo "x - extracting renice/renice.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > renice/renice.c &&
X/*+-------------------------------------------------------------------------
X	renice.c - UNIX 386 renice
X
X * This program was written by me, Mike "Ford" Ditto, and
X * I hereby release it into the public domain in the interest
X * of promoting the development of free, quality software
X * for the hackers and users of the world.
X *
X * Feel free to use, copy, modify, improve, and redistribute
X * this program, but keep in mind the spirit of this
X * contribution; always provide source, and always allow
X * free redistribution (shareware is fine with me).  If
X * you use a significant part of this code in a program of
X * yours, I would appreciate being given the appropriate
X * amount of credit.
X *				-=] Ford [=-
X *
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:06-26-1990-15:09-wht@n4hgf-adapt Ford's work to UNIX 386 */
X
X#include <stdio.h>
X#include <errno.h>
X#include <sys/types.h>
X#undef NGROUPS_MAX
X#undef NULL
X#include <sys/param.h>
X#include <sys/immu.h>
X#include <sys/region.h>
X#include <sys/proc.h>
X#include <sys/var.h>
X#include <nlist.h>
X#include "../nlsym.h"
X#include "../libkmem.h"
X#include "../libnlsym.h"
X
Xstruct var v;
Xstruct proc tproc;
Xint myuid;
Xchar *progname;
Xchar s128[128];
Xdaddr_t myreadcnt;
X
X/*+-------------------------------------------------------------------------
X	leave_text(text,exit_code)
XIf exit_code == 255, do perror
X--------------------------------------------------------------------------*/
Xvoid
Xleave_text(text,exit_code)
Xchar *text;
Xint exit_code;
X{
X	if(exit_code == 255)
X		perror(text);
X	else
X	{
X		fputs(text,stderr);
X		fputs(text,stderr);
X	}
X	exit(exit_code);
X}	/* end of leave */
X
X/* change the nice value of process `pid' based on 'value' and 'relative' */
Xrenice(pid,value,relative)
Xint pid;
Xint value;
Xint relative;
X{
X	register i;
X	int tmpnice;
X
X	for(i = 0; i < v.v_proc; i++)
X	{
X		kread((caddr_t)&tproc,(daddr_t)((struct proc *)procaddr + i),
X		    sizeof(struct proc));
X		if(tproc.p_pid == pid)
X		{
X#ifdef DEBUG
X			fprintf(stderr,"Found it!  proc[%d], p_uid is %d\n",
X			    i,tproc.p_uid);
X
X			fprintf(stderr,"Old p_nice was %d\n",tproc.p_nice);
X#endif /* DEBUG */
X
X			tmpnice = tproc.p_nice;
X
X			if(relative)
X				tmpnice += value;
X			else
X				tmpnice = value;
X
X			if(tmpnice >= 40)
X				tmpnice = 40;
X			if(tmpnice < 0)
X				tmpnice = 0;
X
X#ifdef DEBUG
X			fprintf(stderr,"New p_nice is %d\n",tmpnice);
X#endif /* DEBUG */
X
X			if( 
X#ifdef WHT
X				(myuid && (myuid != 201))
X#else
X				myuid
X#endif
X			 	&& ((myuid != tproc.p_uid) || (tmpnice < tproc.p_nice)))
X			{
X				errno = EACCES;
X				sprintf(s128,"%s: can't renice process %d",progname,pid);
X				perror(s128);
X				return 1;
X			}
X
X			tproc.p_nice = tmpnice;
X
X			kwrite((daddr_t)&((struct proc *)procaddr)[i]
X			    + ( ((caddr_t)&tproc.p_nice) - (caddr_t)&tproc ),
X			    (caddr_t)&tproc.p_nice,sizeof(tproc.p_nice));
X			return(0);
X		}
X	}
X	fprintf(stderr,"%s: process %d not found.\n",progname,pid);
X
X	return(1);
X}
X
X/*+-------------------------------------------------------------------------
X	usage()
X--------------------------------------------------------------------------*/
Xvoid
Xusage()
X{
X    fprintf(stderr,"usage: %s [{+-}inc] [=prio] pid ...\n",progname);
X    exit(-1);
X}	/* end of usage */
X
X/*+-------------------------------------------------------------------------
X	main(argc,argv)
X--------------------------------------------------------------------------*/
Xmain(argc,argv)
Xint argc;
Xchar **argv;
X{
X	int status=0;
X	int pid;
X	int relative = 1;
X	int value = 0;
X
X	progname = *argv;
X	if(argc < 2)
X		usage();
X
X	myuid = getuid();
X	nlsym_read();
X	kinit(1);
X	kread((caddr_t)&v,vaddr,sizeof(v));
X
X	while(++argv,--argc)
X	{
X		switch(**argv)
X		{
X		case '-':
X			if(sscanf(*argv+1,"%d",&value) != 1)
X				usage();
X			relative = 1;
X			break;
X		case '+':
X			if(sscanf(*argv+1,"%d",&value) != 1)
X				usage();
X			value = -value;
X			relative = 1;
X			break;
X		case '=':
X			if(sscanf(*argv+1,"%d",&value) != 1)
X				usage();
X			relative = 0;
X			break;
X		default:
X			if(sscanf(*argv,"%d",&pid) != 1)
X				usage();
X			status += renice(pid,value,relative);
X		}
X	}
X
X	exit(status);
X}	/* end of main */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of renice.c */
SHAR_EOF
$TOUCH -am 0626171790 renice/renice.c &&
chmod 0644 renice/renice.c ||
echo "restore of renice/renice.c failed"
set `wc -c renice/renice.c`;Wc_c=$1
if test "$Wc_c" != "4189"; then
	echo original size 4189, current size $Wc_c
fi
exit 0