]> git.pld-linux.org Git - packages/net-snmp.git/blob - net-snmp-loadave-writable.patch
- added %dir %{_datadir}/snmp to -libs; -devel and -snmptrapd require it;
[packages/net-snmp.git] / net-snmp-loadave-writable.patch
1 --- net-snmp-5.4.2.1/agent/mibgroup/ucd-snmp/loadave.c~ 2009-12-21 21:00:10.094254079 +0200
2 +++ net-snmp-5.4.2.1/agent/mibgroup/ucd-snmp/loadave.c  2009-12-21 22:02:45.398903148 +0200
3 @@ -135,7 +135,19 @@
4  #include "util_funcs.h"
5  #include "kernel.h"
6  
7 -double          maxload[3];
8 +static double maxload[3];
9 +static int laConfigSet = 0;
10 +
11 +static int
12 +loadave_store_config(int a, int b, void *c, void *d)
13 +{
14 +    char line[SNMP_MAXBUF_SMALL];
15 +    if (laConfigSet > 0) {
16 +        snprintf(line, SNMP_MAXBUF_SMALL, "pload %.02f %.02f %.02f", maxload[0], maxload[1], maxload[2]);
17 +        snmpd_store_config(line);
18 +    }
19 +    return SNMPERR_SUCCESS;
20 +}
21  
22  void
23  init_loadave(void)
24 @@ -152,7 +164,7 @@
25           {ERRORNAME}},
26          {LOADAVE, ASN_OCTET_STR, RONLY, var_extensible_loadave, 1,
27           {LOADAVE}},
28 -        {LOADMAXVAL, ASN_OCTET_STR, RONLY, var_extensible_loadave, 1,
29 +        {LOADMAXVAL, ASN_OCTET_STR, RWRITE, var_extensible_loadave, 1,
30           {LOADMAXVAL}},
31          {LOADAVEINT, ASN_INTEGER, RONLY, var_extensible_loadave, 1,
32           {LOADAVEINT}},
33 @@ -179,9 +191,22 @@
34      REGISTER_MIB("ucd-snmp/loadave", extensible_loadave_variables,
35                   variable2, loadave_variables_oid);
36  
37 +    laConfigSet = 0;
38 +
39      snmpd_register_config_handler("load", loadave_parse_config,
40                                    loadave_free_config,
41                                    "max1 [max5] [max15]");
42 +
43 +    snmpd_register_config_handler("pload",
44 +                                  loadave_parse_config, NULL, NULL);
45 +
46 +
47 +    /*
48 +     * we need to be called back later
49 +     */
50 +    snmp_register_callback(SNMP_CALLBACK_LIBRARY, SNMP_CALLBACK_STORE_DATA,
51 +                                       loadave_store_config, NULL);
52 +
53  }
54  
55  void
56 @@ -189,6 +214,25 @@
57  {
58      int             i;
59  
60 +    if (strcmp(token, "pload") == 0) {
61 +        if (laConfigSet < 0) {
62 +            snmp_log(LOG_WARNING,
63 +                     "ignoring attempted override of read-only load\n");
64 +            return;
65 +        } else {
66 +            laConfigSet++;
67 +        }
68 +    } else {
69 +        if (laConfigSet > 0) {
70 +            snmp_log(LOG_WARNING,
71 +                     "ignoring attempted override of read-only load\n");
72 +            /*
73 +             * Fall through and copy in this value.
74 +             */
75 +        }
76 +        laConfigSet = -1;
77 +    }
78 +
79      for (i = 0; i <= 2; i++) {
80          if (cptr != NULL)
81              maxload[i] = atof(cptr);
82 @@ -309,6 +353,71 @@
83      return 0;
84  }
85  
86 +static int
87 +write_laConfig(int action,
88 +                          u_char * var_val,
89 +                          u_char var_val_type,
90 +                          size_t var_val_len,
91 +                          u_char * statP, oid * name, size_t name_len)
92 +{
93 +    static double laConfig = 0;
94 +
95 +    switch (action) {
96 +    case RESERVE1: /* Check values for acceptability */
97 +        if (var_val_type != ASN_OCTET_STR) {
98 +            DEBUGMSGTL(("ucd-snmp/loadave",
99 +                        "write to laConfig not ASN_OCTET_STR\n"));
100 +            return SNMP_ERR_WRONGTYPE;
101 +        }
102 +        if (var_val_len > 8 || var_val_len <= 0) {
103 +            DEBUGMSGTL(("ucd-snmp/loadave",
104 +                        "write to laConfig: bad length\n"));
105 +            return SNMP_ERR_WRONGLENGTH;
106 +        }
107 +
108 +        if (laConfigSet < 0) {
109 +            /*
110 +             * The object is set in a read-only configuration file.
111 +             */
112 +            return SNMP_ERR_NOTWRITABLE;
113 +        }
114 +        break;
115 +
116 +    case RESERVE2: /* Allocate memory and similar resources */
117 +        {
118 +            u_char buf[8];
119 +            int old_errno = errno;
120 +            double val;
121 +            char *endp;
122 +
123 +            strncpy(buf, var_val, var_val_len);
124 +            buf[var_val_len] = '\0';
125 +            val = strtod(buf, &endp);
126 +
127 +            if (errno == ERANGE || *endp != '\0' || val < 0 || val > 65536.00) {
128 +                errno = old_errno;
129 +                DEBUGMSGTL(("ucd-snmp/loadave",
130 +                            "write to laConfig: invalid value\n"));
131 +                return SNMP_ERR_WRONGVALUE;
132 +            }
133 +
134 +            errno = old_errno;
135 +
136 +            laConfig = val;
137 +        }
138 +        break;
139 +
140 +    case COMMIT:
141 +        {
142 +            int idx = name[name_len - 1] - 1;
143 +            maxload[idx] = laConfig;
144 +            laConfigSet = 1;
145 +        }
146 +    }
147 +
148 +    return SNMP_ERR_NOERROR;
149 +}
150 +
151  u_char         *
152  var_extensible_loadave(struct variable * vp,
153                         oid * name,
154 @@ -328,6 +437,10 @@
155      case MIBINDEX:
156          long_ret = name[*length - 1];
157          return ((u_char *) (&long_ret));
158 +    case LOADMAXVAL:
159 +        /* setup write method, but don't return yet */
160 +        *write_method = write_laConfig;
161 +        break;
162      case ERRORNAME:
163          sprintf(errmsg, "Load-%d", ((name[*length - 1] == 1) ? 1 :
164                                      ((name[*length - 1] == 2) ? 5 : 15)));
This page took 0.035271 seconds and 3 git commands to generate.