Subject: kern/468: it'd be nice for /kern to provide tickadj
To: None <gnats-admin>
From: der Mouse <mouse@Collatz.McRCIM.McGill.EDU>
List: netbsd-bugs
Date: 09/08/1994 14:05:44
>Number:         468
>Category:       kern
>Synopsis:       it'd be nice for /kern to provide tickadj
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    gnats-admin (Kernel Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Thu Sep  8 14:05:42 1994
>Originator:     der Mouse
>Organization:
	Me?  Organized??
>Release:        NetBSD 1.0_BETA
>Environment:
	SPARC IPC, but it doesn't matter
>Description:
	I wanted to change tickadj after boot.  Rather than trying to
	patch it the hard way, I just made kernfs provide read/write
	access to tickadj.  As a bonus, this patch also makes it easy
	to provide read/write access to other int variables in the
	kernel, by adding support for KTT_INT in kernfs_xwrite.
>How-To-Repeat:
	Try to change tickadj via /kern and notice it's not possible.
>Fix:
	Apply the following patch to miscfs/kernfs/kernfs_vnops.c.  I
	apologize for the shifted-over code in kernfs_xwrite, but I
	wasn't sure what the NetBSD style would do for this (braces
	that just open a new scope, rather than being "part of control
	structure"), so I just let my electric-C mode have its way with
	the indentation.

	The number parser is very rudimentary.  If the kernel already
	has something better, by all means, feel free to use it. :-)

	*** kernfs_vnops.c=	Mon Jul 25 19:09:25 1994
	--- kernfs_vnops.c	Wed Sep  7 12:17:58 1994
	***************
	*** 67,72 ****
	--- 67,74 ----
	  #define	WRITE_MODE	(S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH)
	  #define DIR_MODE	(S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
	  
	+ extern int tickadj; /* shouldn't this be in a .h file somewhere? */
	+ 
	  struct kern_target {
	  	u_char kt_type;
	  	u_char kt_namlen;
	***************
	*** 93,98 ****
	--- 95,101 ----
	       { DT_REG, N("copyright"), copyright,    KTT_STRING,   VREG, READ_MODE  },
	       { DT_REG, N("hostname"),  0,            KTT_HOSTNAME, VREG, WRITE_MODE },
	       { DT_REG, N("hz"),        &hz,          KTT_INT,      VREG, READ_MODE  },
	+      { DT_REG, N("tickadj"),   &tickadj,     KTT_INT,      VREG, WRITE_MODE },
	       { DT_REG, N("loadavg"),   0,            KTT_AVENRUN,  VREG, READ_MODE  },
	       { DT_REG, N("msgbuf"),    0,	     KTT_MSGBUF,   VREG, READ_MODE  },
	       { DT_REG, N("pagesize"),  &cnt.v_page_size, KTT_INT,  VREG, READ_MODE  },
	***************
	*** 191,196 ****
	--- 194,210 ----
	  {
	  
	  	switch (kt->kt_tag) {
	+ 			      case KTT_INT:
	+ 			       { int i;
	+ 				 int v;
	+ 				 v = 0;
	+ 				 for (i=0;(i<len)&&(buf[i]>='0')&&(buf[i]<='9');i++)
	+ 				  { v = (10 * v) + (buf[i] - '0');
	+ 				  }
	+ 				 *(int *)kt->kt_data = v;
	+ 			       }
	+ 			      return(0);
	+ 
	  	case KTT_HOSTNAME:
	  		if (buf[len-1] == '\n')
	  			--len;

					der Mouse

			    mouse@collatz.mcrcim.mcgill.edu
>Audit-Trail:
>Unformatted:


------------------------------------------------------------------------------