]> git.pld-linux.org Git - packages/net-snmp.git/blobdiff - net-snmp-loadave-writable.patch
- release 5
[packages/net-snmp.git] / net-snmp-loadave-writable.patch
index 9c2e5e18c1dc1083e31962221b29f84d095c2780..196f9735e0f4e7872cd9cf882eb82f6d53c70a56 100644 (file)
@@ -1,35 +1,56 @@
---- net-snmp-5.4.2.1/agent/mibgroup/ucd-snmp/loadave.c~        2009-12-21 21:00:10.094254079 +0200
-+++ net-snmp-5.4.2.1/agent/mibgroup/ucd-snmp/loadave.c 2009-12-21 22:02:45.398903148 +0200
-@@ -137,6 +137,15 @@
- double          maxload[3];
+This patch makes "load X Y Z" snmpsettable via snmpset,
+
+it behaves the same as sysName.0, once written in snmpd.conf, it becames
+readonly.
+
+Signed-off-by: Elan Ruusamäe <glen@delfi.ee>
+Upstream-Tracker: https://sourceforge.net/tracker/?func=detail&aid=2931446&group_id=12694&atid=312694
+
+--- net-snmp/agent/mibgroup/ucd-snmp/loadave.c 2010/07/29 14:58:47     19264
++++ net-snmp/agent/mibgroup/ucd-snmp/loadave.c 2010/08/11 22:07:58     19294
+@@ -128,7 +128,19 @@
+ #include "util_funcs/header_simple_table.h"
+ #include "kernel.h"
  
+-double          maxload[3];
++static double maxload[3];
++static int laConfigSet = 0;
++
 +static int
 +loadave_store_config(int a, int b, void *c, void *d)
 +{
 +    char line[SNMP_MAXBUF_SMALL];
-+    snprintf(line, SNMP_MAXBUF_SMALL, "load %.02f %.02f %.02f", maxload[0], maxload[1], maxload[2]);
-+    snmpd_store_config(line);
++    if (laConfigSet > 0) {
++        snprintf(line, SNMP_MAXBUF_SMALL, "pload %.02f %.02f %.02f", maxload[0], maxload[1], maxload[2]);
++        snmpd_store_config(line);
++    }
 +    return SNMPERR_SUCCESS;
 +}
-+
  void
  init_loadave(void)
- {
-@@ -152,7 +161,7 @@
-          {ERRORNAME}},
-         {LOADAVE, ASN_OCTET_STR, RONLY, var_extensible_loadave, 1,
-          {LOADAVE}},
--        {LOADMAXVAL, ASN_OCTET_STR, RONLY, var_extensible_loadave, 1,
-+        {LOADMAXVAL, ASN_OCTET_STR, RWRITE, var_extensible_loadave, 1,
-          {LOADMAXVAL}},
-         {LOADAVEINT, ASN_INTEGER, RONLY, var_extensible_loadave, 1,
-          {LOADAVEINT}},
-@@ -182,6 +191,14 @@
+@@ -145,7 +157,7 @@
+          var_extensible_loadave, 1, {ERRORNAME}},
+         {LOADAVE, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
+          var_extensible_loadave, 1, {LOADAVE}},
+-        {LOADMAXVAL, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
++        {LOADMAXVAL, ASN_OCTET_STR, NETSNMP_OLDAPI_RWRITE,
+          var_extensible_loadave, 1, {LOADMAXVAL}},
+         {LOADAVEINT, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
+          var_extensible_loadave, 1, {LOADAVEINT}},
+@@ -172,9 +184,22 @@
+     REGISTER_MIB("ucd-snmp/loadave", extensible_loadave_variables,
+                  variable2, loadave_variables_oid);
++    laConfigSet = 0;
++
      snmpd_register_config_handler("load", loadave_parse_config,
                                    loadave_free_config,
                                    "max1 [max5] [max15]");
 +
++    snmpd_register_config_handler("pload",
++                                  loadave_parse_config, NULL, NULL);
++
 +
 +    /*
 +     * we need to be called back later
  }
  
  void
-@@ -309,6 +326,63 @@
+@@ -182,6 +207,25 @@
+ {
+     int             i;
++    if (strcmp(token, "pload") == 0) {
++        if (laConfigSet < 0) {
++            snmp_log(LOG_WARNING,
++                     "ignoring attempted override of read-only load\n");
++            return;
++        } else {
++            laConfigSet++;
++        }
++    } else {
++        if (laConfigSet > 0) {
++            snmp_log(LOG_WARNING,
++                     "ignoring attempted override of read-only load\n");
++            /*
++             * Fall through and copy in this value.
++             */
++        }
++        laConfigSet = -1;
++    }
++
+     for (i = 0; i <= 2; i++) {
+         if (cptr != NULL)
+             maxload[i] = atof(cptr);
+@@ -307,6 +351,71 @@
      return 0;
  }
  
 +    static double laConfig = 0;
 +
 +    switch (action) {
-+    case RESERVE1:
++    case RESERVE1: /* Check values for acceptability */
 +        if (var_val_type != ASN_OCTET_STR) {
 +            DEBUGMSGTL(("ucd-snmp/loadave",
 +                        "write to laConfig not ASN_OCTET_STR\n"));
 +                        "write to laConfig: bad length\n"));
 +            return SNMP_ERR_WRONGLENGTH;
 +        }
++
++        if (laConfigSet < 0) {
++            /*
++             * The object is set in a read-only configuration file.
++             */
++            return SNMP_ERR_NOTWRITABLE;
++        }
 +        break;
 +
-+    case RESERVE2:
++    case RESERVE2: /* Allocate memory and similar resources */
 +        {
 +            u_char buf[8];
 +            int old_errno = errno;
 +        {
 +            int idx = name[name_len - 1] - 1;
 +            maxload[idx] = laConfig;
++            laConfigSet = 1;
 +        }
 +    }
 +
  u_char         *
  var_extensible_loadave(struct variable * vp,
                         oid * name,
-@@ -328,6 +402,10 @@
+@@ -326,6 +435,10 @@
      case MIBINDEX:
          long_ret = name[*length - 1];
          return ((u_char *) (&long_ret));
This page took 0.06582 seconds and 4 git commands to generate.