Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Add a KERN_MSGBUF sysctl to return the message buffer.



details:   https://anonhg.NetBSD.org/src/rev/2c04d86b1b52
branches:  trunk
changeset: 487963:2c04d86b1b52
user:      simonb <simonb%NetBSD.org@localhost>
date:      Fri Jun 16 00:18:09 2000 +0000

description:
Add a KERN_MSGBUF sysctl to return the message buffer.

diffstat:

 sys/kern/kern_sysctl.c |  48 +++++++++++++++++++++++++++++++++++++++++++++++-
 sys/sys/sysctl.h       |   6 ++++--
 2 files changed, 51 insertions(+), 3 deletions(-)

diffs (103 lines):

diff -r 37dd7c521508 -r 2c04d86b1b52 sys/kern/kern_sysctl.c
--- a/sys/kern/kern_sysctl.c    Thu Jun 15 23:39:14 2000 +0000
+++ b/sys/kern/kern_sysctl.c    Fri Jun 16 00:18:09 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_sysctl.c,v 1.71 2000/06/13 01:27:00 simonb Exp $  */
+/*     $NetBSD: kern_sysctl.c,v 1.72 2000/06/16 00:18:09 simonb Exp $  */
 
 /*-
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -102,6 +102,7 @@
 #if defined(SYSVMSG) || defined(SYSVSEM) || defined(SYSVSHM)
 static int sysctl_sysvipc __P((int *, u_int, void *, size_t *));
 #endif
+static int sysctl_msgbuf __P((void *, size_t *));
 static int sysctl_doeproc __P((int *, u_int, void *, size_t *));
 static void fill_kproc2 __P((struct proc *, struct kinfo_proc2 *));
 static int sysctl_procargs __P((int *, u_int, void *, size_t *, struct proc *));
@@ -466,6 +467,8 @@
        case KERN_SYSVIPC_INFO:
                return (sysctl_sysvipc(name + 1, namelen - 1, oldp, oldlenp));
 #endif
+       case KERN_MSGBUF:
+               return (sysctl_msgbuf(oldp, oldlenp));
        default:
                return (EOPNOTSUPP);
        }
@@ -1150,6 +1153,49 @@
 }
 #endif /* SYSVMSG || SYSVSEM || SYSVSHM */
 
+static int
+sysctl_msgbuf(vwhere, sizep)
+       void *vwhere;
+       size_t *sizep;
+{
+       char *where = vwhere;
+       size_t len, maxlen = *sizep;
+       long pos;
+       int error;
+
+       /*
+        * deal with cases where the message buffer has
+        * become corrupted.
+        */
+       if (!msgbufenabled || msgbufp->msg_magic != MSG_MAGIC) {
+               msgbufenabled = 0;
+               return (ENXIO);
+       }
+
+       if (where == NULL) {
+               /* always return full buffer size */
+               *sizep = msgbufp->msg_bufs;
+               return (0);
+       }
+
+       error = 0;
+       maxlen = min(msgbufp->msg_bufs, maxlen);
+       pos = msgbufp->msg_bufx;
+       while (maxlen > 0) {
+               len = pos == 0 ? msgbufp->msg_bufx : msgbufp->msg_bufs - msgbufp->msg_bufx;
+               len = min(len, maxlen);
+               if (len == 0)
+                       break;
+               error = copyout(&msgbufp->msg_bufc[pos], where, len);
+               if (error)
+                       break;
+               where += len;
+               maxlen -= len;
+               pos = 0;
+       }
+       return (error);
+}
+
 /*
  * try over estimating by 5 procs
  */
diff -r 37dd7c521508 -r 2c04d86b1b52 sys/sys/sysctl.h
--- a/sys/sys/sysctl.h  Thu Jun 15 23:39:14 2000 +0000
+++ b/sys/sys/sysctl.h  Fri Jun 16 00:18:09 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sysctl.h,v 1.50 2000/06/13 01:27:02 simonb Exp $       */
+/*     $NetBSD: sysctl.h,v 1.51 2000/06/16 00:18:10 simonb Exp $       */
 
 /*
  * Copyright (c) 1989, 1993
@@ -164,7 +164,8 @@
 #define        KERN_CCPU               50      /* int: fixpt ccpu */
 #define        KERN_CP_TIME            51      /* struct: cpu time counters */
 #define        KERN_SYSVIPC_INFO       52      /* number of valid kern ids */
-#define        KERN_MAXID              53      /* number of valid kern ids */
+#define        KERN_MSGBUF             53      /* kernel message buffer */
+#define        KERN_MAXID              54      /* number of valid kern ids */
 
 #define        CTL_KERN_NAMES { \
        { 0, 0 }, \
@@ -220,6 +221,7 @@
        { "ccpu", CTLTYPE_INT }, \
        { "cp_time", CTLTYPE_STRUCT }, \
        { "sysvipc_info", CTLTYPE_STRUCT }, \
+       { "msgbuf", CTLTYPE_STRUCT }, \
 }
 
 /*



Home | Main Index | Thread Index | Old Index