1diff -I '\$Id: ' -u -r -b -w -p -d --new-file --exclude-from=/Users/rstory/.rcfiles/diff-ignore SVN/agent/mibgroup/host/data_access/swrun.c APPLE/agent/mibgroup/host/data_access/swrun.c
2--- SVN/agent/mibgroup/host/data_access/swrun.c
3+++ APPLE/agent/mibgroup/host/data_access/swrun.c
4@@ -0,0 +1,260 @@
5+/*
6+ *  Swrun MIB architecture support
7+ *
8+ * $Id: swrun.patch,v 1.3 2007/08/16 22:09:13 randall Exp $
9+ */
10+#include <net-snmp/net-snmp-config.h>
11+#include <net-snmp/net-snmp-includes.h>
12+
13+#include <net-snmp/agent/net-snmp-agent-includes.h>
14+#include <net-snmp/data_access/swrun.h>
15+
16+
17+/**---------------------------------------------------------------------*/
18+/*
19+ * local static vars
20+ */
21+static int _swrun_init = 0;
22+
23+/*
24+ * local static prototypes
25+ */
26+static void _swrun_entry_release(netsnmp_swrun_entry * entry,
27+                                            void *unused);
28+
29+/**---------------------------------------------------------------------*/
30+/*
31+ * external per-architecture functions prototypes
32+ *
33+ * These shouldn't be called by the general public, so they aren't in
34+ * the header file.
35+ */
36+extern void netsnmp_arch_swrun_init(void);
37+extern int netsnmp_arch_swrun_container_load(netsnmp_container* container,
38+                                             u_int load_flags);
39+
40+/**
41+ * initialization
42+ */
43+void
44+init_swrun(void)
45+{
46+    DEBUGMSGTL(("swrun:access", "init\n"));
47+
48+    netsnmp_assert(0 == _swrun_init); /* who is calling twice? */
49+
50+    if (1 == _swrun_init)
51+        return;
52+
53+    _swrun_init = 1;
54+
55+    netsnmp_arch_swrun_init();
56+}
57+
58+void
59+shutdown_swrun(void)
60+{
61+    DEBUGMSGTL(("swrun:access", "shutdown\n"));
62+
63+}
64+
65+/**---------------------------------------------------------------------*/
66+/*
67+ * container functions
68+ */
69+/**
70+ * create swrun container
71+ */
72+netsnmp_container *
73+netsnmp_swrun_container_create(u_int flags)
74+{
75+    netsnmp_container *container;
76+
77+    DEBUGMSGTL(("swrun:container", "init\n"));
78+
79+    /*
80+     * create the container.
81+     */
82+    container = netsnmp_container_find("swrun:table_container");
83+    if (NULL == container)
84+        return NULL;
85+
86+    container->container_name = strdup("swrun container");
87+
88+    return container;
89+}
90+
91+/**
92+ * load swrun information in specified container
93+ *
94+ * @param container empty container to be filled.
95+ *                  pass NULL to have the function create one.
96+ * @param load_flags flags to modify behaviour. Examples:
97+ *                   NETSNMP_SWRUN_ALL_OR_NONE
98+ *
99+ * @retval NULL  error
100+ * @retval !NULL pointer to container
101+ */
102+netsnmp_container*
103+netsnmp_swrun_container_load(netsnmp_container* user_container, u_int load_flags)
104+{
105+    netsnmp_container* container = user_container;
106+    int rc;
107+
108+    DEBUGMSGTL(("swrun:container:load", "load\n"));
109+    netsnmp_assert(1 == _swrun_init);
110+
111+    if (NULL == container)
112+        container = netsnmp_swrun_container_create(load_flags);
113+    if (NULL == container) {
114+        snmp_log(LOG_ERR, "no container specified/found for swrun\n");
115+        return NULL;
116+    }
117+
118+    rc =  netsnmp_arch_swrun_container_load(container, load_flags);
119+    if (0 != rc) {
120+        if (NULL == user_container) {
121+            netsnmp_swrun_container_free(container, NETSNMP_SWRUN_NOFLAGS);
122+            container = NULL;
123+        }
124+        else if (load_flags & NETSNMP_SWRUN_ALL_OR_NONE) {
125+            DEBUGMSGTL(("swrun:container:load",
126+                        " discarding partial results\n"));
127+            netsnmp_swrun_container_free_items(container);
128+        }
129+    }
130+
131+    return container;
132+}
133+
134+void
135+netsnmp_swrun_container_free(netsnmp_container *container, u_int free_flags)
136+{
137+    DEBUGMSGTL(("swrun:container", "free\n"));
138+
139+    if (NULL == container) {
140+        snmp_log(LOG_ERR, "invalid container for netsnmp_swrun_container_free\n");
141+        return;
142+    }
143+
144+    if(! (free_flags & NETSNMP_SWRUN_DONT_FREE_ITEMS))
145+        netsnmp_swrun_container_free_items(container);
146+
147+    CONTAINER_FREE(container);
148+}
149+
150+void
151+netsnmp_swrun_container_free_items(netsnmp_container *container)
152+{
153+    DEBUGMSGTL(("swrun:container", "free_items\n"));
154+
155+    if (NULL == container) {
156+        snmp_log(LOG_ERR, "invalid container for netsnmp_swrun_container_free_items\n");
157+        return;
158+    }
159+
160+    /*
161+     * free all items.
162+     */
163+    CONTAINER_CLEAR(container,
164+                    (netsnmp_container_obj_func*)_swrun_entry_release,
165+                    NULL);
166+}
167+
168+/**---------------------------------------------------------------------*/
169+/*
170+ * swrun_entry functions
171+ */
172+/**
173+ */
174+netsnmp_swrun_entry *
175+netsnmp_swrun_entry_get_by_index(netsnmp_container *container, oid index)
176+{
177+    netsnmp_index   tmp;
178+
179+    DEBUGMSGTL(("swrun:entry", "by_index\n"));
180+    netsnmp_assert(1 == _swrun_init);
181+
182+    if (NULL == container) {
183+        snmp_log(LOG_ERR,
184+                 "invalid container for netsnmp_swrun_entry_get_by_index\n");
185+        return NULL;
186+    }
187+
188+    tmp.len = 1;
189+    tmp.oids = &index;
190+
191+    return (netsnmp_swrun_entry *) CONTAINER_FIND(container, &tmp);
192+}
193+
194+/**
195+ */
196+netsnmp_swrun_entry *
197+netsnmp_swrun_entry_create(int32_t index)
198+{
199+    netsnmp_swrun_entry *entry =
200+        SNMP_MALLOC_TYPEDEF(netsnmp_swrun_entry);
201+
202+    if(NULL == entry)
203+        return NULL;
204+
205+    entry->hrSWRunIndex = index;
206+    entry->hrSWRunType = 1; /* unknown */
207+    entry->hrSWRunStatus = 2; /* runnable */
208+
209+    entry->oid_index.len = 1;
210+    entry->oid_index.oids = (oid *) & entry->hrSWRunIndex;
211+
212+    return entry;
213+}
214+
215+/**
216+ */
217+NETSNMP_INLINE void
218+netsnmp_swrun_entry_free(netsnmp_swrun_entry * entry)
219+{
220+    if (NULL == entry)
221+        return;
222+
223+    /*
224+     * SNMP_FREE not needed, for any of these, 
225+     * since the whole entry is about to be freed
226+     */
227+    free(entry);
228+}
229+
230+/**---------------------------------------------------------------------*/
231+/*
232+ * Utility routines
233+ */
234+
235+/**
236+ */
237+static void
238+_swrun_entry_release(netsnmp_swrun_entry * entry, void *context)
239+{
240+    netsnmp_swrun_entry_free(entry);
241+}
242+
243+
244+#ifdef TEST
245+int main(int argc, char *argv[])
246+{
247+    const char *tokens = getenv("SNMP_DEBUG");
248+
249+    netsnmp_container_init_list();
250+
251+    /** swrun,verbose:swrun,9:swrun,8:swrun,5:swrun */
252+    if (tokens)
253+        debug_register_tokens(tokens);
254+    else
255+        debug_register_tokens("swrun");
256+    snmp_set_do_debugging(1);
257+
258+    init_swrun();
259+    netsnmp_swrun_container_load(NULL, 0);
260+    shutdown_swrun();
261+
262+    return 0;
263+}
264+#endif
265diff -I '\$Id: ' -u -r -b -w -p -d --new-file --exclude-from=/Users/rstory/.rcfiles/diff-ignore SVN/agent/mibgroup/host/data_access/swrun.h APPLE/agent/mibgroup/host/data_access/swrun.h
266--- SVN/agent/mibgroup/host/data_access/swrun.h
267+++ APPLE/agent/mibgroup/host/data_access/swrun.h
268@@ -0,0 +1,46 @@
269+/*
270+ * swrun data access header
271+ *
272+ * $Id: swrun.patch,v 1.3 2007/08/16 22:09:13 randall Exp $
273+ */
274+#ifndef NETSNMP_ACCESS_SWRUN_CONFIG_H
275+#define NETSNMP_ACCESS_SWRUN_CONFIG_H
276+
277+/*
278+ * all platforms use this generic code
279+ */
280+config_require(host/data_access/swrun)
281+
282+/**---------------------------------------------------------------------*/
283+/*
284+ * configure required files
285+ *
286+ * Notes:
287+ *
288+ * 1) prefer functionality over platform, where possible. If a method
289+ *    is available for multiple platforms, test that first. That way
290+ *    when a new platform is ported, it won't need a new test here.
291+ *
292+ * 2) don't do detail requirements here. If, for example,
293+ *    HPUX11 had different reuirements than other HPUX, that should
294+ *    be handled in the *_hpux.h header file.
295+ */
296+
297+#ifdef NETSNMP_INCLUDE_HRSWRUN_REWRITES
298+
299+config_exclude(host/hr_swrun)
300+
301+#   if defined( darwin )
302+
303+    config_require(host/data_access/swrun_darwin)
304+
305+#   else
306+
307+    config_error(This platform does not yet support hrSWRunTable rewrites)
308+
309+#   endif
310+#else
311+#   define NETSNMP_ACCESS_SWRUN_NOARCH 1
312+#endif
313+
314+#endif /* NETSNMP_ACCESS_SWRUN_CONFIG_H */
315diff -I '\$Id: ' -u -r -b -w -p -d --new-file --exclude-from=/Users/rstory/.rcfiles/diff-ignore SVN/agent/mibgroup/host/data_access/swrun_darwin.c APPLE/agent/mibgroup/host/data_access/swrun_darwin.c
316--- SVN/agent/mibgroup/host/data_access/swrun_darwin.c
317+++ APPLE/agent/mibgroup/host/data_access/swrun_darwin.c
318@@ -0,0 +1,491 @@
319+/*
320+ * swinst.c : hrSWInstalledTable data access
321+ */
322+#include <net-snmp/net-snmp-config.h>
323+#include <net-snmp/net-snmp-includes.h>
324+#include <net-snmp/agent/net-snmp-agent-includes.h>
325+#include <net-snmp/library/container.h>
326+#include <net-snmp/library/snmp_debug.h>
327+#include <net-snmp/data_access/swrun.h>
328+
329+#include <stdlib.h>
330+#include <unistd.h>
331+
332+#include <libproc.h>
333+#include <sys/proc_info.h>
334+#include <sys/sysctl.h>	/* for sysctl() and struct kinfo_proc */
335+
336+#define __APPLE_API_EVOLVING 1
337+#include <sys/acl.h> /* or else CoreFoundation.h barfs */
338+#undef __APPLE_API_EVOLVING 
339+
340+#include <CoreFoundation/CFBase.h>
341+#include <CoreFoundation/CFNumber.h>
342+#include <CoreFoundation/CFBundle.h>
343+#include <CoreServices/CoreServices.h>
344+#include <IOKit/IOCFBundle.h>
345+#include <mach/mach.h>
346+#include <mach/mach_time.h>
347+
348+/** sigh... can't find Processes.h */
349+#ifndef kProcessDictionaryIncludeAllInformationMask 
350+#define kProcessDictionaryIncludeAllInformationMask (long)0xFFFFFFFF
351+#endif
352+#ifndef procNotFound
353+#define procNotFound -600
354+#endif
355+
356+/* ---------------------------------------------------------------------
357+ */
358+static int _kern_argmax;
359+static int _set_command_name(netsnmp_swrun_entry *entry);
360+
361+/** avoid kernel bug in 10.2. 8192 oughta be enough anyways, right? */
362+#define MAX_KERN_ARGMAX 8192
363+
364+/* ---------------------------------------------------------------------
365+ */
366+void
367+netsnmp_arch_swrun_init(void)
368+{
369+    int    mib[2] = { CTL_KERN, KERN_ARGMAX };
370+    size_t size, mib_size = sizeof(mib)/sizeof(mib[0]);
371+    
372+    DEBUGMSGTL(("swrun:load:arch","init\n"));
373+
374+    size = sizeof(_kern_argmax);
375+    if (sysctl(mib, mib_size, &_kern_argmax, &size, NULL, 0) == -1) {
376+        snmp_log(LOG_ERR, "Error in ARGMAX sysctl(): %s", strerror(errno));
377+        _kern_argmax = MAX_KERN_ARGMAX;
378+    }
379+    else if (_kern_argmax > MAX_KERN_ARGMAX) {
380+        DEBUGMSGTL(("swrun:load:arch",
381+                    "artificially limiting ARGMAX to %d (from %d)\n",
382+                    MAX_KERN_ARGMAX, _kern_argmax));
383+        _kern_argmax = MAX_KERN_ARGMAX;
384+    }
385+
386+
387+}
388+
389+/* ---------------------------------------------------------------------
390+ */
391+#define SWRUNINDENT "           "
392+int
393+netsnmp_arch_swrun_container_load( netsnmp_container *container, u_int flags)
394+{
395+    int	                 mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL};
396+    size_t               buf_size, mib_size = sizeof(mib)/sizeof(mib[0]);
397+    struct kinfo_proc   *processes = NULL;
398+    struct proc_taskallinfo taskinfo;
399+    netsnmp_swrun_entry *entry;
400+    int                  rc, num_entries, i;
401+
402+    DEBUGMSGTL(("swrun:load:arch"," load\n"));
403+
404+    /*
405+     * get size to allocate. This introduces a bit of a race condition,
406+     * as the size could change between this call and the next...
407+     */
408+    rc = sysctl(mib, mib_size, NULL, &buf_size, NULL, 0);
409+    if (rc < 0) {
410+        snmp_log(LOG_ERR, "KERN_PROC_ALL size sysctl failed: %d\n", rc);
411+        return -1;
412+    }
413+
414+    processes = (struct kinfo_proc*) malloc(buf_size);
415+    if (NULL == processes) {
416+        snmp_log(LOG_ERR, "malloc failed\n");
417+        return -1;
418+    }
419+
420+    rc = sysctl(mib, mib_size, processes, &buf_size, NULL, 0);
421+    if (rc < 0) {
422+        snmp_log(LOG_ERR, "KERN_PROC_ALL sysctl failed: %d\n", rc);
423+        free(processes);
424+        return -1;
425+    }
426+    
427+    num_entries = buf_size / sizeof(struct kinfo_proc);
428+    
429+    for (i = 0; i < num_entries; i++) {
430+        /*
431+         * skip empty names.
432+         * p_stat = (SIDL|SRUN|SSLEEP|SSTOP|SZOMB)
433+         */
434+        if ((NULL == processes[i].kp_proc.p_comm) ||
435+            (0 == processes[i].kp_proc.p_pid)) {
436+            DEBUGMSGTL(("swrun:load:arch",
437+                        " skipping p_comm '%s', pid %5d, p_pstat %d\n",
438+                        processes[i].kp_proc.p_comm ? 
439+                        processes[i].kp_proc.p_comm : "NULL",
440+                        processes[i].kp_proc.p_pid,
441+                        processes[i].kp_proc.p_stat));
442+            continue;
443+        }
444+
445+        DEBUGMSGTL(("swrun:load:arch"," %s pid %5d\n",
446+                    processes[i].kp_proc.p_comm,
447+                    processes[i].kp_proc.p_pid));
448+
449+        entry = netsnmp_swrun_entry_create(processes[i].kp_proc.p_pid);
450+        if (NULL == entry)
451+            continue; /* error already logged by function */
452+        rc = CONTAINER_INSERT(container, entry);
453+
454+        /*
455+         * p_comm is a partial name, but it is all we have at this point.
456+         */
457+        entry->hrSWRunName_len = snprintf(entry->hrSWRunName,
458+                                          sizeof(entry->hrSWRunName)-1,
459+                                          "%s", processes[i].kp_proc.p_comm);
460+
461+        /** sysctl for name, path, params */
462+        rc = _set_command_name(entry);
463+
464+        /*
465+         * map p_stat to RunStatus. Odd that there is no 'running' status.
466+         */
467+        switch(processes[i].kp_proc.p_stat) {
468+            case SRUN:
469+                entry->hrSWRunStatus = HRSWRUNSTATUS_RUNNABLE;
470+                break;
471+            case SSLEEP:
472+            case SSTOP:
473+                entry->hrSWRunStatus = HRSWRUNSTATUS_NOTRUNNABLE;
474+                break;
475+            case SIDL:
476+            case SZOMB:
477+            default:
478+                entry->hrSWRunStatus = HRSWRUNSTATUS_INVALID;
479+                break;
480+        } 
481+
482+        /*
483+         * check for system processes
484+         */
485+        if (P_SYSTEM & processes[i].kp_proc.p_flag) {
486+            entry->hrSWRunType = 2; /* operatingSystem */
487+            DEBUGMSGTL(("swrun:load:arch", SWRUNINDENT "SYSTEM\n"));
488+        }
489+
490+        /*
491+         * get mem size, run time
492+         */
493+        rc = proc_pidinfo( processes[i].kp_proc.p_pid, PROC_PIDTASKALLINFO, 0,
494+                           &taskinfo, sizeof(taskinfo));
495+        if (sizeof(taskinfo) != rc) {
496+            DEBUGMSGTL(("swrun:load:arch", " proc_pidinfo returned %d\n", rc));
497+        }
498+        else {
499+            uint64_t task_mem = taskinfo.ptinfo.pti_resident_size / 1024;
500+            union {
501+                u_quad_t     uq; /* u_int64_t */
502+                UnsignedWide uw; /* struct u_int32_t hi/lo */
503+            } at, ns;
504+            at.uq = taskinfo.ptinfo.pti_total_user +
505+                    taskinfo.ptinfo.pti_total_system;
506+            ns.uw = AbsoluteToNanoseconds( at.uw );
507+            ns.uq = ns.uq / 10000000LL; /* nano to deci */
508+            if (task_mem > INT32_MAX) {
509+                DEBUGMSGTL(("swrun:load:arch", SWRUNINDENT "mem overflow\n"));
510+                task_mem = INT32_MAX;
511+            }
512+            if (ns.uq > INT32_MAX) {
513+                DEBUGMSGTL(("swrun:load:arch", SWRUNINDENT "time overflow\n"));
514+                ns.uq = INT32_MAX;
515+            }
516+            entry->hrSWRunPerfMem = task_mem;
517+            entry->hrSWRunPerfCPU = ns.uq;
518+        }
519+    }
520+    free(processes);
521+
522+    DEBUGMSGTL(("swrun:load:arch"," loaded %d entries\n",
523+                CONTAINER_SIZE(container)));
524+
525+    return 0;
526+}
527+
528+/* ---------------------------------------------------------------------
529+ * The following code was snagged from Darwin code, and the original
530+ * file had the following licences:
531+ */
532+
533+/*
534+ * Copyright (c) 2002-2004 Apple Computer, Inc.  All rights reserved.
535+ *
536+ * @APPLE_LICENSE_HEADER_START@
537+ * 
538+ * The contents of this file constitute Original Code as defined in and
539+ * are subject to the Apple Public Source License Version 1.1 (the
540+ * "License").  You may not use this file except in compliance with the
541+ * License.  Please obtain a copy of the License at
542+ * http://www.apple.com/publicsource and read it before using this file.
543+ * 
544+ * This Original Code and all software distributed under the License are
545+ * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
546+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
547+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
548+ * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
549+ * License for the specific language governing rights and limitations
550+ * under the License.
551+ * 
552+ * @APPLE_LICENSE_HEADER_END@
553+ */
554+#ifdef JAGUAR /* xxx configure test? */
555+static int
556+_set_command_name_jaguar(netsnmp_swrun_entry *entry)
557+{
558+    int	        mib[3] = {CTL_KERN, KERN_PROCARGS, 0};
559+    size_t      procargssize, mib_size = sizeof(mib)/sizeof(mib[0]);
560+    char       *arg_end, *exec_path;
561+    int        *ip;
562+    int         len;
563+    char       *command_beg, *command, *command_end;
564+    char        arg_buf[MAX_KERN_ARGMAX]; /* max to avoid kernel bug */
565+
566+    DEBUGMSGTL(("swrun:load:arch:_cn"," pid %d\n", entry->hrSWRunIndex));
567+
568+    mib[2] = entry->hrSWRunIndex;
569+
570+    memset(arg_buf, 0x0, sizeof(arg_buf));
571+    procargssize = _kern_argmax;
572+    if (sysctl(mib, mib_size, arg_buf, &procargssize, NULL, 0) == -1) {
573+        snmp_log(LOG_ERR, "Error in PROCARGS sysctl() for %s: %s\n",
574+                 entry->hrSWRunName, strerror(errno));
575+        entry->hrSWRunPath_len = 0;
576+        return -1;
577+    }
578+
579+    /* Set ip just above the end of arg_buf. */
580+    arg_end = &arg_buf[procargssize];
581+    ip = (int *)arg_end;
582+    
583+    /*
584+     * Skip the last 2 words, since the last is a 0 word, and
585+     * the second to last may be as well, if there are no
586+     * arguments.
587+     */
588+    ip -= 3;
589+    
590+    /* Iterate down the arguments until a 0 word is found. */
591+    for (; *ip != 0; ip--) {
592+        if (ip == (int *)arg_buf) {
593+            DEBUGMSGTL(("swrun:load:arch:_cn"," unexpected toparg\n"));
594+            return -1;
595+        }
596+    }
597+    
598+    /* The saved exec_path is just above the 0 word. */
599+    ip++;
600+    exec_path = (char *)ip;
601+    DEBUGMSGTL(("swrun:load:arch:_cn"," exec_path %s\n", exec_path));
602+    len = strlen(exec_path);
603+    strncpy(entry->hrSWRunPath, exec_path, sizeof(entry->hrSWRunPath)-1);
604+    entry->hrSWRunPath[sizeof(entry->hrSWRunPath)-1] = 0;
605+    if (len > sizeof(entry->hrSWRunPath)-1) {
606+        DEBUGMSGTL(("swrun:load:arch:_cn"," truncating long run path\n"));
607+        entry->hrSWRunPath[sizeof(entry->hrSWRunPath)-2] = '$';
608+        entry->hrSWRunPath_len = sizeof(entry->hrSWRunPath)-1;
609+        DEBUGMSGTL(("swrun:load:arch:_cn"," exec_path %s\n",
610+                    entry->hrSWRunPath));
611+    }
612+    else
613+        entry->hrSWRunPath_len = len;
614+    
615+    /*
616+     * Get the beginning of the first argument.  It is word-aligned,
617+     * so skip padding '\0' bytes.
618+     */
619+    command_beg = exec_path + strlen(exec_path);
620+    DEBUGMSGTL(("swrun:load:arch:_cn"," command_beg '%s'\n", command_beg));
621+    for (; *command_beg == '\0'; command_beg++) {
622+        if (command_beg >= arg_end)
623+            return -1;
624+    }
625+    DEBUGMSGTL(("swrun:load:arch:_cn"," command_beg '%s'\n", command_beg));
626+    
627+    /* Get the basename of command. */
628+    command = command_end = command_beg + strlen(command_beg) + 1;
629+    for (command--; command >= command_beg; command--) {
630+        if (*command == '/')
631+            break;
632+    }
633+    command++;
634+    DEBUGMSGTL(("swrun:load:arch:_cn"," command '%s'\n", command));
635+    
636+    /* Allocate space for the command and copy. */
637+    DEBUGMSGTL(("swrun:load:arch:_cn",
638+                SWRUNINDENT "kernel name %s\n", command));
639+    if (strncmp(command, entry->hrSWRunName, sizeof(entry->hrSWRunName)-1)) {
640+        strncpy(entry->hrSWRunName, command, sizeof(entry->hrSWRunName)-1);
641+        entry->hrSWRunName[sizeof(entry->hrSWRunName)-1] = 0;
642+        entry->hrSWRunName_len = strlen(entry->hrSWRunName);
643+        DEBUGMSGTL(("swrun:load:arch:_cn", "**"
644+                    SWRUNINDENT "updated name to %s\n", entry->hrSWRunName));
645+        return 0;
646+    }
647+
648+    /** no error, no change */
649+    return 1;
650+}
651+#else
652+static int
653+_set_command_name(netsnmp_swrun_entry *entry)
654+{
655+    int	        mib[3] = {CTL_KERN, 0, 0};
656+    size_t      procargssize, mib_size = sizeof(mib)/sizeof(mib[0]);
657+    char       *cp;
658+    int         len, nargs;
659+    char       *command_beg, *command, *command_end, *exec_path, *argN;
660+    char        arg_buf[MAX_KERN_ARGMAX]; /* max to avoid kernel bug */
661+
662+    /*
663+     * arguments
664+     */
665+    mib[1] = KERN_PROCARGS2;
666+    mib[2] = entry->hrSWRunIndex;
667+
668+    memset(arg_buf, 0x0, sizeof(arg_buf));
669+    procargssize = _kern_argmax;
670+    if (sysctl(mib, mib_size, arg_buf, &procargssize, NULL, 0) == -1) {
671+        snmp_log(LOG_ERR, "Error in PROCARGS2 sysctl() for %s: %s\n",
672+                 entry->hrSWRunName, strerror(errno));
673+        entry->hrSWRunPath_len = 0;
674+        entry->hrSWRunParameters_len = 0;
675+        return -1;
676+    }
677+    else {
678+        memcpy(&nargs,arg_buf, sizeof(nargs));
679+    }
680+
681+    exec_path = arg_buf + sizeof(nargs);
682+    len = strlen(exec_path);
683+    strncpy(entry->hrSWRunPath, exec_path, sizeof(entry->hrSWRunPath)-1);
684+    entry->hrSWRunPath[sizeof(entry->hrSWRunPath)-1] = 0;
685+    if (len > sizeof(entry->hrSWRunPath)-1) {
686+        DEBUGMSGTL(("swrun:load:arch:_cn"," truncating long run path\n"));
687+        entry->hrSWRunPath[sizeof(entry->hrSWRunPath)-2] = '$';
688+        entry->hrSWRunPath_len = sizeof(entry->hrSWRunPath)-1;
689+    }
690+    else
691+        entry->hrSWRunPath_len = len;
692+
693+    /** Skip the saved exec_path. */
694+#if 0
695+    cp = exec_path + len;
696+#else
697+    for (cp = exec_path; cp < &arg_buf[procargssize]; cp++) {
698+        if (*cp == '\0') 
699+            break; /* End of exec_path reached. */
700+    }
701+    if (cp != exec_path + len) {
702+        DEBUGMSGTL(("swrun:load:arch:_cn"," OFF BY %d\n",
703+                    (exec_path + len) - cp));
704+        netsnmp_assert( cp == exec_path + len );
705+    }
706+#endif
707+    if (cp == &arg_buf[procargssize]) {
708+        DEBUGMSGTL(("swrun:load:arch:_cn"," unexpected end of buffer\n"));
709+        return -1;
710+    }
711+
712+    /** Skip trailing '\0' characters. */
713+    for (; cp < &arg_buf[procargssize]; cp++) {
714+        if (*cp != '\0')
715+            break; /* Beginning of first argument reached. */
716+    }
717+    if (cp == &arg_buf[procargssize]) {
718+        DEBUGMSGTL(("swrun:load:arch:_cn"," unexpected end of buffer\n"));
719+        return -1;
720+    }
721+    command_beg = cp;
722+
723+    /*
724+     * Make sure that the command is '\0'-terminated.  This protects
725+     * against malicious programs; under normal operation this never
726+     * ends up being a problem..
727+     */
728+    for (; cp < &arg_buf[procargssize]; cp++) {
729+        if (*cp == '\0')
730+            break; /* End of first argument reached. */
731+    }
732+    if (cp == &arg_buf[procargssize]) {
733+        DEBUGMSGTL(("swrun:load:arch:_cn"," unexpected end of buffer\n"));
734+        return -1;
735+    }
736+    command_end = command = cp;
737+    --nargs;
738+
739+    /*
740+     * save arguments
741+     */
742+    while( nargs && cp < &arg_buf[procargssize] ) {
743+        /** Skip trailing '\0' characters from prev arg. */
744+        for (; (cp < &arg_buf[procargssize]) && (*cp == 0); cp++) 
745+            ; /* noop */
746+        if (cp == &arg_buf[procargssize])
747+            continue; /* effectively a break */
748+    
749+        /** save argN start */
750+        argN = cp;
751+        --nargs;
752+        if (0 == nargs)
753+            continue; /* effectively a break */
754+
755+        /** Skip to end of arg */
756+        for (; (cp < &arg_buf[procargssize]) && (*cp != 0); cp++) 
757+            ;  /* noop */
758+        if (cp == &arg_buf[procargssize])
759+            continue; /* effectively a break */
760+
761+        /*
762+         * check for overrun into env
763+         */
764+        if ((*argN != '-') && strchr(argN,'='))  {
765+            DEBUGMSGTL(("swrun:load:arch:_cn", " *** OVERRUN INTO ENV %d\n",nargs));
766+            continue;
767+        }
768+
769+        /*
770+         * save arg
771+         */
772+        if(entry->hrSWRunParameters_len < sizeof(entry->hrSWRunParameters)-1) {
773+            strncat(&entry->hrSWRunParameters[entry->hrSWRunParameters_len], argN,
774+                    sizeof(entry->hrSWRunParameters) - entry->hrSWRunParameters_len - 2);
775+            entry->hrSWRunParameters_len = strlen(entry->hrSWRunParameters);
776+            if ((entry->hrSWRunParameters_len+2 < sizeof(entry->hrSWRunParameters)-1) && (0 != nargs)) {
777+                /* add space between params */
778+                entry->hrSWRunParameters[entry->hrSWRunParameters_len++] = ' ';
779+                entry->hrSWRunParameters[entry->hrSWRunParameters_len] = 0;
780+            } else {
781+                DEBUGMSGTL(("swrun:load:arch:_cn"," truncating long arg list\n"));
782+                entry->hrSWRunParameters[entry->hrSWRunParameters_len++] = '$';
783+                entry->hrSWRunParameters[entry->hrSWRunParameters_len] = '0';
784+            }
785+        }
786+    }
787+    if (' ' == entry->hrSWRunParameters[entry->hrSWRunParameters_len])
788+        entry->hrSWRunParameters[entry->hrSWRunParameters_len--] = 0;
789+
790+    
791+    /* Get the basename of command. */
792+    for (command--; command >= command_beg; command--) {
793+        if (*command == '/')
794+            break;
795+    }
796+    command++;
797+    
798+    /* Allocate space for the command and copy. */
799+    if (strncmp(command, entry->hrSWRunName, sizeof(entry->hrSWRunName)-1)) {
800+        strncpy(entry->hrSWRunName, command, sizeof(entry->hrSWRunName)-1);
801+        entry->hrSWRunName[sizeof(entry->hrSWRunName)-1] = 0;
802+        entry->hrSWRunName_len = strlen(entry->hrSWRunName);
803+        DEBUGMSGTL(("swrun:load:arch:_cn",
804+                    " **updated name to %s\n", entry->hrSWRunName));
805+    }
806+
807+    return 0;
808+}
809+#endif
810diff -I '\$Id: ' -u -r -b -w -p -d --new-file --exclude-from=/Users/rstory/.rcfiles/diff-ignore SVN/agent/mibgroup/host/hrSWRunPerfTable.c APPLE/agent/mibgroup/host/hrSWRunPerfTable.c
811--- SVN/agent/mibgroup/host/hrSWRunPerfTable.c
812+++ APPLE/agent/mibgroup/host/hrSWRunPerfTable.c
813@@ -0,0 +1,186 @@
814+/*
815+ * Note: this file originally auto-generated by mib2c using
816+ *  : mib2c.container.conf,v 1.8 2006/07/26 15:58:26 dts12 Exp $
817+ */
818+
819+#include <net-snmp/net-snmp-config.h>
820+#include <net-snmp/net-snmp-includes.h>
821+#include <net-snmp/agent/net-snmp-agent-includes.h>
822+#include <net-snmp/data_access/swrun.h>
823+#include "hrSWRunPerfTable.h"
824+
825+#define MYTABLE "hrSWRunPerfTable"
826+
827+/** Initializes the hrSWRunPerfTable module */
828+void
829+init_hrSWRunPerfTable(void)
830+{
831+    /*
832+     * here we initialize all the tables we're planning on supporting 
833+     */
834+    initialize_table_hrSWRunPerfTable();
835+}
836+
837+extern oid      hrSWRunTable_oid[];
838+extern size_t   hrSWRunTable_oid_len;
839+
840+/** Initialize the hrSWRunPerfTable table by defining its contents and how it's structured */
841+void
842+initialize_table_hrSWRunPerfTable(void)
843+{
844+    static oid      hrSWRunPerfTable_oid[] =
845+        { 1, 3, 6, 1, 2, 1, 25, 5, 1 };
846+    size_t          hrSWRunPerfTable_oid_len =
847+        OID_LENGTH(hrSWRunPerfTable_oid);
848+    netsnmp_handler_registration *reg;
849+    netsnmp_mib_handler *handler;
850+    netsnmp_cache *cache;
851+    netsnmp_table_registration_info *table_info;
852+
853+    reg =
854+        netsnmp_create_handler_registration("hrSWRunPerfTable",
855+                                            hrSWRunPerfTable_handler,
856+                                            hrSWRunPerfTable_oid,
857+                                            hrSWRunPerfTable_oid_len,
858+                                            HANDLER_CAN_RONLY);
859+    if (NULL == reg) {
860+        snmp_log(LOG_ERR,"error creating handler registration for "
861+                 MYTABLE "\n");
862+        goto bail;
863+    }
864+
865+    table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
866+    if (NULL == table_info) {
867+        snmp_log(LOG_ERR,"error allocating table registration for "
868+                 MYTABLE "\n");
869+        goto bail;
870+    }
871+    netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER,   /* index: hrSWRunIndex */
872+                                     0);
873+    table_info->min_column = COLUMN_HRSWRUNPERFCPU;
874+    table_info->max_column = COLUMN_HRSWRUNPERFMEM;
875+
876+    /*************************************************
877+     *
878+     * find hrSWRunTable cache
879+     */
880+    cache =
881+        netsnmp_cache_find_by_oid(hrSWRunTable_oid, hrSWRunTable_oid_len);
882+    if (NULL == cache) {
883+        snmp_log(LOG_ERR, "error creating cache for " MYTABLE "\n");
884+        goto bail;
885+    }
886+
887+    /*************************************************
888+     *
889+     * inject container_table helper
890+     */
891+    handler = netsnmp_container_table_handler_get(table_info, (netsnmp_container*)cache->magic,
892+                                                  TABLE_CONTAINER_KEY_NETSNMP_INDEX);
893+    if (NULL == handler) {
894+        snmp_log(LOG_ERR,"error allocating table registration for "
895+                 MYTABLE "\n");
896+        goto bail;
897+    }
898+    if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) {
899+        snmp_log(LOG_ERR,"error injecting container_table handler for "
900+                 MYTABLE "\n");
901+        goto bail;
902+    }
903+    handler = NULL; /* reg has it, will reuse below */
904+
905+    /*************************************************
906+     *
907+     * inject cache helper
908+     */
909+
910+    handler = netsnmp_cache_handler_get(cache);
911+    if (NULL == handler) {
912+        snmp_log(LOG_ERR, "error creating cache handler for " MYTABLE "\n");
913+        goto bail;
914+    }
915+
916+    if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) {
917+        snmp_log(LOG_ERR,"error injecting cache handler for "
918+                 MYTABLE "\n");
919+        goto bail;
920+    }
921+    handler = NULL; /* reg has it*/
922+
923+    if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) {
924+        snmp_log(LOG_ERR,"error registering table handler for "
925+                 MYTABLE "\n");
926+        goto bail;
927+    }
928+
929+    return; /* ok */
930+
931+
932+  bail: /* not ok */
933+    
934+    if (handler)
935+        netsnmp_handler_free(handler);
936+
937+    if (cache)
938+        netsnmp_cache_free(cache);
939+
940+    if (table_info)
941+        netsnmp_table_registration_info_free(table_info);
942+
943+    if (reg) 
944+        netsnmp_handler_registration_free(reg);
945+}
946+
947+/** handles requests for the hrSWRunPerfTable table */
948+int
949+hrSWRunPerfTable_handler(netsnmp_mib_handler *handler,
950+                         netsnmp_handler_registration *reginfo,
951+                         netsnmp_agent_request_info *reqinfo,
952+                         netsnmp_request_info *requests)
953+{
954+
955+    netsnmp_request_info *request;
956+    netsnmp_table_request_info *table_info;
957+    netsnmp_swrun_entry *table_entry;
958+
959+    switch (reqinfo->mode) {
960+        /*
961+         * Read-support (also covers GetNext requests)
962+         */
963+    case MODE_GET:
964+        for (request = requests; request; request = request->next) {
965+            if (request->processed)
966+               continue;
967+            table_entry = (netsnmp_swrun_entry *)
968+                netsnmp_container_table_extract_context(request);
969+            table_info = netsnmp_extract_table_info(request);
970+            if ((NULL == table_entry) || (NULL == table_info)) {
971+                snmp_log(LOG_ERR, "could not extract table entry or info for "
972+                 MYTABLE "\n");
973+                snmp_set_var_typed_value(request->requestvb,
974+                                         SNMP_ERR_GENERR, NULL, 0);
975+                continue;
976+            }
977+
978+            switch (table_info->colnum) {
979+            case COLUMN_HRSWRUNPERFCPU:
980+                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
981+                                           table_entry->hrSWRunPerfCPU);
982+                break;
983+            case COLUMN_HRSWRUNPERFMEM:
984+                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
985+                                           table_entry->hrSWRunPerfMem);
986+                break;
987+            default:
988+                /*
989+                 * An unsupported/unreadable column (if applicable) 
990+                 */
991+                snmp_set_var_typed_value(request->requestvb,
992+                                         SNMP_NOSUCHOBJECT, NULL, 0);
993+            }
994+        }
995+        break;
996+
997+    }
998+    return SNMP_ERR_NOERROR;
999+}
1000diff -I '\$Id: ' -u -r -b -w -p -d --new-file --exclude-from=/Users/rstory/.rcfiles/diff-ignore SVN/agent/mibgroup/host/hrSWRunPerfTable.h APPLE/agent/mibgroup/host/hrSWRunPerfTable.h
1001--- SVN/agent/mibgroup/host/hrSWRunPerfTable.h
1002+++ APPLE/agent/mibgroup/host/hrSWRunPerfTable.h
1003@@ -0,0 +1,22 @@
1004+/*
1005+ * Note: this file originally auto-generated by mib2c using
1006+ *  : mib2c.container.conf,v 1.8 2006/07/26 15:58:26 dts12 Exp $
1007+ */
1008+#ifndef HRSWRUNPERFTABLE_H
1009+#define HRSWRUNPERFTABLE_H
1010+
1011+config_require(host/hrSWRunTable)
1012+
1013+/*
1014+ * function declarations 
1015+ */
1016+void            init_hrSWRunPerfTable(void);
1017+void            initialize_table_hrSWRunPerfTable(void);
1018+Netsnmp_Node_Handler hrSWRunPerfTable_handler;
1019+
1020+/*
1021+ * column number definitions for table hrSWRunPerfTable 
1022+ */
1023+#define COLUMN_HRSWRUNPERFCPU		1
1024+#define COLUMN_HRSWRUNPERFMEM		2
1025+#endif                          /* HRSWRUNPERFTABLE_H */
1026diff -I '\$Id: ' -u -r -b -w -p -d --new-file --exclude-from=/Users/rstory/.rcfiles/diff-ignore SVN/agent/mibgroup/host/hrSWRunTable.c APPLE/agent/mibgroup/host/hrSWRunTable.c
1027--- SVN/agent/mibgroup/host/hrSWRunTable.c
1028+++ APPLE/agent/mibgroup/host/hrSWRunTable.c
1029@@ -0,0 +1,395 @@
1030+/*
1031+ * Note: this file originally auto-generated by mib2c using
1032+ *  : mib2c.container.conf,v 1.8 2006/07/26 15:58:26 dts12 Exp $
1033+ */
1034+
1035+#include <net-snmp/net-snmp-config.h>
1036+#include <net-snmp/net-snmp-includes.h>
1037+#include <net-snmp/agent/net-snmp-agent-includes.h>
1038+#include <net-snmp/agent/table_container.h>
1039+#include <net-snmp/data_access/swrun.h>
1040+#include <net-snmp/agent/cache_handler.h>
1041+#include "hrSWRunTable.h"
1042+
1043+#include <signal.h>
1044+
1045+#define MYTABLE "hrSWRunTable"
1046+
1047+static void _cache_free(netsnmp_cache * cache, void *magic);
1048+static int _cache_load(netsnmp_cache * cache, void *vmagic);
1049+
1050+/** Initializes the hrSWRunTable module */
1051+void
1052+init_hrSWRunTable(void)
1053+{
1054+    /*
1055+     * here we initialize all the tables we're planning on supporting 
1056+     */
1057+    initialize_table_hrSWRunTable();
1058+}
1059+
1060+oid      hrSWRunTable_oid[] = { 1, 3, 6, 1, 2, 1, 25, 4, 2 };
1061+size_t   hrSWRunTable_oid_len = OID_LENGTH(hrSWRunTable_oid);
1062+
1063+/** Initialize the hrSWRunTable table by defining its contents and how it's structured */
1064+void
1065+initialize_table_hrSWRunTable(void)
1066+{
1067+    netsnmp_handler_registration *reg;
1068+    netsnmp_mib_handler *handler = NULL;
1069+    netsnmp_container *container = NULL;
1070+    netsnmp_table_registration_info *table_info = NULL;
1071+    netsnmp_cache  *cache = NULL;
1072+
1073+#ifdef NETSNMP_INCLUDE_HRSWRUN_WRITE_SUPPORT
1074+#  define SWRUN_ACCESS_LEVEL HANDLER_CAN_RWRITE
1075+#else
1076+#  define SWRUN_ACCESS_LEVEL HANDLER_CAN_RONLY
1077+#endif
1078+    reg =
1079+        netsnmp_create_handler_registration(MYTABLE,
1080+                                            hrSWRunTable_handler,
1081+                                            hrSWRunTable_oid,
1082+                                            hrSWRunTable_oid_len,
1083+                                            SWRUN_ACCESS_LEVEL);
1084+    if (NULL == reg) {
1085+        snmp_log(LOG_ERR,"error creating handler registration for "
1086+                 MYTABLE "\n");
1087+        goto bail;
1088+    }
1089+    reg->modes |= HANDLER_CAN_NOT_CREATE;
1090+
1091+    container = netsnmp_container_find("hrSWRunTable:table_container");
1092+    if (NULL == container) {
1093+        snmp_log(LOG_ERR,"error creating container for " MYTABLE "\n");
1094+        goto bail;
1095+    }
1096+
1097+    table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
1098+    if (NULL == table_info) {
1099+        snmp_log(LOG_ERR,"error allocating table registration for "
1100+                 MYTABLE "\n");
1101+        goto bail;
1102+    }
1103+
1104+    netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER,   /* index: hrSWRunIndex */
1105+                                     0);
1106+    table_info->min_column = COLUMN_HRSWRUNINDEX;
1107+    table_info->max_column = COLUMN_HRSWRUNSTATUS;
1108+
1109+    /*************************************************
1110+     *
1111+     * inject container_table helper
1112+     */
1113+    handler = netsnmp_container_table_handler_get(table_info, container,
1114+                                                  TABLE_CONTAINER_KEY_NETSNMP_INDEX);
1115+    if (NULL == handler) {
1116+        snmp_log(LOG_ERR,"error allocating table registration for "
1117+                 MYTABLE "\n");
1118+        goto bail;
1119+    }
1120+    if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) {
1121+        snmp_log(LOG_ERR,"error injecting container_table handler for "
1122+                 MYTABLE "\n");
1123+        goto bail;
1124+    }
1125+    handler = NULL; /* reg has it, will reuse below */
1126+
1127+    /*************************************************
1128+     *
1129+     * inject cache helper
1130+     */
1131+    cache = netsnmp_cache_create(30,    /* timeout in seconds */
1132+                                 _cache_load, _cache_free,
1133+                                 hrSWRunTable_oid, hrSWRunTable_oid_len);
1134+
1135+    if (NULL == cache) {
1136+        snmp_log(LOG_ERR, "error creating cache for " MYTABLE "\n");
1137+        goto bail;
1138+    }
1139+    cache->flags = NETSNMP_CACHE_DONT_INVALIDATE_ON_SET;
1140+    cache->magic = container;
1141+
1142+    handler = netsnmp_cache_handler_get(cache);
1143+    if (NULL == handler) {
1144+        snmp_log(LOG_ERR, "error creating cache handler for " MYTABLE "\n");
1145+        goto bail;
1146+    }
1147+
1148+    if (SNMPERR_SUCCESS != netsnmp_inject_handler(reg, handler)) {
1149+        snmp_log(LOG_ERR,"error injecting cache handler for "
1150+                 MYTABLE "\n");
1151+        goto bail;
1152+    }
1153+    handler = NULL; /* reg has it*/
1154+
1155+    if (SNMPERR_SUCCESS != netsnmp_register_table(reg, table_info)) {
1156+        snmp_log(LOG_ERR,"error registering table handler for "
1157+                 MYTABLE "\n");
1158+        goto bail;
1159+    }
1160+
1161+    return; /* ok */
1162+
1163+
1164+  bail: /* not ok */
1165+    
1166+    if (handler)
1167+        netsnmp_handler_free(handler);
1168+
1169+    if (cache)
1170+        netsnmp_cache_free(cache);
1171+
1172+    if (table_info)
1173+        netsnmp_table_registration_info_free(table_info);
1174+
1175+    if (container)
1176+        CONTAINER_FREE(container);
1177+
1178+    if (reg) 
1179+        netsnmp_handler_registration_free(reg);
1180+
1181+}
1182+
1183+/** handles requests for the hrSWRunTable table */
1184+int
1185+hrSWRunTable_handler(netsnmp_mib_handler *handler,
1186+                     netsnmp_handler_registration *reginfo,
1187+                     netsnmp_agent_request_info *reqinfo,
1188+                     netsnmp_request_info *requests)
1189+{
1190+    netsnmp_request_info *request;
1191+    netsnmp_table_request_info *table_info;
1192+    netsnmp_swrun_entry *table_entry;
1193+
1194+    switch (reqinfo->mode) {
1195+        /*
1196+         * Read-support (also covers GetNext requests)
1197+         */
1198+    case MODE_GET:
1199+        for (request = requests; request; request = request->next) {
1200+            if (request->processed)
1201+               continue;
1202+            table_entry = (netsnmp_swrun_entry *)
1203+                netsnmp_container_table_extract_context(request);
1204+            table_info = netsnmp_extract_table_info(request);
1205+            if ((NULL == table_entry) || (NULL == table_info)) {
1206+                snmp_log(LOG_ERR, "could not extract table entry or info for "
1207+                 MYTABLE "\n");
1208+                snmp_set_var_typed_value(request->requestvb,
1209+                                         SNMP_ERR_GENERR, NULL, 0);
1210+                continue;
1211+            }
1212+
1213+            switch (table_info->colnum) {
1214+            case COLUMN_HRSWRUNINDEX:
1215+                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
1216+                                           table_entry->hrSWRunIndex);
1217+                break;
1218+            case COLUMN_HRSWRUNNAME:
1219+                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
1220+                                         (u_char *) table_entry->
1221+                                         hrSWRunName,
1222+                                         table_entry->hrSWRunName_len);
1223+                break;
1224+            case COLUMN_HRSWRUNID:
1225+                snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID,
1226+#ifdef NETSNMP_SWRUN_HAVE_ID
1227+                                         (u_char *) table_entry->hrSWRunID,
1228+                                         table_entry->hrSWRunID_len
1229+#else
1230+                                         (u_char *) &nullOid, nullOidLen
1231+#endif
1232+                    );
1233+                break;
1234+            case COLUMN_HRSWRUNPATH:
1235+                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
1236+                                         (u_char *) table_entry->
1237+                                         hrSWRunPath,
1238+                                         table_entry->hrSWRunPath_len);
1239+                break;
1240+            case COLUMN_HRSWRUNPARAMETERS:
1241+                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
1242+                                         (u_char *) table_entry->
1243+                                         hrSWRunParameters,
1244+                                         table_entry->
1245+                                         hrSWRunParameters_len);
1246+                break;
1247+            case COLUMN_HRSWRUNTYPE:
1248+                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
1249+                                           table_entry->hrSWRunType);
1250+                break;
1251+            case COLUMN_HRSWRUNSTATUS:
1252+                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
1253+                                           table_entry->hrSWRunStatus);
1254+                break;
1255+            default:
1256+                /*
1257+                 * An unsupported/unreadable column (if applicable) 
1258+                 */
1259+                snmp_set_var_typed_value(request->requestvb,
1260+                                         SNMP_NOSUCHOBJECT, NULL, 0);
1261+            }
1262+        }
1263+        break;
1264+
1265+#ifdef NETSNMP_INCLUDE_HRSWRUN_WRITE_SUPPORT
1266+        /*
1267+         * Write-support
1268+         */
1269+    case MODE_SET_RESERVE1:
1270+        for (request = requests; request; request = request->next) {
1271+            int pid;
1272+            if (request->processed)
1273+               continue;
1274+            table_entry = (netsnmp_swrun_entry *)
1275+                netsnmp_container_table_extract_context(request);
1276+            table_info = netsnmp_extract_table_info(request);
1277+            if ((NULL == table_entry) || (NULL == table_info)) {
1278+                snmp_log(LOG_ERR, "could not extract table entry or info for "
1279+                 MYTABLE "\n");
1280+                snmp_set_var_typed_value(request->requestvb,
1281+                                         SNMP_ERR_GENERR, NULL, 0);
1282+                continue;
1283+            }
1284+
1285+            switch (table_info->colnum) {
1286+            case COLUMN_HRSWRUNSTATUS:
1287+                if (*request->requestvb->val.integer != HRSWRUNSTATUS_INVALID) {
1288+                    netsnmp_set_request_error(reqinfo, request,
1289+                                              SNMP_ERR_WRONGVALUE);
1290+                    return SNMP_ERR_NOERROR;
1291+                }
1292+                pid = request->requestvb->name[request->requestvb->name_length-1];
1293+                if (1 == pid) {
1294+                    snmp_log(LOG_WARNING,"refusing to kill pid 1\n");
1295+                    netsnmp_set_request_error(reqinfo, request,
1296+                                              SNMP_ERR_NOACCESS);
1297+                    return SNMP_ERR_NOERROR;
1298+                }
1299+                break;
1300+            default:
1301+                netsnmp_set_request_error(reqinfo, request,
1302+                                          SNMP_ERR_NOTWRITABLE);
1303+                return SNMP_ERR_NOERROR;
1304+            }
1305+        }
1306+        break;
1307+
1308+    case MODE_SET_RESERVE2:
1309+        break;
1310+
1311+    case MODE_SET_FREE:
1312+        break;
1313+
1314+    case MODE_SET_ACTION:
1315+        for (request = requests; request; request = request->next) {
1316+            if (request->processed)
1317+               continue;
1318+            table_entry = (netsnmp_swrun_entry *)
1319+                netsnmp_container_table_extract_context(request);
1320+            table_info = netsnmp_extract_table_info(request);
1321+            if ((NULL == table_entry) || (NULL == table_info)) {
1322+                snmp_log(LOG_ERR, "could not extract table entry or info for "
1323+                 MYTABLE "\n");
1324+                snmp_set_var_typed_value(request->requestvb,
1325+                                         SNMP_ERR_GENERR, NULL, 0);
1326+                continue;
1327+            }
1328+
1329+            switch (table_info->colnum) {
1330+            case COLUMN_HRSWRUNSTATUS:
1331+                table_entry->old_hrSWRunStatus =
1332+                    table_entry->hrSWRunStatus;
1333+                table_entry->hrSWRunStatus =
1334+                    *request->requestvb->val.integer;
1335+                break;
1336+            }
1337+        }
1338+        break;
1339+
1340+    case MODE_SET_UNDO:
1341+        for (request = requests; request; request = request->next) {
1342+            if (request->processed)
1343+               continue;
1344+            container = netsnmp_container_table_extract_context(request);
1345+            table_entry = (netsnmp_swrun_entry *)
1346+                netsnmp_container_table_extract_context(request);
1347+            table_info = netsnmp_extract_table_info(request);
1348+            if ((NULL == table_entry) || (NULL == table_info)) {
1349+                snmp_log(LOG_ERR, "could not extract table entry or info for "
1350+                 MYTABLE "\n");
1351+                snmp_set_var_typed_value(request->requestvb,
1352+                                         SNMP_ERR_GENERR, NULL, 0);
1353+                continue;
1354+            }
1355+
1356+            switch (table_info->colnum) {
1357+            case COLUMN_HRSWRUNSTATUS:
1358+                table_entry->hrSWRunStatus =
1359+                    table_entry->old_hrSWRunStatus;
1360+                table_entry->old_hrSWRunStatus = 0;
1361+                break;
1362+            }
1363+        }
1364+        break;
1365+
1366+    case MODE_SET_COMMIT:
1367+        for (request = requests; request; request = request->next) {
1368+            int pid;
1369+            if (request->processed)
1370+               continue;
1371+            pid = request->requestvb->name[request->requestvb->name_length-1];
1372+            DEBUGMSGTL(("hrSWRunTable:commit", "kill(%d,TERM)\n", pid));
1373+            kill(pid, SIGTERM);
1374+        }
1375+        break;
1376+#endif /* NETSNMP_INCLUDE_HRSWRUN_WRITE_SUPPORT */
1377+    }
1378+    return SNMP_ERR_NOERROR;
1379+}
1380+
1381+/***********************************************************************
1382+ *
1383+ * DATA ACCESS
1384+ *
1385+ * The data access mechanism here is rather simple: let newsnmp_swrun_*
1386+ * take care of it.
1387+ ***********************************************************************/
1388+/**
1389+ * @internal
1390+ */
1391+static int
1392+_cache_load(netsnmp_cache * cache, void *vmagic)
1393+{
1394+    DEBUGMSGTL(("internal:hrSWRunTable:_cache_load", "called\n"));
1395+
1396+    if ((NULL == cache) || (NULL == cache->magic)) {
1397+        snmp_log(LOG_ERR, "invalid cache for hrSWRunTable_cache_load\n");
1398+        return -1;
1399+    }
1400+
1401+    /** should only be called for an invalid or expired cache */
1402+    netsnmp_assert((0 == cache->valid) || (1 == cache->expired));
1403+
1404+    cache->magic =
1405+        netsnmp_swrun_container_load((netsnmp_container *) cache->magic,
1406+                                            0);
1407+    return 0;
1408+}                               /* _cache_load */
1409+
1410+/**
1411+ * @internal
1412+ */
1413+static void
1414+_cache_free(netsnmp_cache * cache, void *magic)
1415+{
1416+    DEBUGMSGTL(("internal:hrSWRunTable:_cache_free", "called\n"));
1417+
1418+    if ((NULL == cache) || (NULL == cache->magic)) {
1419+        snmp_log(LOG_ERR, "invalid cache in hrSWRunTable_cache_free\n");
1420+        return;
1421+    }
1422+
1423+    netsnmp_swrun_container_free_items((netsnmp_container *) cache->magic);
1424+}                               /* _cache_free */
1425diff -I '\$Id: ' -u -r -b -w -p -d --new-file --exclude-from=/Users/rstory/.rcfiles/diff-ignore SVN/agent/mibgroup/host/hrSWRunTable.h APPLE/agent/mibgroup/host/hrSWRunTable.h
1426--- SVN/agent/mibgroup/host/hrSWRunTable.h
1427+++ APPLE/agent/mibgroup/host/hrSWRunTable.h
1428@@ -0,0 +1,27 @@
1429+/*
1430+ * Note: this file originally auto-generated by mib2c using
1431+ *  : mib2c.container.conf,v 1.8 2006/07/26 15:58:26 dts12 Exp $
1432+ */
1433+#ifndef HRSWRUNTABLE_H
1434+#define HRSWRUNTABLE_H
1435+
1436+config_require(host/data_access/swrun)
1437+
1438+/*
1439+ * function declarations 
1440+ */
1441+void            init_hrSWRunTable(void);
1442+void            initialize_table_hrSWRunTable(void);
1443+Netsnmp_Node_Handler hrSWRunTable_handler;
1444+
1445+/*
1446+ * column number definitions for table hrSWRunTable 
1447+ */
1448+#define COLUMN_HRSWRUNINDEX		1
1449+#define COLUMN_HRSWRUNNAME		2
1450+#define COLUMN_HRSWRUNID		3
1451+#define COLUMN_HRSWRUNPATH		4
1452+#define COLUMN_HRSWRUNPARAMETERS		5
1453+#define COLUMN_HRSWRUNTYPE		6
1454+#define COLUMN_HRSWRUNSTATUS		7
1455+#endif                          /* HRSWRUNTABLE_H */
1456diff -I '\$Id: ' -u -r -b -w -p -d --new-file --exclude-from=/Users/rstory/.rcfiles/diff-ignore SVN/include/net-snmp/data_access/swrun.h APPLE/include/net-snmp/data_access/swrun.h
1457--- SVN/include/net-snmp/data_access/swrun.h
1458+++ APPLE/include/net-snmp/data_access/swrun.h
1459@@ -0,0 +1,90 @@
1460+#ifndef NETSNMP_SWRUN_H
1461+#define NETSNMP_SWRUN_H
1462+
1463+#ifdef  __cplusplus
1464+extern "C" {
1465+#endif
1466+
1467+
1468+    /*-*****************************************************************
1469+     *
1470+     * Data structure for a row entry 
1471+     */
1472+    typedef struct hrSWRunTable_entry {
1473+        netsnmp_index   oid_index;
1474+        
1475+        /*
1476+         * Index values 
1477+         */
1478+        oid             hrSWRunIndex;
1479+        
1480+        /*
1481+         * Column values 
1482+         */
1483+        char            hrSWRunName[65]; /* size per MIB + 1 */
1484+        char            hrSWRunPath[129]; /* size per MIB + 1 */
1485+        char            hrSWRunParameters[129]; /* size per MIB + 1 */
1486+#ifdef NETSNMP_SWRUN_HAVE_ID  /* if not defined, will always use nullOid */
1487+        oid             hrSWRunID[128];
1488+        u_char          hrSWRunID_len;
1489+#endif
1490+        u_char          hrSWRunName_len;
1491+        u_char          hrSWRunPath_len;
1492+        u_char          hrSWRunParameters_len;
1493+
1494+        u_char          hrSWRunType;
1495+        u_char          hrSWRunStatus;
1496+        u_char          old_hrSWRunStatus;
1497+
1498+        /*
1499+         * Perf values
1500+         */
1501+        int32_t         hrSWRunPerfCPU;
1502+        int32_t         hrSWRunPerfMem;
1503+        
1504+    } netsnmp_swrun_entry;
1505+
1506+    /*
1507+     * enums for column hrSWRunType
1508+     */
1509+#define HRSWRUNTYPE_UNKNOWN             1
1510+#define HRSWRUNTYPE_OPERATINGSYSTEM     2
1511+#define HRSWRUNTYPE_DEVICEDRIVER        3
1512+#define HRSWRUNTYPE_APPLICATION         4
1513+
1514+    /*
1515+     * enums for column hrSWRunStatus
1516+     */
1517+#define HRSWRUNSTATUS_RUNNING           1
1518+#define HRSWRUNSTATUS_RUNNABLE          2
1519+#define HRSWRUNSTATUS_NOTRUNNABLE       3
1520+#define HRSWRUNSTATUS_INVALID           4
1521+
1522+    /*-*****************************************************************
1523+     *
1524+     * Prototypes
1525+     */
1526+    netsnmp_container *
1527+    netsnmp_swrun_container_load(netsnmp_container *container, u_int flags );
1528+
1529+    void netsnmp_swrun_container_free(netsnmp_container *container, u_int flags);
1530+    void netsnmp_swrun_container_free_items(netsnmp_container * container);
1531+
1532+    netsnmp_swrun_entry *
1533+    netsnmp_swrun_entry_create(int32_t swIndex);
1534+
1535+    void netsnmp_swrun_entry_free(netsnmp_swrun_entry *entry);
1536+
1537+#define NETSNMP_SWRUN_NOFLAGS            0x00000000
1538+#define NETSNMP_SWRUN_ALL_OR_NONE        0x00000001
1539+#define NETSNMP_SWRUN_DONT_FREE_ITEMS    0x00000002
1540+/*#define NETSNMP_SWRUN_xx                0x00000004 */
1541+
1542+#ifdef  __cplusplus
1543+}
1544+#endif
1545+
1546+
1547+#endif /* NETSNMP_SWRUN_H */
1548+
1549+
1550