http://www.usr.com/support/gpl/USR9107_release1.1.tar.gz
[bcm963xx.git] / userapps / opensource / net-snmp / agent / mibgroup / ucd-snmp / memory.c
1 #include <net-snmp/net-snmp-config.h>
2
3 #if HAVE_STDLIB_H
4 #include <stdlib.h>
5 #endif
6 #if HAVE_UNISTD_H
7 #include <unistd.h>
8 #endif
9 #if HAVE_FCNTL_H
10 #include <fcntl.h>
11 #endif
12 #include <ctype.h>
13 #include <signal.h>
14 #if HAVE_MACHINE_PARAM_H
15 #include <machine/param.h>
16 #endif
17 #if HAVE_SYS_VMMETER_H
18 #if !defined(bsdi2) && !defined(netbsd1)
19 #include <sys/vmmeter.h>
20 #endif
21 #endif
22 #if HAVE_SYS_CONF_H
23 #include <sys/conf.h>
24 #endif
25 #if HAVE_ASM_PAGE_H
26 #include <asm/page.h>
27 #endif
28 #if HAVE_SYS_SWAP_H
29 #include <sys/swap.h>
30 #endif
31 #if HAVE_SYS_FS_H
32 #include <sys/fs.h>
33 #else
34 #if HAVE_UFS_FS_H
35 #include <ufs/fs.h>
36 #else
37 #ifdef HAVE_SYS_STAT_H
38 #include <sys/stat.h>
39 #endif
40 #ifdef HAVE_SYS_VNODE_H
41 #include <sys/vnode.h>
42 #endif
43 #ifdef HAVE_UFS_UFS_QUOTA_H
44 #include <ufs/ufs/quota.h>
45 #endif
46 #ifdef HAVE_UFS_UFS_INODE_H
47 #include <ufs/ufs/inode.h>
48 #endif
49 #ifdef HAVE_SYS_PARAM_H
50 #include <sys/param.h>
51 #endif
52 #if HAVE_UFS_FFS_FS_H
53 #include <ufs/ffs/fs.h>
54 #endif
55 #endif
56 #endif
57 #if HAVE_MTAB_H
58 #include <mtab.h>
59 #endif
60 #include <sys/stat.h>
61 #include <errno.h>
62 #if HAVE_FSTAB_H
63 #include <fstab.h>
64 #endif
65 #if HAVE_SYS_STATVFS_H
66 #include <sys/statvfs.h>
67 #endif
68 #if HAVE_SYS_VFS_H
69 #include <sys/vfs.h>
70 #endif
71 #if (!defined(HAVE_STATVFS)) && defined(HAVE_STATFS)
72 #if HAVE_SYS_PARAM_H
73 #include <sys/param.h>
74 #endif
75 #if HAVE_SYS_MOUNT_H
76 #include <sys/mount.h>
77 #endif
78 #if HAVE_SYS_SYSCTL_H
79 #include <sys/sysctl.h>
80 #endif
81 #define statvfs statfs
82 #endif
83 #if HAVE_VM_SWAP_PAGER_H
84 #include <vm/swap_pager.h>
85 #endif
86 #if HAVE_SYS_FIXPOINT_H
87 #include <sys/fixpoint.h>
88 #endif
89 #if HAVE_MALLOC_H
90 #include <malloc.h>
91 #endif
92 #if HAVE_STRING_H
93 #include <string.h>
94 #endif
95 #if TIME_WITH_SYS_TIME
96 # include <sys/time.h>
97 # include <time.h>
98 #else
99 # if HAVE_SYS_TIME_H
100 #  include <sys/time.h>
101 # else
102 #  include <time.h>
103 # endif
104 #endif
105 #if defined(hpux10) || defined(hpux11)
106 #include <sys/pstat.h>
107 #endif
108
109 #include <net-snmp/net-snmp-includes.h>
110 #include <net-snmp/agent/net-snmp-agent-includes.h>
111 #include <net-snmp/agent/auto_nlist.h>
112
113 #include "mibdefs.h"
114 #include "struct.h"
115 #include "util_funcs.h"
116 #include "memory.h"
117
118 int             minimumswap;
119 #ifndef linux
120 static int      pageshift;      /* log base 2 of the pagesize */
121 #endif
122
123 #ifndef bsdi2
124 #ifdef NSWAPDEV_SYMBOL
125 int nswapdev=10;            /* taken from <machine/space.h> */
126 #endif
127 #ifdef NSWAPFS_SYMBOL
128 int nswapfs=10;            /* taken from <machine/space.h> */
129 #endif
130 #endif      /* !bsdi2 */
131
132 #define DEFAULTMINIMUMSWAP 16000        /* kilobytes */
133
134 static FindVarMethod var_extensible_mem;
135
136 void
137 init_memory(void)
138 {
139 #ifndef linux
140     int             pagesize;
141 #ifdef PHYSMEM_SYMBOL
142     auto_nlist(PHYSMEM_SYMBOL, 0, 0);
143 #endif
144 #ifdef TOTAL_MEMORY_SYMBOL
145     auto_nlist(TOTAL_MEMORY_SYMBOL, 0, 0);
146 #endif
147 #ifdef MBSTAT_SYMBOL
148     auto_nlist(MBSTAT_SYMBOL, 0, 0);
149 #endif
150 #ifdef SWDEVT_SYMBOL
151     auto_nlist(SWDEVT_SYMBOL, 0, 0);
152 #endif
153 #ifdef FSWDEVT_SYMBOL
154     auto_nlist(FSWDEVT_SYMBOL, 0, 0);
155 #endif
156 #ifdef NSWAPFS_SYMBOL
157     auto_nlist(NSWAPFS_SYMBOL, 0, 0);
158 #endif
159 #ifdef NSWAPDEV_SYMBOL
160     auto_nlist(NSWAPDEV_SYMBOL, 0, 0);
161 #endif
162
163 #ifndef bsdi2
164 #ifdef NSWAPDEV_SYMBOL
165     if (auto_nlist(NSWAPDEV_SYMBOL, (char *) &nswapdev, sizeof(nswapdev))
166         == 0)
167         return;
168 #endif
169 #ifdef NSWAPFS_SYMBOL
170     if (auto_nlist(NSWAPFS_SYMBOL, (char *) &nswapfs, sizeof(nswapfs)) ==
171         0)
172         return;
173 #endif
174 #endif
175     pagesize = 1 << PGSHIFT;
176     pageshift = 0;
177     while (pagesize > 1) {
178         pageshift++;
179         pagesize >>= 1;
180     }
181     pageshift -= 10;
182 #endif
183     {
184         struct variable2 extensible_mem_variables[] = {
185             {MIBINDEX, ASN_INTEGER, RONLY, var_extensible_mem, 1,
186              {MIBINDEX}},
187             {ERRORNAME, ASN_OCTET_STR, RONLY, var_extensible_mem, 1,
188              {ERRORNAME}},
189             {MEMTOTALSWAP, ASN_INTEGER, RONLY, var_extensible_mem, 1,
190              {MEMTOTALSWAP}},
191             {MEMAVAILSWAP, ASN_INTEGER, RONLY, var_extensible_mem, 1,
192              {MEMAVAILSWAP}},
193             {MEMTOTALREAL, ASN_INTEGER, RONLY, var_extensible_mem, 1,
194              {MEMTOTALREAL}},
195             {MEMAVAILREAL, ASN_INTEGER, RONLY, var_extensible_mem, 1,
196              {MEMAVAILREAL}},
197             {MEMTOTALSWAPTXT, ASN_INTEGER, RONLY, var_extensible_mem, 1,
198              {MEMTOTALSWAPTXT}},
199             {MEMUSEDSWAPTXT, ASN_INTEGER, RONLY, var_extensible_mem, 1,
200              {MEMUSEDSWAPTXT}},
201             {MEMTOTALREALTXT, ASN_INTEGER, RONLY, var_extensible_mem, 1,
202              {MEMTOTALREALTXT}},
203             {MEMUSEDREALTXT, ASN_INTEGER, RONLY, var_extensible_mem, 1,
204              {MEMUSEDREALTXT}},
205             {MEMTOTALFREE, ASN_INTEGER, RONLY, var_extensible_mem, 1,
206              {MEMTOTALFREE}},
207             {MEMSWAPMINIMUM, ASN_INTEGER, RONLY, var_extensible_mem, 1,
208              {MEMSWAPMINIMUM}},
209             {MEMSHARED, ASN_INTEGER, RONLY, var_extensible_mem, 1,
210              {MEMSHARED}},
211             {MEMBUFFER, ASN_INTEGER, RONLY, var_extensible_mem, 1,
212              {MEMBUFFER}},
213             {MEMCACHED, ASN_INTEGER, RONLY, var_extensible_mem, 1,
214              {MEMCACHED}},
215             {ERRORFLAG, ASN_INTEGER, RONLY, var_extensible_mem, 1,
216              {ERRORFLAG}},
217             {ERRORMSG, ASN_OCTET_STR, RONLY, var_extensible_mem, 1,
218              {ERRORMSG}}
219         };
220
221         /*
222          * Define the OID pointer to the top of the mib tree that we're
223          * registering underneath 
224          */
225         oid             mem_variables_oid[] = { UCDAVIS_MIB, MEMMIBNUM };
226
227         /*
228          * register ourselves with the agent to handle our mib tree 
229          */
230         REGISTER_MIB("ucd-snmp/memory", extensible_mem_variables,
231                      variable2, mem_variables_oid);
232
233         snmpd_register_config_handler("swap", memory_parse_config,
234                                       memory_free_config, "min-avail");
235     }
236 }
237
238 void
239 memory_parse_config(const char *token, char *cptr)
240 {
241     minimumswap = atoi(cptr);
242 }
243
244 void
245 memory_free_config(void)
246 {
247     minimumswap = DEFAULTMINIMUMSWAP;
248 }
249
250 #ifdef linux
251 enum meminfo_row { meminfo_main = 0,
252     meminfo_swap
253 };
254
255 enum meminfo_col { meminfo_total = 0, meminfo_used, meminfo_free,
256     meminfo_shared, meminfo_buffers, meminfo_cached
257 };
258 #define MEMINFO_FILE "/proc/meminfo"
259
260 static char     buf[300];
261
262 /*
263  * This macro opens FILE only if necessary and seeks to 0 so that successive
264  * calls to the functions are more efficient.  It also reads the current
265  * contents of the file into the global buf.
266  */
267 #define FILE_TO_BUF(FILE) {                                     \
268     static int n, fd = -1;                                      \
269     if (fd == -1 && (fd = open(FILE, O_RDONLY)) == -1) {        \
270         return 0;                                               \
271     }                                                           \
272     lseek(fd, 0L, SEEK_SET);                                    \
273     if ((n = read(fd, buf, sizeof buf - 1)) < 0) {              \
274         close(fd);                                              \
275         fd = -1;                                                \
276         return 0;                                               \
277     }                                                           \
278     buf[n] = '\0';                                              \
279 }
280
281 #define MAX_ROW 3               /* these are a little liberal for flexibility */
282 #define MAX_COL 7
283
284 unsigned      **
285 meminfo(void)
286 {
287     static unsigned *row[MAX_ROW + 1];  /* row pointers */
288     static unsigned num[MAX_ROW * MAX_COL];     /* number storage */
289     char           *p;
290     int             i, j, k, l;
291     unsigned long   m;
292
293     FILE_TO_BUF(MEMINFO_FILE)
294         if (!row[0])            /* init ptrs 1st time through */
295         for (i = 0; i < MAX_ROW; i++)   /* std column major order: */
296             row[i] = num + MAX_COL * i; /* A[i][j] = A + COLS*i + j */
297     p = buf;
298     for (i = 0; i < MAX_ROW; i++)       /* zero unassigned fields */
299         for (j = 0; j < MAX_COL; j++)
300             row[i][j] = 0;
301     for (i = 0; i < MAX_ROW && *p; i++) {       /* loop over rows */
302         while (*p && !isdigit(*p))
303             p++;                /* skip chars until a digit */
304         for (j = 0; j < MAX_COL && *p; j++) {   /* scanf column-by-column */
305             l = sscanf(p, "%lu%n", &m, &k);
306             m /= 1024;
307             if (0x7fffffff < m) {
308                 *(row[i] + j) = 0x7fffffff;
309             } else {
310                 *(row[i] + j) = (unsigned) m;
311             }
312             p += k;             /* step over used buffer */
313             if (*p == '\n' || l < 1)    /* end of line/buffer */
314                 break;
315         }
316     }
317     /*
318      * row[i+1] = NULL;     terminate the row list, currently unnecessary 
319      */
320     return row;                 /* NULL return ==> error */
321 }
322
323 unsigned
324 memory(int iindex)
325 {
326     unsigned      **mem = meminfo();
327     if (mem != NULL)
328         return mem[meminfo_main][iindex];
329     else
330         return -1;
331 }
332
333 unsigned
334 memswap(int iindex)
335 {
336     unsigned      **mem = meminfo();
337     if (mem != NULL)
338         return mem[meminfo_swap][iindex];
339     else
340         return -1;
341 }
342 #else
343 #define pagetok(size) ((size) << pageshift)
344 #endif
345
346 #define SWAPGETLEFT 0
347 #define SWAPGETTOTAL 1
348
349 static long
350 getswap(int rettype)
351 {
352     long            spaceleft = 0, spacetotal = 0;
353
354 #if defined(linux)
355     spaceleft = memswap(meminfo_free);
356     spacetotal = memswap(meminfo_total);
357 #elif defined(bsdi2)
358     struct swapstats swapst;
359     size_t          size = sizeof(swapst);
360     static int      mib[] = { CTL_VM, VM_SWAPSTATS };
361     if (sysctl(mib, 2, &swapst, &size, NULL, 0) < 0)
362         return (0);
363     spaceleft = swapst.swap_free / 2;
364     spacetotal = swapst.swap_total / 2;
365 #elif defined (hpux10) || defined(hpux11)
366     struct pst_swapinfo pst_buf;
367     int ndx = 0;
368     long pgs, pgs_free;
369   
370     while (pstat_getswap(&pst_buf, sizeof(struct pst_swapinfo), 1, ndx) > 0) {
371         if (pst_buf.pss_flags & SW_BLOCK) {
372             pgs = pst_buf.pss_nblksenabled;
373             pgs_free = pst_buf.pss_nblksavail;
374         }
375         else if (pst_buf.pss_flags & SW_FS) {
376             pgs = pst_buf.pss_limit;
377             pgs_free = pgs - pst_buf.pss_allocated - pst_buf.pss_reserve;
378             /*
379              * the following calculation is done this way to avoid integer overflow!
380              * pss_swapchunk is either 512 or a multiple of 1024!
381              */
382             if (pst_buf.pss_swapchunk == 512) {
383                 pgs_free /= 2;
384                 pgs /= 2;
385             } else {
386                 pgs_free *= (pst_buf.pss_swapchunk / 1024);
387                 pgs *= (pst_buf.pss_swapchunk / 1024);
388             }
389         }
390         else {
391             pgs = pgs_free = 0;
392         }
393         spaceleft += pgs_free;
394         spacetotal += pgs;
395         ndx = pst_buf.pss_idx + 1;
396     }
397 #else /* !linux && !bsdi2 && !hpux10 && !hpux11 */
398     struct swdevt   swdevt[100];
399     struct fswdevt  fswdevt[100];
400     FILE           *file;
401     struct extensible ex;
402     int             i, fd;
403     char           *cp;
404
405     if (auto_nlist
406         (SWDEVT_SYMBOL, (char *) swdevt, sizeof(struct swdevt) * nswapdev)
407         == 0)
408         return (0);
409     DEBUGMSGTL(("ucd-snmp/memory", "%d block swap devices: \n", nswapdev));
410     for (i = 0; i < nswapdev; i++) {
411         DEBUGMSGTL(("ucd-snmp/memory", "swdevt[%d]: %d\n", i,
412                     swdevt[i].sw_enable));
413         if (swdevt[i].sw_enable)
414         {
415 #ifdef STRUCT_SWDEVT_HAS_SW_NBLKSENABLED
416             DEBUGMSGTL(("ucd-snmp/memory",
417                         "  swdevt.sw_nblksenabled:     %d\n",
418                         swdevt[i].sw_nblksenabled));
419             spacetotal += swdevt[i].sw_nblksenabled;
420 #else
421             DEBUGMSGTL(("ucd-snmp/memory", "  swdevt.sw_nblks:     %d\n",
422                         swdevt[i].sw_nblks));
423             spacetotal += swdevt[i].sw_nblks;
424 #endif
425             DEBUGMSGTL(("ucd-snmp/memory", "  swdevt.sw_nfpgs:     %d\n",
426                         swdevt[i].sw_nfpgs));
427             spaceleft += (swdevt[i].sw_nfpgs * 4);
428         }
429     }
430     if (auto_nlist
431         (FSWDEVT_SYMBOL, (char *) fswdevt,
432          sizeof(struct fswdevt) * nswapfs)
433         == 0)
434         return (0);
435     DEBUGMSGTL(("ucd-snmp/memory", "%d fs swap devices: \n", nswapfs));
436     for (i = 0; i < nswapfs; i++) {
437         DEBUGMSGTL(("ucd-snmp/memory", "fswdevt[%d]: %d\n", i,
438                     fswdevt[i].fsw_enable));
439         if (fswdevt[i].fsw_enable)
440         {
441             spacetotal += (fswdevt[i].fsw_limit * 2048);        /* 2048=bytes per page? */
442             spaceleft += (fswdevt[i].fsw_limit * 2048 -
443                           ((fswdevt[i].fsw_allocated -
444                             fswdevt[i].fsw_min) * 37));
445             DEBUGMSGTL(("ucd-snmp/memory",
446                         "  fswdevt[i].fsw_limit:     %d\n",
447                         fswdevt[i].fsw_limit));
448             DEBUGMSGTL(("ucd-snmp/memory",
449                         "  fswdevt[i].fsw_allocated: %d\n",
450                         fswdevt[i].fsw_allocated));
451             DEBUGMSGTL(("ucd-snmp/memory",
452                         "  fswdevt[i].fsw_min:       %d\n",
453                         fswdevt[i].fsw_min));
454             DEBUGMSGTL(("ucd-snmp/memory",
455                         "  fswdevt[i].fsw_reserve:   %d\n",
456                         fswdevt[i].fsw_reserve));
457             /*
458              * 37 = calculated value I know it makes no sense, nor is it accurate 
459              */
460         }
461     }
462     /*
463      * this is a real hack.  I need to get the hold info from swapinfo, but
464      * I can't figure out how to read it out of the kernel directly
465      * -- Wes 
466      */
467     strcpy(ex.command, "/etc/swapinfo -h");
468     if ((fd = get_exec_output(&ex)) != -1) {
469         file = fdopen(fd, "r");
470         for (i = 1;
471              i <= 2 && fgets(ex.output, sizeof(ex.output), file) != NULL;
472              i++);
473         if (fgets(ex.output, sizeof(ex.output), file) != NULL) {
474             cp = skip_white(ex.output); /* not there should be any */
475             cp = skip_not_white(cp);    /* skip over "reserve" */
476             cp = skip_white(cp);
477             cp = skip_not_white(cp);    /* avail swap, a '-' in most cases */
478             cp = skip_white(cp);
479             spaceleft -= atoi(cp);      /* reserved swap */
480         }
481         fclose(file);
482         wait_on_exec(&ex);
483     } else {
484         return (0);
485     }
486 #endif                          /* !linux && !bsdi2 && !hpux10 && !hpux11 */
487
488     switch (rettype) {
489     case SWAPGETLEFT:
490         return (spaceleft);
491     case SWAPGETTOTAL:
492         return (spacetotal);
493     }
494     return 0;
495 }
496
497 static
498 unsigned char  *
499 var_extensible_mem(struct variable *vp,
500                    oid * name,
501                    size_t * length,
502                    int exact,
503                    size_t * var_len, WriteMethod ** write_method)
504 {
505
506     static long     long_ret;
507     static char     errmsg[300];
508 #if !defined(linux)
509 #if defined(hpux10) || defined(hpux11)
510     struct pst_dynamic pst_buf;
511 #elif defined(TOTAL_MEMORY_SYMBOL) || defined(USE_SYSCTL_VM)
512     struct vmtotal total;
513 #endif
514 #endif
515
516     long_ret = 0;               /* set to 0 as default */
517
518     if (header_generic(vp, name, length, exact, var_len, write_method))
519         return (NULL);
520
521 #if !defined(linux)
522 #if defined(hpux10) || defined(hpux11)
523     if (pstat_getdynamic(&pst_buf, sizeof(struct pst_dynamic), 1, 0) < 0)
524         return NULL;
525 #elif defined(USE_SYSCTL_VM)
526     /*
527      * sum memory statistics 
528      */
529     {
530         size_t          size = sizeof(total);
531         static int      mib[] = { CTL_VM, VM_TOTAL };
532         if (sysctl(mib, 2, &total, &size, NULL, 0) < 0)
533             return NULL;
534     }
535 #elif defined(TOTAL_MEMORY_SYMBOL)
536     if (auto_nlist(TOTAL_MEMORY_SYMBOL, (char *) &total, sizeof(total)) ==
537         0)
538         return NULL;
539 #endif
540 #endif                          /* !linux */
541
542     switch (vp->magic) {
543     case MIBINDEX:
544         long_ret = 0;
545         return ((u_char *) (&long_ret));
546     case ERRORNAME:            /* dummy name */
547         sprintf(errmsg, "swap");
548         *var_len = strlen(errmsg);
549         return ((u_char *) (errmsg));
550     case MEMTOTALSWAP:
551         long_ret = getswap(SWAPGETTOTAL);
552         return ((u_char *) (&long_ret));
553     case MEMAVAILSWAP:
554         long_ret = getswap(SWAPGETLEFT);
555         return ((u_char *) (&long_ret));
556     case MEMSWAPMINIMUM:
557         long_ret = minimumswap;
558         return ((u_char *) (&long_ret));
559     case MEMTOTALREAL:
560 #if defined(USE_SYSCTL)
561         {
562             size_t          size = sizeof(long_ret);
563             static int      mib[] = { CTL_HW, HW_PHYSMEM };
564             if (sysctl(mib, 2, &long_ret, &size, NULL, 0) < 0)
565                 return NULL;
566             long_ret = long_ret / 1024;
567         }
568 #elif defined(hpux10) || defined(hpux11)
569         {
570             struct pst_static pst_buf;
571             if (pstat_getstatic(&pst_buf, sizeof(struct pst_static), 1, 0)
572                 < 0)
573                 return NULL;
574             long_ret =
575                 pst_buf.physical_memory * (pst_buf.page_size / 1024);
576         }
577 #elif defined(linux)
578         long_ret = memory(meminfo_total);
579 #elif defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE)
580         long_ret =
581             sysconf(_SC_PHYS_PAGES) * (sysconf(_SC_PAGESIZE) / 1024);
582 #elif defined(PHYSMEM_SYMBOL)
583         {
584             int             result;
585             if (auto_nlist
586                 (PHYSMEM_SYMBOL, (char *) &result, sizeof(result)) == 0)
587                 return NULL;
588             long_ret = result * 1000;   /* ??? */
589         }
590 #else
591         return NULL;            /* no dummy values */
592 #endif
593         return ((u_char *) (&long_ret));
594     case MEMAVAILREAL:
595 #ifdef linux
596         long_ret = memory(meminfo_free);
597 #elif defined(hpux10) || defined(hpux11)
598         long_ret = pagetok((int) pst_buf.psd_arm);
599 #elif defined(TOTAL_MEMORY_SYMBOL) || defined(USE_SYSCTL_VM)
600         long_ret = pagetok((int) total.t_arm);
601 #else
602         return NULL;            /* no dummy values */
603 #endif
604         return ((u_char *) (&long_ret));
605 #ifndef linux
606     case MEMTOTALSWAPTXT:
607 #if defined(hpux10) || defined(hpux11)
608         long_ret = pagetok((int) pst_buf.psd_vmtxt);
609 #elif !defined(bsdi2)
610         long_ret = pagetok(total.t_vmtxt);
611 #else
612         return NULL;            /* no dummy values */
613 #endif
614         return ((u_char *) (&long_ret));
615     case MEMUSEDSWAPTXT:
616 #if defined(hpux10) || defined(hpux11)
617         long_ret = pagetok((int) pst_buf.psd_avmtxt);
618 #elif !defined(bsdi2)
619         long_ret = pagetok(total.t_avmtxt);
620 #else
621         return NULL;            /* no dummy values */
622 #endif
623         return ((u_char *) (&long_ret));
624     case MEMTOTALREALTXT:
625 #if defined(hpux10) || defined(hpux11)
626         long_ret = pagetok((int) pst_buf.psd_rmtxt);
627 #elif !defined(bsdi2)
628         long_ret = pagetok(total.t_rmtxt);
629 #else
630         return NULL;            /* no dummy values */
631 #endif
632         return ((u_char *) (&long_ret));
633     case MEMUSEDREALTXT:
634 #if defined(hpux10) || defined(hpux11)
635         long_ret = pagetok((int) pst_buf.psd_armtxt);
636 #elif !defined(bsdi2)
637         long_ret = pagetok(total.t_armtxt);
638 #else
639         return NULL;            /* no dummy values */
640 #endif
641         return ((u_char *) (&long_ret));
642 #endif                          /* linux */
643     case MEMTOTALFREE:
644 #ifdef linux
645         long_ret = memory(meminfo_free) + memswap(meminfo_free);
646 #elif defined(hpux10) || defined(hpux11)
647         long_ret = pagetok((int) pst_buf.psd_free);
648 #else
649         long_ret = pagetok(total.t_free);
650 #endif
651         return ((u_char *) (&long_ret));
652     case MEMCACHED:
653 #ifdef linux
654         long_ret = memory(meminfo_cached);
655 #else
656         return NULL;            /* no dummy values */
657 #endif
658         return ((u_char *) (&long_ret));
659     case MEMBUFFER:
660 #ifdef linux
661         long_ret = memory(meminfo_buffers);
662 #else
663         return NULL;            /* no dummy values */
664 #endif
665         return ((u_char *) (&long_ret));
666     case MEMSHARED:
667 #ifdef linux
668         long_ret = memory(meminfo_shared);
669 #else
670         return NULL;            /* no dummy values */
671 #endif
672         return ((u_char *) (&long_ret));
673     case ERRORFLAG:
674         long_ret = getswap(SWAPGETLEFT);
675         long_ret = (long_ret > minimumswap) ? 0 : 1;
676         return ((u_char *) (&long_ret));
677     case ERRORMSG:
678         long_ret = getswap(SWAPGETLEFT);
679         if ((long_ret > minimumswap) ? 0 : 1)
680             sprintf(errmsg, "Running out of swap space (%ld)",
681                     getswap(SWAPGETLEFT));
682         else
683             errmsg[0] = 0;
684         *var_len = strlen(errmsg);
685         return ((u_char *) (errmsg));
686     }
687     return NULL;
688 }