Commit 41495c78 authored by Adam Wujek's avatar Adam Wujek 💬

userspace/snmpd: bugfix remove printing extra item at the end of table

At the end of pstats and ppsi tables extra item was printed. 0 or null as an
output from function netsnmp_extract_iterator_context shall be interpreted as
no more elements instead of element 0 as it was so far.

Fixed ppsi and pstats tables.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 82089655
......@@ -564,12 +564,6 @@ but sooner or later I'll fix it. As a side effect, I now use
the two contexts concurrently in an ambiguous way. No, I'm not
proud of this code.
I don't feel confident with all the data structures as yet, and there
still is some magic in all of this. This is confirmed by a buglet in
the current code, that makes @i{snmpwalk} always return one item after
the end of the table -- most likely I need to fix @t{next_entry()}
to return @t{NULL} earlier.
@c =========================================================================
@node wrsPpsi
@section wrsPpsi
......
......@@ -342,8 +342,10 @@ ppsi_p_next_entry(void **loop_context,
/* Create the row OID: only the counter index */
snmp_set_var_value(index, (u_char *)&i, sizeof(i));
/* Set the data context (1..4 -> 0..3) */
*data_context = (void *)(intptr_t)(i - 1);
/* Set the data context (1..4)
* Cannot be set to 0, because netsnmp_extract_iterator_context returns
* NULL in function wrsPstats_handler when table is over */
*data_context = (void *)i;
/* and set the loop context for the next iteration */
*loop_context = (void *)i;
return index;
......@@ -410,6 +412,14 @@ ppsi_p_handler(netsnmp_mib_handler *handler,
/* "context" is the port number */
wrport = (intptr_t)netsnmp_extract_iterator_context(request);
if (!wrport)
/* NULL returned from
* netsnmp_extract_iterator_context shuld be
* interpreted as end of table */
break;
/* change range of wrport (1..4 (snmp is 1 based) ->
* 0..3 (wrs_p_array/data array is 0 based)) */
wrport--;
table_info = netsnmp_extract_table_info(request);
subid = table_info->colnum - 1;
......
......@@ -57,9 +57,18 @@ wrsPstats_handler(netsnmp_mib_handler *handler,
logmsg("%s: %i\n", __func__, __LINE__);
/* our "context" is the counter number; "subid" the column i.e. the port */
counter = (intptr_t)netsnmp_extract_iterator_context(request);
if (!counter)
/* NULL returned from
* netsnmp_extract_iterator_context shuld be
* interpreted as end of table */
continue;
/* change range of counter (1..39 (snmp is 1 based) ->
* 0..38 (pstats_global_data array is 0 based)) */
counter--;
table_info = netsnmp_extract_table_info(request);
wrport = table_info->colnum - 2; /* port is 0-based and position 1 is the string */
/* port is 0-based and position 1 is the string */
wrport = table_info->colnum - 2;
logmsg("counter %i, port %i\n", counter, wrport);
if (wrport < 0) {
......@@ -110,8 +119,10 @@ wrsPstats_next_entry(void **loop_context,
/* Create the row OID: only the counter index */
snmp_set_var_value(index, (u_char *)&i, sizeof(i));
/* Set the data context (1..39 -> 0..38) */
*data_context = (void *)(intptr_t)(i - 1);
/* Set the data context (1..39)
* Cannot be set to 0, because netsnmp_extract_iterator_context returns
* NULL in function wrsPstats_handler when table is over */
*data_context = (void *)i;
/* and set the loop context for the next iteration */
*loop_context = (void *)i;
return index;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment