Debian Codegraph @

agent/mibgroup/host/data_access/swrun_prpsinfo.c

raw
1 /*
2 * swrun_prpsinfo.c:
3 * hrSWRunTable data access:
4 * getprpsinfo() interface - Dynix
5 */
6 #include <net-snmp/net-snmp-config.h>
7
8 #include <stdio.h>
9 #ifdef HAVE_STDLIB_H
10 #include <stdlib.h>
11 #endif
12 #ifdef HAVE_UNISTD_H
13 #include <unistd.h>
14 #endif
15 #ifdef HAVE_SYS_TYPES_H
16 #include <sys/types.h>
17 #endif
18
19 #ifdef HAVE_?????_H
20 #include <?????.h>
21 #endif
22
23 #include <net-snmp/net-snmp-includes.h>
24 #include <net-snmp/agent/net-snmp-agent-includes.h>
25 #include <net-snmp/library/container.h>
26 #include <net-snmp/library/snmp_debug.h>
27 #include <net-snmp/data_access/swrun.h>
28 #include "swrun_private.h"
29
30 /* ---------------------------------------------------------------------
31 */
32 void
33 netsnmp_arch_swrun_init(void)
34 {
35 /* Nothing to do */
36 return;
37 }
38
39 /* ---------------------------------------------------------------------
40 */
41 int
42 netsnmp_arch_swrun_container_load( netsnmp_container *container, u_int flags)
43 {
44 pid_t nextproc = 0;
45 getprpsinfo_t *select = 0;
46 prpsinfo_t mypsinfo;
47 int rc;
48 char *cp;
49 netsnmp_swrun_entry *entry;
50
51 while ( 0 <= ( nextproc = getprpsinfo( nextproc, select, &mypsinfo ))) {
52 entry = netsnmp_swrun_entry_create(mypsinfo.pr_pid);
53 if (NULL == entry)
54 continue; /* error already logged by function */
55 rc = CONTAINER_INSERT(container, entry);
56
57 entry->hrSWRunName_len = snprintf(entry->hrSWRunName,
58 sizeof(entry->hrSWRunName)-1,
59 "%s", mypsinfo.pr_fname);
60 /*
61 * Split pr_psargs into two:
62 * argv[0] is hrSWRunPath
63 * argv[1..] is hrSWRunParameters
64 */
65 cp = strchr(mypsinfo.pr_psargs, ' ');
66 if (cp)
67 *cp = '\0'; /* End of argv[0] */
68 entry->hrSWRunPath_len = snprintf(entry->hrSWRunPath,
69 sizeof(entry->hrSWRunPath)-1,
70 "%s", mypsinfo.pr_psargs);
71 if (NULL != cp) {
72 entry->hrSWRunParameters_len = snprintf(entry->hrSWRunParameters,
73 sizeof(entry->hrSWRunParameters)-1,
74 "%s", cp+1);
75 *cp = ' '; /* Restore pr_psargs value */
76 }
77
78 /*
79 * XXX - No information regarding system processes vs applications
80 */
81
82 switch (mypsinfo.pr_state) {
83 /* XXX - which names to use ?? */
84 case SACTIVE:
85 case SRUN:
86 case SONPROC: entry->hrSWRunStatus = HRSWRUNSTATUS_RUNNING;
87 break;
88 case SSWAP:
89 case SSLEEP:
90 case SWAIT: entry->hrSWRunStatus = HRSWRUNSTATUS_RUNNABLE;
91 break;
92 case SSTOP: entry->hrSWRunStatus = HRSWRUNSTATUS_NOTRUNNABLE;
93 break;
94 case SIDL:
95 case SZOMB:
96 default: entry->hrSWRunStatus = HRSWRUNSTATUS_INVALID;
97 break;
98 }
99
100 entry->hrSWRunPerfCPU = (mypsinfo.pr_time.tv_sec * 100);
101 entry->hrSWRunPerfCPU += (mypsinfo.pr_time.tv_nsec / 10000000);
102 entry->hrSWRunPerfMem = (mypsinfo.pr_rssize);
103 entry->hrSWRunPerfMem *= (MU_PAGESIZE/1024); /* in kB */
104 }
105
106 DEBUGMSGTL(("swrun:load:arch"," loaded %d entries\n",
107 CONTAINER_SIZE(container)));
108
109 return 0;
110 }