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
don't allow process to attach to itself
[unix-history]
/
usr
/
src
/
sys
/
kern
/
subr_prf.c
diff --git
a/usr/src/sys/kern/subr_prf.c
b/usr/src/sys/kern/subr_prf.c
index
66b414f
..
39447e6
100644
(file)
--- a/
usr/src/sys/kern/subr_prf.c
+++ b/
usr/src/sys/kern/subr_prf.c
@@
-4,23
+4,23
@@
*
* %sccs.include.redist.c%
*
*
* %sccs.include.redist.c%
*
- * @(#)subr_prf.c 7.
28
(Berkeley) %G%
+ * @(#)subr_prf.c 7.
39
(Berkeley) %G%
*/
*/
-#include
"param.h"
-#include
"systm.h"
-#include
"buf.h"
-#include
"conf.h"
-#include
"reboot.h"
-#include
"msgbuf.h"
-#include
"proc.h"
-#include
"ioctl.h"
-#include
"vnode.h"
-#include
"file.h"
-#include
"tty.h"
-#include
"tprintf.h"
-#include
"syslog.h"
-#include
"malloc.h"
+#include
<sys/param.h>
+#include
<sys/systm.h>
+#include
<sys/buf.h>
+#include
<sys/conf.h>
+#include
<sys/reboot.h>
+#include
<sys/msgbuf.h>
+#include
<sys/proc.h>
+#include
<sys/ioctl.h>
+#include
<sys/vnode.h>
+#include
<sys/file.h>
+#include
<sys/tty.h>
+#include
<sys/tprintf.h>
+#include
<sys/syslog.h>
+#include
<sys/malloc.h>
/*
* Note that stdarg.h and the ANSI style va_start macro is used for both
/*
* Note that stdarg.h and the ANSI style va_start macro is used for both
@@
-29,7
+29,7
@@
#include <machine/stdarg.h>
#ifdef KADB
#include <machine/stdarg.h>
#ifdef KADB
-#include
"machine/kdbparam.h"
+#include
<machine/kdbparam.h>
#endif
#define TOCONS 0x01
#endif
#define TOCONS 0x01
@@
-38,19
+38,15
@@
struct tty *constty; /* pointer to console "window" tty */
struct tty *constty; /* pointer to console "window" tty */
-#ifdef KADB
-extern cngetc(); /* standard console getc */
-int (*v_getc)() = cngetc; /* "" getc from virtual console */
-extern cnpoll();
-int (*v_poll)() = cnpoll; /* kdb hook to enable input polling */
-#endif
extern cnputc(); /* standard console putc */
extern cnputc(); /* standard console putc */
-int (*v_putc)() = cnputc; /* routine to putc on virtual console */
+int (*v_putc)() = cnputc; /* routine to putc on virtual console */
-
static
void logpri __P((int level));
+void logpri __P((int level));
static void putchar __P((int ch, int flags, struct tty *tp));
static char *ksprintn __P((u_long num, int base, int *len));
static void putchar __P((int ch, int flags, struct tty *tp));
static char *ksprintn __P((u_long num, int base, int *len));
-void kprintf __P((const char *fmt, int flags, struct tty *tp, va_list));
+void kprintf __P((const char *fmt, int flags, struct tty *tp, va_list ap));
+
+int consintr = 1; /* Ok to handle console interrupts? */
extern cnputc(); /* standard console putc */
extern struct tty cons; /* standard console tty */
extern cnputc(); /* standard console putc */
extern struct tty cons; /* standard console tty */
@@
-58,37
+54,47
@@
struct tty *constty; /* pointer to console "window" tty */
int (*v_console)() = cnputc; /* routine to putc on virtual console */
/*
int (*v_console)() = cnputc; /* routine to putc on virtual console */
/*
- * Variable panicstr contains argument to first call to panic; used
- *
as flag
to indicate that the kernel has already called panic.
+ * Variable panicstr contains argument to first call to panic; used
as flag
+ * to indicate that the kernel has already called panic.
*/
*/
-c
har
*panicstr;
+c
onst char
*panicstr;
/*
* Panic is called on unresolvable fatal errors. It prints "panic: mesg",
* and then reboots. If we are called twice, then we avoid trying to sync
* the disks as this often leads to recursive panics.
*/
/*
* Panic is called on unresolvable fatal errors. It prints "panic: mesg",
* and then reboots. If we are called twice, then we avoid trying to sync
* the disks as this often leads to recursive panics.
*/
+#ifdef __GNUC__
+volatile void boot(int flags); /* boot() does not return */
+volatile /* panic() does not return */
+#endif
void
void
-panic(msg)
- char *msg;
+#ifdef __STDC__
+panic(const char *fmt, ...)
+#else
+panic(fmt, va_alist)
+ char *fmt;
+#endif
{
{
- int bootopt
= RB_AUTOBOOT | RB_DUMP
;
-
int s
;
+ int bootopt;
+
va_list ap
;
+ bootopt = RB_AUTOBOOT | RB_DUMP;
if (panicstr)
bootopt |= RB_NOSYNC;
else
if (panicstr)
bootopt |= RB_NOSYNC;
else
- panicstr = msg;
- printf("panic: %s\n", msg);
+ panicstr = fmt;
+
+ va_start(ap, fmt);
+ printf("panic: %r\n", fmt, ap);
+ va_end(ap);
+
#ifdef KGDB
kgdb_panic();
#endif
#ifdef KADB
#ifdef KGDB
kgdb_panic();
#endif
#ifdef KADB
- if (boothowto & RB_KDB) {
- s = splnet(); /* below kdb pri */
- setsoftkdb();
- splx(s);
- }
+ if (boothowto & RB_KDB)
+ kdbpanic();
#endif
boot(bootopt);
}
#endif
boot(bootopt);
}
@@
-98,7
+104,7
@@
panic(msg)
*/
void
tablefull(tab)
*/
void
tablefull(tab)
- char *tab;
+ c
onst c
har *tab;
{
log(LOG_ERR, "%s: table is full\n", tab);
{
log(LOG_ERR, "%s: table is full\n", tab);
@@
-113,23
+119,25
@@
void
#ifdef __STDC__
uprintf(const char *fmt, ...)
#else
#ifdef __STDC__
uprintf(const char *fmt, ...)
#else
-uprintf(fmt
/*, va_alist */
)
+uprintf(fmt
, va_alist
)
char *fmt;
#endif
{
register struct proc *p = curproc;
va_list ap;
char *fmt;
#endif
{
register struct proc *p = curproc;
va_list ap;
- va_start(ap, fmt);
- if (p->p_flag & SCTTY && p->p_session->s_ttyvp)
+ if (p->p_flag & SCTTY && p->p_session->s_ttyvp) {
+ va_start(ap, fmt);
kprintf(fmt, TOTTY, p->p_session->s_ttyp, ap);
kprintf(fmt, TOTTY, p->p_session->s_ttyp, ap);
- va_end(ap);
+ va_end(ap);
+ }
}
tpr_t
tprintf_open(p)
register struct proc *p;
{
}
tpr_t
tprintf_open(p)
register struct proc *p;
{
+
if (p->p_flag & SCTTY && p->p_session->s_ttyvp) {
SESSHOLD(p->p_session);
return ((tpr_t) p->p_session);
if (p->p_flag & SCTTY && p->p_session->s_ttyvp) {
SESSHOLD(p->p_session);
return ((tpr_t) p->p_session);
@@
-141,6
+149,7
@@
void
tprintf_close(sess)
tpr_t sess;
{
tprintf_close(sess)
tpr_t sess;
{
+
if (sess)
SESSRELE((struct session *) sess);
}
if (sess)
SESSRELE((struct session *) sess);
}
@@
-153,7
+162,7
@@
void
#ifdef __STDC__
tprintf(tpr_t tpr, const char *fmt, ...)
#else
#ifdef __STDC__
tprintf(tpr_t tpr, const char *fmt, ...)
#else
-tprintf(tpr, fmt
/*, va_alist */
)
+tprintf(tpr, fmt
, va_alist
)
tpr_t tpr;
char *fmt;
#endif
tpr_t tpr;
char *fmt;
#endif
@@
-183,7
+192,7
@@
void
#ifdef __STDC__
ttyprintf(struct tty *tp, const char *fmt, ...)
#else
#ifdef __STDC__
ttyprintf(struct tty *tp, const char *fmt, ...)
#else
-ttyprintf(tp, fmt
/*, va_alist */
)
+ttyprintf(tp, fmt
, va_alist
)
struct tty *tp;
char *fmt;
#endif
struct tty *tp;
char *fmt;
#endif
@@
-206,25
+215,29
@@
void
#ifdef __STDC__
log(int level, const char *fmt, ...)
#else
#ifdef __STDC__
log(int level, const char *fmt, ...)
#else
-log(level, fmt
/*, va_alist */
)
+log(level, fmt
, va_alist
)
int level;
char *fmt;
#endif
{
int level;
char *fmt;
#endif
{
- register
s = splhigh()
;
+ register
int s
;
va_list ap;
va_list ap;
+ s = splhigh();
logpri(level);
va_start(ap, fmt);
kprintf(fmt, TOLOG, NULL, ap);
splx(s);
logpri(level);
va_start(ap, fmt);
kprintf(fmt, TOLOG, NULL, ap);
splx(s);
- if (!log_open)
- kprintf(fmt, TOCONS, NULL, ap);
va_end(ap);
va_end(ap);
+ if (!log_open) {
+ va_start(ap, fmt);
+ kprintf(fmt, TOCONS, NULL, ap);
+ va_end(ap);
+ }
logwakeup();
}
logwakeup();
}
-
static
void
+void
logpri(level)
int level;
{
logpri(level)
int level;
{
@@
-241,34
+254,36
@@
void
#ifdef __STDC__
addlog(const char *fmt, ...)
#else
#ifdef __STDC__
addlog(const char *fmt, ...)
#else
-addlog(fmt
/*, va_alist */
)
+addlog(fmt
, va_alist
)
char *fmt;
#endif
{
char *fmt;
#endif
{
- register
s = splhigh()
;
+ register
int s
;
va_list ap;
va_list ap;
+ s = splhigh();
va_start(ap, fmt);
kprintf(fmt, TOLOG, NULL, ap);
splx(s);
va_start(ap, fmt);
kprintf(fmt, TOLOG, NULL, ap);
splx(s);
- if (!log_open)
- kprintf(fmt, TOCONS, NULL, ap);
va_end(ap);
va_end(ap);
+ if (!log_open) {
+ va_start(ap, fmt);
+ kprintf(fmt, TOCONS, NULL, ap);
+ va_end(ap);
+ }
logwakeup();
}
logwakeup();
}
-int consintr = 1; /* ok to handle console interrupts? */
-
void
#ifdef __STDC__
printf(const char *fmt, ...)
#else
void
#ifdef __STDC__
printf(const char *fmt, ...)
#else
-printf(fmt
/*, va_alist */
)
+printf(fmt
, va_alist
)
char *fmt;
#endif
{
char *fmt;
#endif
{
- register int savintr;
va_list ap;
va_list ap;
+ register int savintr;
savintr = consintr; /* disable interrupts */
consintr = 0;
savintr = consintr; /* disable interrupts */
consintr = 0;
@@
-296,21
+311,22
@@
printf(fmt /*, va_alist */)
* the next characters (up to a control character, i.e. a character <= 32),
* give the name of the register. Thus:
*
* the next characters (up to a control character, i.e. a character <= 32),
* give the name of the register. Thus:
*
- * printf("reg=%b\n", 3, "\10\2BITTWO\1BITONE\n");
+ *
k
printf("reg=%b\n", 3, "\10\2BITTWO\1BITONE\n");
*
* would produce output:
*
* reg=3<BITTWO,BITONE>
*
*
* would produce output:
*
* reg=3<BITTWO,BITONE>
*
- * The format %r is supposed to pass an additional format string and argument
- * list recursively.
- * Its usage is:
+ * The format %r passes an additional format string and argument list
+ * recursively. Its usage is:
*
*
- * fn(otherstuff, fmt [, arg1, ... ])
- * char *fmt;
- * u_int arg1, ...;
- *
- * printf("prefix: %r, other stuff\n", fmt, ap);
+ * fn(char *fmt, ...)
+ * {
+ * va_list ap;
+ * va_start(ap, fmt);
+ * printf("prefix: %r: suffix\n", fmt, ap);
+ * va_end(ap);
+ * }
*
* Space or zero padding and a field width are supported for the numeric
* formats only.
*
* Space or zero padding and a field width are supported for the numeric
* formats only.
@@
-322,7
+338,7
@@
kprintf(fmt, flags, tp, ap)
struct tty *tp;
va_list ap;
{
struct tty *tp;
va_list ap;
{
- register char *p;
+ register char *p
, *q
;
register int ch, n;
u_long ul;
int base, lflag, tmp, width;
register int ch, n;
u_long ul;
int base, lflag, tmp, width;
@@
-356,7
+372,7
@@
reswitch: switch (ch = *(u_char *)fmt++) {
case 'b':
ul = va_arg(ap, int);
p = va_arg(ap, char *);
case 'b':
ul = va_arg(ap, int);
p = va_arg(ap, char *);
- for (
p = ksprintn(ul, *p++, NULL); ch = *p
--;)
+ for (
q = ksprintn(ul, *p++, NULL); ch = *q
--;)
putchar(ch, flags, tp);
if (!ul)
putchar(ch, flags, tp);
if (!ul)
@@
-369,7
+385,8
@@
reswitch: switch (ch = *(u_char *)fmt++) {
putchar(n, flags, tp);
tmp = 1;
} else
putchar(n, flags, tp);
tmp = 1;
} else
- for (; *p > ' '; ++p);
+ for (; *p > ' '; ++p)
+ continue;
}
if (tmp)
putchar('>', flags, tp);
}
if (tmp)
putchar('>', flags, tp);
@@
-397,7
+414,7
@@
reswitch: switch (ch = *(u_char *)fmt++) {
case 'o':
ul = lflag ? va_arg(ap, u_long) : va_arg(ap, u_int);
base = 8;
case 'o':
ul = lflag ? va_arg(ap, u_long) : va_arg(ap, u_int);
base = 8;
- goto number;
;
+ goto number;
case 'u':
ul = lflag ? va_arg(ap, u_long) : va_arg(ap, u_int);
base = 10;
case 'u':
ul = lflag ? va_arg(ap, u_long) : va_arg(ap, u_int);
base = 10;
@@
-452,14
+469,10
@@
putchar(c, flags, tp)
constty = NULL;
if ((flags & TOLOG) &&
c != '\0' && c != '\r' && c != 0177 && msgbufmapped) {
constty = NULL;
if ((flags & TOLOG) &&
c != '\0' && c != '\r' && c != 0177 && msgbufmapped) {
- mbp = msgbufp;
+ mbp = msgbufp;
if (mbp->msg_magic != MSG_MAGIC) {
if (mbp->msg_magic != MSG_MAGIC) {
- register int i;
-
+ bzero((caddr_t)mbp, sizeof(*mbp));
mbp->msg_magic = MSG_MAGIC;
mbp->msg_magic = MSG_MAGIC;
- mbp->msg_bufx = mbp->msg_bufr = 0;
- for (i = 0; i < MSG_BSIZE; i++)
- mbp->msg_bufc[i] = 0;
}
mbp->msg_bufc[mbp->msg_bufx++] = c;
if (mbp->msg_bufx < 0 || mbp->msg_bufx >= MSG_BSIZE)
}
mbp->msg_bufc[mbp->msg_bufx++] = c;
if (mbp->msg_bufx < 0 || mbp->msg_bufx >= MSG_BSIZE)