projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
date and time created 88/12/22 13:04:38 by sam
[unix-history]
/
usr
/
src
/
usr.bin
/
w
/
w.c
diff --git
a/usr/src/usr.bin/w/w.c
b/usr/src/usr.bin/w/w.c
index
e18cf25
..
c7292d1
100644
(file)
--- a/
usr/src/usr.bin/w/w.c
+++ b/
usr/src/usr.bin/w/w.c
@@
-1,4
+1,19
@@
-static char *sccsid = "@(#)w.c 4.3 (Berkeley) %G%";
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved. The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif not lint
+
+#ifndef lint
+static char sccsid[] = "@(#)w.c 5.9 (Berkeley) %G%";
+#endif not lint
+
/*
* w - print system status (who and what)
*
/*
* w - print system status (who and what)
*
@@
-10,16
+25,18
@@
static char *sccsid = "@(#)w.c 4.3 (Berkeley) %G%";
#include <stdio.h>
#include <ctype.h>
#include <utmp.h>
#include <stdio.h>
#include <ctype.h>
#include <utmp.h>
-#include <time.h>
#include <sys/stat.h>
#include <sys/dir.h>
#include <sys/user.h>
#include <sys/proc.h>
#include <sys/stat.h>
#include <sys/dir.h>
#include <sys/user.h>
#include <sys/proc.h>
-#include <sys/pte.h>
+#include <sys/ioctl.h>
+#include <machine/pte.h>
#include <sys/vm.h>
#include <sys/vm.h>
+#include <sys/tty.h>
#define NMAX sizeof(utmp.ut_name)
#define LMAX sizeof(utmp.ut_line)
#define NMAX sizeof(utmp.ut_name)
#define LMAX sizeof(utmp.ut_line)
+#define HMAX sizeof(utmp.ut_host)
#define ARGWIDTH 33 /* # chars left on 80 col crt for args */
#define ARGWIDTH 33 /* # chars left on 80 col crt for args */
@@
-33,29
+50,34
@@
struct pr {
time_t w_time; /* CPU time used by this process */
time_t w_ctime; /* CPU time used by children */
dev_t w_tty; /* tty device of process */
time_t w_time; /* CPU time used by this process */
time_t w_ctime; /* CPU time used by children */
dev_t w_tty; /* tty device of process */
+ int w_uid; /* uid of process */
char w_comm[15]; /* user.u_comm, null terminated */
char w_args[ARGWIDTH+1]; /* args if interesting process */
} *pr;
int nproc;
struct nlist nl[] = {
char w_comm[15]; /* user.u_comm, null terminated */
char w_args[ARGWIDTH+1]; /* args if interesting process */
} *pr;
int nproc;
struct nlist nl[] = {
+ { "_avenrun" },
+#define X_AVENRUN 0
+ { "_boottime" },
+#define X_BOOTTIME 1
{ "_proc" },
{ "_proc" },
-#define X_PROC
0
+#define X_PROC
2
{ "_swapdev" },
{ "_swapdev" },
-#define X_SWAPDEV
1
+#define X_SWAPDEV
3
{ "_Usrptmap" },
{ "_Usrptmap" },
-#define X_USRPTMA
2
+#define X_USRPTMA
4
{ "_usrpt" },
{ "_usrpt" },
-#define X_USRPT
3
+#define X_USRPT
5
{ "_nswap" },
{ "_nswap" },
-#define X_NSWAP 4
- { "_avenrun" },
-#define X_AVENRUN 5
- { "_bootime" },
-#define X_BOOTIME 6
+#define X_NSWAP 6
{ "_nproc" },
#define X_NPROC 7
{ "_nproc" },
#define X_NPROC 7
- { 0 },
+ { "_dmmin" },
+#define X_DMMIN 8
+ { "_dmmax" },
+#define X_DMMAX 9
+ { "" },
};
FILE *ps;
};
FILE *ps;
@@
-65,40
+87,48
@@
int kmem;
int mem;
int swap; /* /dev/kmem, mem, and swap */
int nswap;
int mem;
int swap; /* /dev/kmem, mem, and swap */
int nswap;
+int dmmin, dmmax;
dev_t tty;
dev_t tty;
+int uid;
char doing[520]; /* process attached to terminal */
time_t proctime; /* cpu time of process in doing */
double avenrun[3];
struct proc *aproc;
char doing[520]; /* process attached to terminal */
time_t proctime; /* cpu time of process in doing */
double avenrun[3];
struct proc *aproc;
+struct tty ttyent;
#define DIV60(t) ((t+30)/60) /* x/60 rounded */
#define TTYEQ (tty == pr[i].w_tty)
#define IGINT (1+3*1) /* ignoring both SIGINT & SIGQUIT */
char *getargs();
#define DIV60(t) ((t+30)/60) /* x/60 rounded */
#define TTYEQ (tty == pr[i].w_tty)
#define IGINT (1+3*1) /* ignoring both SIGINT & SIGQUIT */
char *getargs();
-char *fread();
char *ctime();
char *rindex();
FILE *popen();
struct tm *localtime();
char *ctime();
char *rindex();
FILE *popen();
struct tm *localtime();
+time_t findidle();
int debug; /* true if -d flag: debugging output */
int debug; /* true if -d flag: debugging output */
+int ttywidth = 80; /* width of tty */
int header = 1; /* true if -h flag: don't print heading */
int lflag = 1; /* true if -l flag: long style output */
int header = 1; /* true if -h flag: don't print heading */
int lflag = 1; /* true if -l flag: long style output */
+int prfrom = 1; /* true if not -f flag: print host from */
int login; /* true if invoked as login shell */
int login; /* true if invoked as login shell */
-
int
idle; /* number of minutes user is idle */
+
time_t
idle; /* number of minutes user is idle */
int nusers; /* number of users logged in now */
char * sel_user; /* login of particular user selected */
char firstchar; /* first char of name of prog invoked as */
time_t jobtime; /* total cpu time visible */
time_t now; /* the current time of day */
int nusers; /* number of users logged in now */
char * sel_user; /* login of particular user selected */
char firstchar; /* first char of name of prog invoked as */
time_t jobtime; /* total cpu time visible */
time_t now; /* the current time of day */
-struct t
m *nowt; /* current time as time struct */
-time_t
bootime, uptime;
/* time of last reboot & elapsed time since */
+struct t
imeval boottime;
+time_t
uptime;
/* time of last reboot & elapsed time since */
int np; /* number of processes currently active */
struct utmp utmp;
struct proc mproc;
int np; /* number of processes currently active */
struct utmp utmp;
struct proc mproc;
-struct user up;
-char fill[512];
+union {
+ struct user U_up;
+ char pad[NBPG][UPAGES];
+} Up;
+#define up Up.U_up
main(argc, argv)
char **argv;
main(argc, argv)
char **argv;
@@
-107,9
+137,8
@@
main(argc, argv)
register int i, j;
char *cp;
register int curpid, empty;
register int i, j;
char *cp;
register int curpid, empty;
-
char obuf[BUFSIZ]
;
+
struct winsize win
;
- setbuf(stdout, obuf);
login = (argv[0][0] == '-');
cp = rindex(argv[0], '/');
firstchar = login ? argv[0][1] : (cp==0) ? argv[0][0] : cp[1];
login = (argv[0][0] == '-');
cp = rindex(argv[0], '/');
firstchar = login ? argv[0][1] : (cp==0) ? argv[0][0] : cp[1];
@@
-124,6
+153,10
@@
main(argc, argv)
debug++;
break;
debug++;
break;
+ case 'f':
+ prfrom = !prfrom;
+ break;
+
case 'h':
header = 0;
break;
case 'h':
header = 0;
break;
@@
-148,7
+181,7
@@
main(argc, argv)
}
} else {
if (!isalnum(argv[1][0]) || argc > 2) {
}
} else {
if (!isalnum(argv[1][0]) || argc > 2) {
- printf("Usage: %s [ -hlsuw ] [ user ]\n", cp);
+ printf("Usage: %s [ -hls
f
uw ] [ user ]\n", cp);
exit(1);
} else
sel_user = argv[1];
exit(1);
} else
sel_user = argv[1];
@@
-166,29
+199,34
@@
main(argc, argv)
exit(1);
}
exit(1);
}
- if (firstchar != 'u')
+ if (firstchar == 'u') /* uptime(1) */
+ nl[X_BOOTTIME+1].n_name = "";
+ else { /* then read in procs, get window size */
readpr();
readpr();
+ if (ioctl(1, TIOCGWINSZ, &win) != -1 && win.ws_col > 70)
+ ttywidth = win.ws_col;
+ }
ut = fopen("/etc/utmp","r");
ut = fopen("/etc/utmp","r");
+ time(&now);
if (header) {
/* Print time of day */
if (header) {
/* Print time of day */
- time(&now);
- nowt = localtime(&now);
- prtat(nowt);
+ prtat(&now);
/*
* Print how long system has been up.
/*
* Print how long system has been up.
- * (Found by looking for "bootime" in kernel)
+ * (Found by looking for "boot
t
ime" in kernel)
*/
*/
- lseek(kmem, (long)nl[X_BOOTIME].n_value, 0);
- read(kmem, &boot
ime, sizeof (boo
time));
+ lseek(kmem, (long)nl[X_BOOT
T
IME].n_value, 0);
+ read(kmem, &boot
time, sizeof (boot
time));
- uptime = now - bootime;
+ uptime = now - boottime.tv_sec;
+ uptime += 30;
days = uptime / (60*60*24);
uptime %= (60*60*24);
hrs = uptime / (60*60);
uptime %= (60*60);
days = uptime / (60*60*24);
uptime %= (60*60*24);
hrs = uptime / (60*60);
uptime %= (60*60);
- mins =
DIV60(uptime)
;
+ mins =
uptime / 60
;
printf(" up");
if (days > 0)
printf(" up");
if (days > 0)
@@
-208,7
+246,7
@@
main(argc, argv)
nusers++;
}
rewind(ut);
nusers++;
}
rewind(ut);
- printf(" %d user
s", nusers
);
+ printf(" %d user
%s", nusers, nusers>1?"s":""
);
/*
* Print 1, 5, and 15 minute load averages.
/*
* Print 1, 5, and 15 minute load averages.
@@
-223,12
+261,16
@@
main(argc, argv)
printf(" %.2f", avenrun[i]);
}
printf("\n");
printf(" %.2f", avenrun[i]);
}
printf("\n");
- if (firstchar == 'u')
+ if (firstchar == 'u')
/* if this was uptime(1), finished */
exit(0);
/* Headers for rest of output */
exit(0);
/* Headers for rest of output */
- if (lflag)
+ if (lflag && prfrom)
+ printf("User tty from login@ idle JCPU PCPU what\n");
+ else if (lflag)
printf("User tty login@ idle JCPU PCPU what\n");
printf("User tty login@ idle JCPU PCPU what\n");
+ else if (prfrom)
+ printf("User tty from idle what\n");
else
printf("User tty idle what\n");
fflush(stdout);
else
printf("User tty idle what\n");
fflush(stdout);
@@
-257,7
+299,15
@@
main(argc, argv)
continue;
jobtime += pr[i].w_time + pr[i].w_ctime;
proctime += pr[i].w_time;
continue;
jobtime += pr[i].w_time + pr[i].w_ctime;
proctime += pr[i].w_time;
- if (debug) {
+ /*
+ * Meaning of debug fields following proc name is:
+ * & by itself: ignoring both SIGINT and QUIT.
+ * (==> this proc is not a candidate.)
+ * & <i> <q>: i is SIGINT status, q is quit.
+ * 0 == DFL, 1 == IGN, 2 == caught.
+ * *: proc pgrp == tty pgrp.
+ */
+ if (debug) {
printf("\t\t%d\t%s", pr[i].w_pid, pr[i].w_args);
if ((j=pr[i].w_igintr) > 0)
if (j==IGINT)
printf("\t\t%d\t%s", pr[i].w_pid, pr[i].w_args);
if ((j=pr[i].w_igintr) > 0)
if (j==IGINT)
@@
-297,6
+347,7
@@
gettty()
strcat(ttybuf, utmp.ut_line);
stat(ttybuf, &statbuf);
tty = statbuf.st_rdev;
strcat(ttybuf, utmp.ut_line);
stat(ttybuf, &statbuf);
tty = statbuf.st_rdev;
+ uid = statbuf.st_uid;
}
/*
}
/*
@@
-305,42
+356,60
@@
gettty()
putline()
{
register int tm;
putline()
{
register int tm;
+ int width = ttywidth - 1;
/* print login name of the user */
printf("%-*.*s ", NMAX, NMAX, utmp.ut_name);
/* print login name of the user */
printf("%-*.*s ", NMAX, NMAX, utmp.ut_name);
+ width -= NMAX + 1;
/* print tty user is on */
/* print tty user is on */
- if (lflag
)
+ if (lflag
&& !prfrom) {
/* long form: all (up to) LMAX chars */
printf("%-*.*s", LMAX, LMAX, utmp.ut_line);
/* long form: all (up to) LMAX chars */
printf("%-*.*s", LMAX, LMAX, utmp.ut_line);
- else {
+ width -= LMAX;
+ } else {
/* short form: 2 chars, skipping 'tty' if there */
if (utmp.ut_line[0]=='t' && utmp.ut_line[1]=='t' && utmp.ut_line[2]=='y')
printf("%-2.2s", &utmp.ut_line[3]);
else
printf("%-2.2s", utmp.ut_line);
/* short form: 2 chars, skipping 'tty' if there */
if (utmp.ut_line[0]=='t' && utmp.ut_line[1]=='t' && utmp.ut_line[2]=='y')
printf("%-2.2s", &utmp.ut_line[3]);
else
printf("%-2.2s", utmp.ut_line);
+ width -= 2;
}
}
- if (lflag)
+ if (prfrom) {
+ printf(" %-14.14s", utmp.ut_host);
+ width -= 15;
+ }
+
+ if (lflag) {
/* print when the user logged in */
/* print when the user logged in */
- prtat(localtime(&utmp.ut_time));
+ prtat(&utmp.ut_time);
+ width -= 8;
+ }
/* print idle time */
/* print idle time */
- prttime(idle," ");
+ if (idle >= 36 * 60)
+ printf("%2ddays ", (idle + 12 * 60) / (24 * 60));
+ else
+ prttime(idle," ");
+ width -= 7;
if (lflag) {
/* print CPU time for all processes & children */
if (lflag) {
/* print CPU time for all processes & children */
- prttime(DIV60(jobtime)," ");
+ prttime(jobtime," ");
+ width -= 7;
/* print cpu time for interesting process */
/* print cpu time for interesting process */
- prttime(DIV60(proctime)," ");
+ prttime(proctime," ");
+ width -= 7;
}
/* what user is doing, either command tail or args */
}
/* what user is doing, either command tail or args */
- printf(" %-.
32s\n",
doing);
+ printf(" %-.
*s\n", width-1,
doing);
fflush(stdout);
}
/* find & return number of minutes current tty has been idle */
fflush(stdout);
}
/* find & return number of minutes current tty has been idle */
+time_t
findidle()
{
struct stat stbuf;
findidle()
{
struct stat stbuf;
@@
-358,8
+427,12
@@
findidle()
return(diff);
}
return(diff);
}
+#define HR (60 * 60)
+#define DAY (24 * HR)
+#define MON (30 * DAY)
+
/*
/*
- * prttime prints a time in hours and minutes.
+ * prttime prints a time in hours and minutes
or minutes and seconds
.
* The character string tail is printed at the end, obvious
* strings to pass are "", " ", or "am".
*/
* The character string tail is printed at the end, obvious
* strings to pass are "", " ", or "am".
*/
@@
-367,41
+440,52
@@
prttime(tim, tail)
time_t tim;
char *tail;
{
time_t tim;
char *tail;
{
- register int didhrs = 0;
if (tim >= 60) {
printf("%3d:", tim/60);
if (tim >= 60) {
printf("%3d:", tim/60);
- didhrs++;
- } else {
- printf(" ");
- }
- tim %= 60;
- if (tim > 0 || didhrs) {
- printf(didhrs&&tim<10 ? "%02d" : "%2d", tim);
- } else {
- printf(" ");
- }
+ tim %= 60;
+ printf("%02d", tim);
+ } else if (tim > 0)
+ printf(" %2d", tim);
+ else
+ printf(" ");
printf("%s", tail);
}
printf("%s", tail);
}
+char *weekday[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
+char *month[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
+
/* prtat prints a 12 hour time given a pointer to a time of day */
/* prtat prints a 12 hour time given a pointer to a time of day */
-prtat(
p
)
-
struct tm *p
;
+prtat(
time
)
+
long *time
;
{
{
- register int t, pm;
-
- t = p -> tm_hour;
- pm = (t > 11);
- if (t > 11)
- t -= 12;
- if (t == 0)
- t = 12;
- prttime(t*60 + p->tm_min, pm ? "pm" : "am");
+ struct tm *p;
+ register int hr, pm;
+
+ p = localtime(time);
+ hr = p->tm_hour;
+ pm = (hr > 11);
+ if (hr > 11)
+ hr -= 12;
+ if (hr == 0)
+ hr = 12;
+ if (now - *time <= 18 * HR)
+ prttime(hr * 60 + p->tm_min, pm ? "pm" : "am");
+ else if (now - *time <= 7 * DAY)
+ printf(" %s%2d%s", weekday[p->tm_wday], hr, pm ? "pm" : "am");
+ else
+ printf(" %2d%s%2d", p->tm_mday, month[p->tm_mon], p->tm_year);
}
/*
* readpr finds and reads in the array pr, containing the interesting
* parts of the proc and user tables for each live process.
}
/*
* readpr finds and reads in the array pr, containing the interesting
* parts of the proc and user tables for each live process.
+ * We only accept procs whos controlling tty has a pgrp equal to the
+ * pgrp of the proc. This accurately defines the notion of the current
+ * process(s), but because of time skew, we always read in the tty struct
+ * after reading the proc, even though the same tty struct may have been
+ * read earlier on.
*/
readpr()
{
*/
readpr()
{
@@
-426,10
+510,14
@@
readpr()
lseek(kmem, (long)nl[X_SWAPDEV].n_value, 0);
read(kmem, &nl[X_SWAPDEV].n_value, sizeof(nl[X_SWAPDEV].n_value));
/*
lseek(kmem, (long)nl[X_SWAPDEV].n_value, 0);
read(kmem, &nl[X_SWAPDEV].n_value, sizeof(nl[X_SWAPDEV].n_value));
/*
- * Find base of swap
+ * Find base of
and parameters of
swap
*/
lseek(kmem, (long)nl[X_NSWAP].n_value, 0);
read(kmem, &nswap, sizeof(nswap));
*/
lseek(kmem, (long)nl[X_NSWAP].n_value, 0);
read(kmem, &nswap, sizeof(nswap));
+ lseek(kmem, (long)nl[X_DMMIN].n_value, 0);
+ read(kmem, &dmmin, sizeof(dmmin));
+ lseek(kmem, (long)nl[X_DMMAX].n_value, 0);
+ read(kmem, &dmmax, sizeof(dmmax));
/*
* Locate proc table
*/
/*
* Locate proc table
*/
@@
-443,14
+531,13
@@
readpr()
lseek(kmem, (int)(aproc + pn), 0);
read(kmem, &mproc, sizeof mproc);
/* decide if it's an interesting process */
lseek(kmem, (int)(aproc + pn), 0);
read(kmem, &mproc, sizeof mproc);
/* decide if it's an interesting process */
- if (mproc.p_stat==0 || mproc.p_pgrp==0)
- continue;
- if (mproc.p_flag&SDETACH)
+ if (mproc.p_stat==0 || mproc.p_stat==SZOMB
+ || mproc.p_stat==SSTOP || mproc.p_pgrp==0)
continue;
/* find & read in the user structure */
if ((mproc.p_flag & SLOAD) == 0) {
/* not in memory - get from swap device */
continue;
/* find & read in the user structure */
if ((mproc.p_flag & SLOAD) == 0) {
/* not in memory - get from swap device */
- addr =
mproc.p_swaddr<<9
;
+ addr =
dtob(mproc.p_swaddr)
;
lseek(swap, (long)addr, 0);
if (read(swap, &up, sizeof(up)) != sizeof(up)) {
continue;
lseek(swap, (long)addr, 0);
if (read(swap, &up, sizeof(up)) != sizeof(up)) {
continue;
@@
-479,19
+566,31
@@
cont:
szpt = up.u_pcb.pcb_szpt;
pr[np].w_seekaddr = ctob(apte.pg_pfnum);
}
szpt = up.u_pcb.pcb_szpt;
pr[np].w_seekaddr = ctob(apte.pg_pfnum);
}
- vstodb(0,
1
, &up.u_smap, &db, 1);
- pr[np].w_lastpg =
c
tob(db.db_base);
+ vstodb(0,
CLSIZE
, &up.u_smap, &db, 1);
+ pr[np].w_lastpg =
d
tob(db.db_base);
if (up.u_ttyp == NULL)
continue;
if (up.u_ttyp == NULL)
continue;
+ /* only include a process whose tty has a pgrp which matchs its own */
+ lseek(kmem, (long)up.u_ttyp, 0);
+ if (read(kmem, &ttyent, sizeof(ttyent)) != sizeof(ttyent))
+ continue;
+ if (ttyent.t_pgrp != mproc.p_pgrp)
+ continue;
+
/* save the interesting parts */
pr[np].w_pid = mproc.p_pid;
pr[np].w_flag = mproc.p_flag;
pr[np].w_size = mproc.p_dsize + mproc.p_ssize;
/* save the interesting parts */
pr[np].w_pid = mproc.p_pid;
pr[np].w_flag = mproc.p_flag;
pr[np].w_size = mproc.p_dsize + mproc.p_ssize;
- pr[np].w_igintr = (((int)up.u_signal[2]==1) + 2*((int)up.u_signal[2]>1) + 3*((int)up.u_signal[3]==1)) + 6*((int)up.u_signal[3]>1);
- pr[np].w_time = up.u_vm.vm_utime + up.u_vm.vm_stime;
- pr[np].w_ctime = up.u_cvm.vm_utime + up.u_cvm.vm_stime;
+ pr[np].w_igintr = (((int)up.u_signal[2]==1) +
+ 2*((int)up.u_signal[2]>1) + 3*((int)up.u_signal[3]==1)) +
+ 6*((int)up.u_signal[3]>1);
+ pr[np].w_time =
+ up.u_ru.ru_utime.tv_sec + up.u_ru.ru_stime.tv_sec;
+ pr[np].w_ctime =
+ up.u_cru.ru_utime.tv_sec + up.u_cru.ru_stime.tv_sec;
pr[np].w_tty = up.u_ttyd;
pr[np].w_tty = up.u_ttyd;
+ pr[np].w_uid = mproc.p_uid;
up.u_comm[14] = 0; /* Bug: This bombs next field. */
strcpy(pr[np].w_comm, up.u_comm);
/*
up.u_comm[14] = 0; /* Bug: This bombs next field. */
strcpy(pr[np].w_comm, up.u_comm);
/*
@@
-519,7
+618,7
@@
getargs(p)
struct pr *p;
{
int c, addr, nbad;
struct pr *p;
{
int c, addr, nbad;
- static int abuf[
512
/sizeof(int)];
+ static int abuf[
CLSIZE*NBPG
/sizeof(int)];
struct pte pagetbl[NPTEPG];
register int *ip;
register char *cp, *cp1;
struct pte pagetbl[NPTEPG];
register int *ip;
register char *cp, *cp1;
@@
-533,8
+632,8
@@
getargs(p)
lseek(mem,c,0);
if (read(mem,pagetbl,NBPG) != NBPG)
return(p->w_comm);
lseek(mem,c,0);
if (read(mem,pagetbl,NBPG) != NBPG)
return(p->w_comm);
- if (pagetbl[NPTEPG-
1-UPAGES].pg_fod==0 && pagetbl[NPTEPG-1
-UPAGES].pg_pfnum) {
- lseek(mem,ctob(pagetbl[NPTEPG-
1
-UPAGES].pg_pfnum),0);
+ if (pagetbl[NPTEPG-
CLSIZE-UPAGES].pg_fod==0 && pagetbl[NPTEPG-CLSIZE
-UPAGES].pg_pfnum) {
+ lseek(mem,ctob(pagetbl[NPTEPG-
CLSIZE
-UPAGES].pg_pfnum),0);
if (read(mem,abuf,sizeof(abuf)) != sizeof(abuf))
return(p->w_comm);
} else {
if (read(mem,abuf,sizeof(abuf)) != sizeof(abuf))
return(p->w_comm);
} else {
@@
-543,15
+642,15
@@
getargs(p)
return(p->w_comm);
}
}
return(p->w_comm);
}
}
- abuf[
127
] = 0;
- for (ip = &abuf[
126
]; ip > abuf;) {
+ abuf[
sizeof(abuf)/sizeof(abuf[0])-1
] = 0;
+ for (ip = &abuf[
sizeof(abuf)/sizeof(abuf[0])-2
]; ip > abuf;) {
/* Look from top for -1 or 0 as terminator flag. */
if (*--ip == -1 || *ip == 0) {
cp = (char *)(ip+1);
if (*cp==0)
cp++;
nbad = 0; /* up to 5 funny chars as ?'s */
/* Look from top for -1 or 0 as terminator flag. */
if (*--ip == -1 || *ip == 0) {
cp = (char *)(ip+1);
if (*cp==0)
cp++;
nbad = 0; /* up to 5 funny chars as ?'s */
- for (cp1 = cp; cp1 < (char *)&abuf[
128
]; cp1++) {
+ for (cp1 = cp; cp1 < (char *)&abuf[
sizeof(abuf)/sizeof(abuf[0])
]; cp1++) {
c = *cp1&0177;
if (c==0) /* nulls between args => spaces */
*cp1 = ' ';
c = *cp1&0177;
if (c==0) /* nulls between args => spaces */
*cp1 = ' ';
@@
-589,14
+688,16
@@
vstodb(vsbase, vssize, dmp, dbp, rev)
struct dmap *dmp;
register struct dblock *dbp;
{
struct dmap *dmp;
register struct dblock *dbp;
{
- register int blk =
DMMIN
;
+ register int blk =
dmmin
;
register swblk_t *ip = dmp->dm_map;
register swblk_t *ip = dmp->dm_map;
+ vsbase = ctod(vsbase);
+ vssize = ctod(vssize);
if (vsbase < 0 || vsbase + vssize > dmp->dm_size)
panic("vstodb");
while (vsbase >= blk) {
vsbase -= blk;
if (vsbase < 0 || vsbase + vssize > dmp->dm_size)
panic("vstodb");
while (vsbase >= blk) {
vsbase -= blk;
- if (blk <
DMMAX
)
+ if (blk <
dmmax
)
blk *= 2;
ip++;
}
blk *= 2;
ip++;
}