static u_char * var_extensible_mem(struct variable *vp, oid * name, size_t * length, int exact, size_t * var_len, WriteMethod ** write_method) { static long long_ret; /* * Initialize the return value to 0 */ long_ret = 0; if (header_generic(vp, name, length, exact, var_len, write_method)) return (NULL); switch (vp->magic) { case MIBINDEX: long_ret = 0; return ((u_char *) (&long_ret)); case ERRORNAME: /* dummy name */ sprintf(errmsg, "swap"); *var_len = strlen(errmsg); return ((u_char *) (errmsg)); case MEMTOTALSWAP: long_ret = getTotalSwap() * (getpagesize() / 1024); return ((u_char *) (&long_ret)); case MEMAVAILSWAP: long_ret = getFreeSwap() * (getpagesize() / 1024); return ((u_char *) (&long_ret)); case MEMSWAPMINIMUM: long_ret = minimumswap; return ((u_char *) (&long_ret)); case MEMTOTALREAL: long_ret = getTotalReal() * (getpagesize() / 1024); return ((u_char *) (&long_ret)); case MEMAVAILREAL: long_ret = getFreeReal() * (getpagesize() / 1024); return ((u_char *) (&long_ret)); case MEMTOTALFREE: long_ret = getTotalFree() * (getpagesize() / 1024); return ((u_char *) (&long_ret)); case ERRORFLAG: long_ret = getTotalFree() * (getpagesize() / 1024); long_ret = (long_ret > minimumswap) ? 0 : 1; return ((u_char *) (&long_ret)); case ERRORMSG: long_ret = getTotalFree() * (getpagesize() / 1024); if ((long_ret > minimumswap) ? 0 : 1) sprintf(errmsg, "Running out of swap space (%ld)", long_ret); else errmsg[0] = 0; *var_len = strlen(errmsg); return ((u_char *) (errmsg)); } return (NULL); }
static u_char * var_extensible_mem(struct variable *vp, oid * name, size_t * length, int exact, size_t * var_len, WriteMethod ** write_method) { static long long_ret; /* * Initialize the return value to 0 */ long_ret = 0; if (header_generic(vp, name, length, exact, var_len, write_method)) return (NULL); switch (vp->magic) { case MIBINDEX: long_ret = 0; return ((u_char *) (&long_ret)); case ERRORNAME: /* dummy name */ sprintf(errmsg, "swap"); *var_len = strlen(errmsg); return ((u_char *) (errmsg)); case MEMTOTALSWAP: long_ret = getTotalSwap() * (getpagesize() / 1024); return ((u_char *) (&long_ret)); case MEMAVAILSWAP: long_ret = getFreeSwap() * (getpagesize() / 1024); return ((u_char *) (&long_ret)); case MEMSWAPMINIMUM: long_ret = minimumswap; return ((u_char *) (&long_ret)); case MEMTOTALREAL: #ifdef _SC_PHYS_PAGES long_ret = sysconf(_SC_PHYS_PAGES) * (getpagesize()/1024); #else ksp1 = kstat_lookup(kstat_fd, "unix", 0, "system_pages"); kstat_read(kstat_fd, ksp1, 0); kn = kstat_data_lookup(ksp1, "physmem"); long_ret = kn->value.ul * (getpagesize() / 1024); #endif return ((u_char *) (&long_ret)); case MEMAVAILREAL: #ifdef _SC_AVPHYS_PAGES long_ret = sysconf(_SC_AVPHYS_PAGES) * (getpagesize()/1024); #else long_ret = (getTotalFree() - getFreeSwap()) * (getpagesize() / 1024); #endif return ((u_char *) (&long_ret)); case MEMTOTALFREE: long_ret = getTotalFree() * (getpagesize() / 1024); return ((u_char *) (&long_ret)); case ERRORFLAG: long_ret = getTotalFree() * (getpagesize() / 1024); long_ret = (long_ret > minimumswap) ? 0 : 1; return ((u_char *) (&long_ret)); case ERRORMSG: long_ret = getTotalFree() * (getpagesize() / 1024); if ((long_ret > minimumswap) ? 0 : 1) sprintf(errmsg, "Running out of swap space (%ld)", long_ret); else errmsg[0] = 0; *var_len = strlen(errmsg); return ((u_char *) (errmsg)); } return (NULL); }