Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Apr 97 10:56:00 PDT
From:      "Whitesel, Rick" <rwhitesel@xyplex.com>
To:        "'FreeBSD Hackers'" <freebsd-hackers@FreeBSD.ORG>
Subject:   ucd-snmp-3.1.3 patch
Message-ID:  <3360F09C@smtpgate.xyplex.com>

next in thread | raw e-mail | index | archive | help

Hi:
   I am enclosing the full replacement patch file for the file   
extensible.c. The file was missing an include of vm/vm_param.h. It   
appears that this file is no longer automatically included in the   
kernel.h(?) file. The file extensible.c is normally found in the   
following directory:

/usr/ports/net/ucd-snmp/work/ucd-snmp-3.1.3/agent/extensible

This patch should work for version 2.2x and forward of FreeBSD.

Rick Whitesel
Principal Consulting Engineer
Xyplex Networks
Eml: rwhitesel@xyplex.com
Pho: 508-952-4786
Fax: 508-952-4887


Xyplex Networks
295 Foster Street
Littleton, Mass 01460

[[ EXTENS~1.PAT : 3594 in EXTENS~1.PAT ]]

*** extensible.c.orig	Fri Apr 25 06:03:55 1997
--- extensible.c	Fri Apr 25 07:33:29 1997
***************
*** 75,80 ****
--- 75,85 ----
  #if STDC_HEADERS
  #include <string.h>
  #endif
+ #ifdef freebsd2
+ #include <sys/rlist.h>
+ #include <osreldate.h>
+ #include <vm/vm_param.h>
+ #endif
  
  #include "mibincl.h"
  #include "mibdefs.h"
***************
*** 101,107 ****
    static int exceptions[] = SECURITYEXCEPTIONS;
  #endif
  
! int checkmib(vp,name,length,exact,var_len,write_method,newname,max)
      register struct variable *vp;
      register oid	*name;
      register int	*length;
--- 106,113 ----
    static int exceptions[] = SECURITYEXCEPTIONS;
  #endif
  
! int
! checkmib(vp, name, length, exact, var_len, write_method, newname, max)
      register struct variable *vp;
      register oid	*name;
      register int	*length;
***************
*** 133,140 ****
      memmove(newname, vp->name, (int)vp->namelen * sizeof (oid));
      newname[vp->namelen] = 1;
      *length = vp->namelen+1;
!   }
!   else {
      *length = vp->namelen+1;
      memmove(newname, name, (*length) * sizeof(oid));
      if (!exact)
--- 139,145 ----
      memmove(newname, vp->name, (int)vp->namelen * sizeof (oid));
      newname[vp->namelen] = 1;
      *length = vp->namelen+1;
!   } else {
      *length = vp->namelen+1;
      memmove(newname, name, (*length) * sizeof(oid));
      if (!exact)
***************
*** 171,176 ****
--- 176,208 ----
  }
  
  #define pagetok(size) ((size) << pageshift)
+ #define  KNLookup(nl_which, buf, s)   (klookup((int) nl[nl_which].n_value, buf, s))
+ 
+ #ifdef freebsd2
+ 
+ /*
+  * FreeBSD 2.x uses sysctl() for most of it's work, so we only need to
+  * find kernel objects for the swap statistics.
+  */
+ 
+ static struct nlist nl[] = {
+ #define NL_SWAPLIST     0
+ 	{ "_swaplist" },
+ #define NL_SWDEVT	1
+ 	{ "_swdevt" },
+ #define NL_NSWAP	2
+ 	{ "_nswap" },
+ #define NL_NSWDEV	3
+ 	{ "_nswdev" },
+ #define NL_DMMAX	4
+ 	{ "_dmmax" },
+ #define NL_MAXMEM	5
+ 	{ "_Maxmem"},
+ 	{ 0 },
+ };
+ 
+ #else /* freebsd2 */
+ 
  #define NL_AVENRUN 0
  #define NL_TOTAL 1
  #define NL_SWDEVT 2
***************
*** 178,185 ****
  #define NL_NSWAPFS 4
  #define NL_NSWAPDEV 5
  #define NL_PHYSMEM 6
- #define  KNLookup(nl_which, buf, s)   (klookup((int) nl[nl_which].n_value, buf, s))
- 
  static struct nlist nl[] = {
  #if !defined(hpux) && !defined(solaris2)
    { "_avenrun"},
--- 210,215 ----
***************
*** 201,206 ****
--- 231,238 ----
    { 0 }
  };
  
+ #endif /* freebsd2 */
+ 
  #define SWAPGETLEFT 0
  #define SWAPGETTOTAL 1
  
***************
*** 209,215 ****
  
  #ifdef USEMEMMIB
  
! int getswap(rettype)
    int rettype;
  {
    int spaceleft=0, spacetotal=0, i, fd;
--- 241,384 ----
  
  #ifdef USEMEMMIB
  
! #ifdef freebsd2
! /*
!  * getswap is based on a program called swapinfo written
!  * by Kevin Lahey <kml@rokkaku.atl.ga.us>.
!  */
! 
! #define	KGET(idx, var)							\
! 	KGET1(idx, &var, sizeof(var))
! 
! #define	KGET1(idx, p, s)						\
! 	KGET2(nl[idx].n_value, p, s)
! 
! #define	KGET2(addr, p, s)						\
! 	if (klookup((int) (addr), p, s) == NULL)			\
! 		return(NULL);
! 
! int
! getswap(rettype)
!   int rettype;
! {
!     char *header;
!     int hlen, nswap, nswdev, dmmax;
!     int i, div, avail, nfree, npfree, used;
!     struct swdevt *sw;
!     long blocksize, *perdev;
!     struct rlist head;
!     u_long ptr;
! #if __FreeBSD_version >= 220000
!     struct rlisthdr swaplist;
!     struct rlist *swapptr;
! #else 
!     struct rlist *swaplist;
! #endif
! 
!     KGET(NL_NSWAP, nswap);
!     KGET(NL_NSWDEV, nswdev);
!     KGET(NL_DMMAX, dmmax);
!     KGET(NL_SWAPLIST, swaplist);
!     if ((sw = malloc(nswdev * sizeof(*sw))) == NULL ||
! 	(perdev = malloc(nswdev * sizeof(*perdev))) == NULL)
! 	err(1, "malloc");
!     KGET1(NL_SWDEVT, &ptr, sizeof ptr);
!     KGET2(ptr, sw, nswdev * sizeof(*sw));
!     
!     /* Count up swap space. */
!     nfree = 0;
!     memset(perdev, 0, nswdev * sizeof(*perdev));
! 
! #if  __FreeBSD_version >= 220000
!     swapptr = swaplist.rlh_list;
!     while (swapptr) {
! #else
!     while (swaplist) {
! #endif
! 	int	top, bottom, next_block;
! 	
! #if  __FreeBSD_version >= 220000
! 	KGET2(swapptr, &head, sizeof(struct rlist));
! #else
! 	KGET2(swaplist, &head, sizeof(struct rlist));
! #endif
! 	
! 	top = head.rl_end;
! 	bottom = head.rl_start;
! 	
! 	nfree += top - bottom + 1;
! 	
! 	/*
! 	 * Swap space is split up among the configured disks.
! 	 *
! 	 * For interleaved swap devices, the first dmmax blocks
! 	 * of swap space some from the first disk, the next dmmax
! 	 * blocks from the next, and so on up to nswap blocks.
! 	 *
! 	 * The list of free space joins adjacent free blocks,
! 	 * ignoring device boundries.  If we want to keep track
! 	 * of this information per device, we'll just have to
! 	 * extract it ourselves.
! 	 */
! 	while (top / dmmax != bottom / dmmax) {
! 	    next_block = ((bottom + dmmax) / dmmax);
! 	    perdev[(bottom / dmmax) % nswdev] +=
! 		next_block * dmmax - bottom;
! 	    bottom = next_block * dmmax;
! 	}
! 	perdev[(bottom / dmmax) % nswdev] +=
! 	    top - bottom + 1;
! 	
! #if __FreeBSD_version >= 220000
! 	swapptr = head.rl_next;
! #else
! 	swaplist = head.rl_next;
! #endif
!     }
!     
!     header = getbsize(&hlen, &blocksize);
!     div = blocksize / 512;
!     avail = npfree = 0;
!     for (i = 0; i < nswdev; i++) {
! 	int xsize, xfree;
! 	
! 	/*
! 	 * Don't report statistics for partitions which have not
! 	 * yet been activated via swapon(8).
! 	 */
! 	if (!(sw[i].sw_flags & SW_FREED))
! 	    continue;
! 	
! 	/* The first dmmax is never allocated to avoid trashing of
! 	 * disklabels
! 	 */
! 	xsize = sw[i].sw_nblks - dmmax;
! 	xfree = perdev[i];
! 	used = xsize - xfree;
! 	npfree++;
! 	avail += xsize;
!     }
!     
!     /*
!      * If only one partition has been set up via swapon(8), we don't
!      * need to bother with totals.
!      */
!     used = avail - nfree;
! 
!     free(sw); free(perdev);
! 
!     switch (rettype) {
!     case SWAPGETLEFT:
! 	return(nfree / div);
!     case SWAPGETTOTAL:
! 	return(avail / div);
!     }
! }
! 
! #else /* freebsd2 */
! 
! int
! getswap(rettype)
    int rettype;
  {
    int spaceleft=0, spacetotal=0, i, fd;
***************
*** 230,244 ****
--- 399,416 ----
    if (KNLookup(NL_SWDEVT,(int *) swdevt, sizeof(struct swdevt)*nswapdev)
        == NULL)
      return(0);
+ 
    for (i=0; i < nswapdev; i++) {
      if (swdevt[i].sw_enable) {
        spacetotal += swdevt[i].sw_nblks;
        spaceleft += (swdevt[i].sw_nfpgs * 4);
      }
    }
+ 
    if (KNLookup(NL_FSWDEVT,(int *) fswdevt, sizeof(struct fswdevt)*nswapfs)
        == NULL)
      return(0);
+ 
    for (i=0; i < nswapfs; i++) {
      if (fswdevt[i].fsw_enable) {
        spacetotal += (fswdevt[i].fsw_limit * 2048);  /* 2048=bytes per page? */
***************
*** 247,252 ****
--- 419,425 ----
        /* 37 = calculated value I know it makes no sense, nor is it accurate */
      }
    }
+ 
    /* this is a real hack.  I need to get the hold info from swapinfo, but
       I can't figure out how to read it out of the kernel directly
       -- Wes */
***************
*** 271,290 ****
        return(spacetotal);
    }
  }
  
! unsigned char *var_extensible_mem(vp, name, length, exact, var_len, write_method)
!     register struct variable *vp;
! /* IN - pointer to variable entry that points here */
!     register oid	*name;
! /* IN/OUT - input name requested, output name found */
!     register int	*length;
! /* IN/OUT - length of input and output oid's */
!     int			exact;
! /* IN - TRUE if an exact match was requested. */
!     int			*var_len;
! /* OUT - length of variable or 0 if function returned. */
!     int			(**write_method)();
! /* OUT - pointer to function to set variable, otherwise 0 */
  {
  
    oid newname[30];
--- 444,459 ----
        return(spacetotal);
    }
  }
+ #endif /* freebsd2 */
  
! unsigned char *
! var_extensible_mem(vp, name, length, exact, var_len, write_method)
!     register struct variable *vp;	/* IN - pointer to variable entry that points here */
!     register oid	*name;		/* IN/OUT - input name requested, output name found */
!     register int	*length;	/* IN/OUT - length of input and output oid's */
!     int			exact;		/* IN - TRUE if an exact match was requested. */
!     int			*var_len;	/* OUT - length of variable or 0 if function returned. */
!     int			(**write_method)(); /* OUT - pointer to function to set variable, otherwise 0 */
  {
  
    oid newname[30];
***************
*** 298,308 ****
  
    if (!checkmib(vp,name,length,exact,var_len,write_method,newname,1))
      return(NULL);
! #ifdef bsdi2
      /* sum memory statistics */
      {
  	size_t size = sizeof(total);
  	static int mib[] = { CTL_VM, VM_TOTAL };
  	if (sysctl(mib, 2, &total, &size, NULL, 0) < 0) return (0);
      }
  #else
--- 467,482 ----
  
    if (!checkmib(vp,name,length,exact,var_len,write_method,newname,1))
      return(NULL);
! 
! #if defined(bsdi2) || defined(freebsd2)
      /* sum memory statistics */
      {
  	size_t size = sizeof(total);
+ #ifdef freebsd2
+ 	static int mib[] = { CTL_VM, VM_METER };
+ #else
  	static int mib[] = { CTL_VM, VM_TOTAL };
+ #endif
  	if (sysctl(mib, 2, &total, &size, NULL, 0) < 0) return (0);
      }
  #else
***************
*** 328,334 ****
        long_ret = minimumswap;
        return((u_char *) (&long_ret));
      case MEMTOTALREAL:
! #ifdef bsdi2
        {	
  	size_t size = sizeof(long_ret);
  	static int mib[] = { CTL_HW, HW_PHYSMEM };
--- 502,508 ----
        long_ret = minimumswap;
        return((u_char *) (&long_ret));
      case MEMTOTALREAL:
! #if defined (bsdi2) || defined (freebsd2)
        {	
  	size_t size = sizeof(long_ret);
  	static int mib[] = { CTL_HW, HW_PHYSMEM };
***************
*** 345,352 ****
      case MEMUSEDREAL:
        long_ret = pagetok((int) total.t_arm);
        return((u_char *) (&long_ret));
      case MEMTOTALSWAPTXT:
! #ifndef bsdi2
        long_ret = pagetok(total.t_vmtxt);
  #endif
        return((u_char *) (&long_ret));
--- 519,533 ----
      case MEMUSEDREAL:
        long_ret = pagetok((int) total.t_arm);
        return((u_char *) (&long_ret));
+ #ifdef freebsd2
      case MEMTOTALSWAPTXT:
!     case MEMUSEDSWAPTXT:
!     case MEMTOTALREALTXT:
!     case MEMUSEDREALTXT:
!       return(NULL);
! #else
!     case MEMTOTALSWAPTXT:
! #ifndef bsdi2 
        long_ret = pagetok(total.t_vmtxt);
  #endif
        return((u_char *) (&long_ret));
***************
*** 365,370 ****
--- 546,552 ----
        long_ret = pagetok(total.t_armtxt);
  #endif
        return((u_char *) (&long_ret));
+ #endif /* freebsd2 */
      case MEMTOTALFREE:
        long_ret = pagetok(total.t_free);
        return((u_char *) (&long_ret));
***************
*** 382,396 ****
        return((u_char *) (errmsg));
    }
  }
! 
! #endif
  
  static int numdisks;
  struct diskpart disks[MAXDISKS];
  
  #if defined(USEDISKMIB)
  
! unsigned char *var_extensible_disk(vp, name, length, exact, var_len, write_method)
      register struct variable *vp;
  /* IN - pointer to variable entry that points here */
      register oid	*name;
--- 564,578 ----
        return((u_char *) (errmsg));
    }
  }
! #endif /* USEMEMMIB */
  
  static int numdisks;
  struct diskpart disks[MAXDISKS];
  
  #if defined(USEDISKMIB)
  
! unsigned char *
! var_extensible_disk(vp, name, length, exact, var_len, write_method)
      register struct variable *vp;
  /* IN - pointer to variable entry that points here */
      register oid	*name;
***************
*** 415,430 ****
  
  #if defined(HAVE_STATVFS) || defined(HAVE_STATFS)
    struct statvfs vfs;
! #else
! #if HAVE_FSTAB_H
    int file;
    union {
       struct fs iu_fs;
       char dummy[SBSIZE];
    } sb;
  #define filesys sb.iu_fs
! #endif
! #endif
    
    if (!checkmib(vp,name,length,exact,var_len,write_method,newname,numdisks))
      return(NULL);
--- 597,612 ----
  
  #if defined(HAVE_STATVFS) || defined(HAVE_STATFS)
    struct statvfs vfs;
! #elif HAVE_SYS_MOUNT_H
!   struct statfs vfs;
! #elif HAVE_FSTAB_H
    int file;
    union {
       struct fs iu_fs;
       char dummy[SBSIZE];
    } sb;
  #define filesys sb.iu_fs
! #endif /* HAVE_SYS_STATVFS_H */
    
    if (!checkmib(vp,name,length,exact,var_len,write_method,newname,numdisks))
      return(NULL);
***************
*** 481,488 ****
        *var_len = strlen(errmsg);
        return((u_char *) (errmsg));
    }
! #else
! #if HAVE_FSTAB_H
    /* read the disk information */
    if ((file = open(disks[disknum].device,0)) < 0) {
      fprintf(stderr,"Couldn't open device %s\n",disks[disknum].device);
--- 663,669 ----
        *var_len = strlen(errmsg);
        return((u_char *) (errmsg));
    }
! #elif HAVE_FSTAB_H
    /* read the disk information */
    if ((file = open(disks[disknum].device,0)) < 0) {
      fprintf(stderr,"Couldn't open device %s\n",disks[disknum].device);
***************
*** 536,549 ****
  }
  
  /*#endif*/
! #endif
  
  #define NOERR 0
  #define LOCKDBROKE 1
  #define OPENERR 2
  
  /*
! static int locktimeouttest;
  
  int lockd_timeout()
  {
--- 717,731 ----
  }
  
  /*#endif*/
! /*#endif*/
  
  #define NOERR 0
  #define LOCKDBROKE 1
  #define OPENERR 2
  
  /*
! static int
! locktimeouttest;
  
  int lockd_timeout()
  {
***************
*** 552,558 ****
  */
  
  #ifdef USELOCKDMIB
! long lockd_test(msg)
    char *msg;
  {
  
--- 734,741 ----
  */
  
  #ifdef USELOCKDMIB
! long
! lockd_test(msg)
    char *msg;
  {
  
***************
*** 590,596 ****
  }
  
  
! unsigned char *var_extensible_lockd_test(vp, name, length, exact, var_len, write_method)
      register struct variable *vp;
  /* IN - pointer to variable entry that points here */
      register oid	*name;
--- 773,780 ----
  }
  
  
! unsigned char *
! var_extensible_lockd_test(vp, name, length, exact, var_len, write_method)
      register struct variable *vp;
  /* IN - pointer to variable entry that points here */
      register oid	*name;
***************
*** 636,654 ****
  #endif
  #ifdef USELOADAVEMIB
  
! unsigned char *var_extensible_loadave(vp, name, length, exact, var_len, write_method)
!     register struct variable *vp;
! /* IN - pointer to variable entry that points here */
!     register oid	*name;
! /* IN/OUT - input name requested, output name found */
!     register int	*length;
! /* IN/OUT - length of input and output oid's */
!     int			exact;
! /* IN - TRUE if an exact match was requested. */
!     int			*var_len;
! /* OUT - length of variable or 0 if function returned. */
!     int			(**write_method)();
! /* OUT - pointer to function to set variable, otherwise 0 */
  {
  
    oid newname[30];
--- 820,833 ----
  #endif
  #ifdef USELOADAVEMIB
  
! unsigned char *
! var_extensible_loadave(vp, name, length, exact, var_len, write_method)
!     register struct variable *vp;	/* IN - pointer to variable entry that points here */
!     register oid	*name;		/* IN/OUT - input name requested, output name found */
!     register int	*length;	/* IN/OUT - length of input and output oid's */
!     int			exact;		/* IN - TRUE if an exact match was requested. */
!     int			*var_len;	/* OUT - length of variable or 0 if function returned. */
!     int			(**write_method)(); /* OUT - pointer to function to set variable, otherwise 0 */
  {
  
    oid newname[30];
***************
*** 755,761 ****
    
  #ifdef USEERRORMIB
  
! unsigned char *var_extensible_errors(vp, name, length, exact, var_len, write_method)
      register struct variable *vp;
  /* IN - pointer to variable entry that points here */
      register oid	*name;
--- 934,941 ----
    
  #ifdef USEERRORMIB
  
! unsigned char *
! var_extensible_errors(vp, name, length, exact, var_len, write_method)
      register struct variable *vp;
  /* IN - pointer to variable entry that points here */
      register oid	*name;
***************
*** 885,891 ****
    return compare((*ap)->miboid,(*ap)->miblen,(*bp)->miboid,(*bp)->miblen);
  }
  
! RETSIGTYPE update_config(a)
  int a;
  {
    extern struct subtree *subtrees;
--- 1065,1072 ----
    return compare((*ap)->miboid,(*ap)->miblen,(*bp)->miboid,(*bp)->miblen);
  }
  
! RETSIGTYPE
! update_config(a)
  int a;
  {
    extern struct subtree *subtrees;
***************
*** 1013,1019 ****
    }
  
  #ifdef USEMEMMIB
! #ifndef bsdi2
    if (KNLookup(NL_NSWAPDEV,(int *) &nswapdev, sizeof(nswapdev))
        == NULL)
      return;
--- 1194,1200 ----
    }
  
  #ifdef USEMEMMIB
! #if !defined(bsdi2) && !defined(freebsd2)
    if (KNLookup(NL_NSWAPDEV,(int *) &nswapdev, sizeof(nswapdev))
        == NULL)
      return;
***************
*** 1021,1027 ****
--- 1202,1216 ----
        == NULL)
      return;
  #endif
+ #ifdef freebsd2
+ #ifdef PAGE_SHIFT
+   pagesize = 1 << PAGE_SHIFT;
+ #else
    pagesize = 1 << PGSHIFT;
+ #endif
+ #else
+   pagesize = 1 << PGSHIFT;
+ #endif
    pageshift = 0;
    while (pagesize > 1) {
      pageshift++;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3360F09C>