home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Unix / gopher1.12 / gopherd / kernutils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-21  |  2.1 KB  |  96 lines

  1. /********************************************************************
  2.  * $Author: lindner $
  3.  * $Revision: 1.1 $
  4.  * $Date: 1992/12/21 20:46:12 $
  5.  * $Source: /home/mudhoney/GopherSrc/release1.11/gopherd/RCS/kernutils.c,v $
  6.  * $State: Exp $
  7.  *
  8.  * Paul Lindner, University of Minnesota CIS.
  9.  *
  10.  * Copyright 1991, 1992 by the Regents of the University of Minnesota
  11.  * see the file "Copyright" in the distribution for conditions of use.
  12.  *********************************************************************
  13.  * MODULE: kernutils.c
  14.  * Routines to implement kernel specific stuff
  15.  *********************************************************************
  16.  * Revision History:
  17.  * $Log: kernutils.c,v $
  18.  * Revision 1.1  1992/12/21  20:46:12  lindner
  19.  * Initial revision
  20.  *
  21.  *
  22.  *********************************************************************/
  23.  
  24.  
  25. #include "gopherd.h"
  26.  
  27. #define LOADSYMBOL "_avenrun"    /* should work with most Unix flavors */
  28.  
  29. #define WHICHLOAD  2             /* 0 ==  1 min average           */
  30.                                  /* 1 ==  5 min average           */
  31.                                  /* 2 == 15 min average           */
  32.  
  33. #ifndef LOADRESTRICT
  34.  
  35. double maxload = 0;
  36.  
  37. int LoadTooHigh() 
  38. {
  39.   return(0);
  40. }
  41.  
  42. #else /* LOADRESTRICT */
  43.  
  44. int LoadTooHigh()
  45. {
  46.   int status;
  47.  
  48.   status = getload();
  49.   if(DEBUG)
  50.     printf("getload returns %d\n",status);
  51.   return(status);
  52.  
  53. }
  54.  
  55. #ifndef MAXLOAD
  56. #define MAXLOAD 10.0
  57. #endif
  58. double atof();
  59. double maxload = MAXLOAD;
  60. double sysload = 0.0;
  61. #include <nlist.h>
  62. #include <kvm.h>
  63. #define X_AVENRUN 0
  64. long avenrun[3];
  65. kvm_t * kd;
  66. struct nlist nl[] = { {LOADSYMBOL}, {""}, };
  67.  
  68. int getload()
  69. {
  70.   if ((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL)) == NULL) 
  71.     return(-1);
  72.   if (kvm_nlist(kd, nl) != 0) 
  73.     return(-1);
  74.   if(nl[X_AVENRUN].n_type == 0) 
  75.     return(-1);
  76.   if(kvm_read(kd,nl[X_AVENRUN].n_value,avenrun,sizeof(avenrun)) 
  77.      != sizeof(avenrun)) 
  78.     return(-1);
  79.   if((sysload = (((double) avenrun[WHICHLOAD]) / FSCALE)) > maxload) {
  80.     if(DEBUG)
  81.       printf("System maxload %f exceeded (currently %f)\n",maxload,sysload);
  82.     return(1);
  83.   }
  84.   return(0);
  85. }
  86. #endif /* LOADRESTRICT */     
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.