Skip to content

Commit 05b7d79

Browse files
committed
Save and restore libsnmp environment between requests
1 parent ced1410 commit 05b7d79

1 file changed

Lines changed: 37 additions & 2 deletions

File tree

ext/snmp/snmp.c

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ typedef struct snmp_session php_snmp_session;
9191
} \
9292
}
9393

94+
static php_snmp_object saved_snmp_settings;
95+
static int saved_mib_allow_underscores;
96+
static int saved_mib_comment_term;
97+
static int saved_mib_replace;
98+
9499
ZEND_DECLARE_MODULE_GLOBALS(snmp)
95100
static PHP_GINIT_FUNCTION(snmp);
96101

@@ -2316,6 +2321,36 @@ PHP_MSHUTDOWN_FUNCTION(snmp)
23162321
}
23172322
/* }}} */
23182323

2324+
/* {{{ PHP_INIT_FUNCTION */
2325+
static PHP_RINIT_FUNCTION(snmp)
2326+
{
2327+
// Save the output options
2328+
save_snmplib_output_options(&saved_snmp_settings);
2329+
2330+
// Save the MIB options
2331+
saved_mib_allow_underscores = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIB_PARSE_LABEL);
2332+
saved_mib_comment_term = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIB_COMMENT_TERM);
2333+
saved_mib_replace = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIB_REPLACE);
2334+
2335+
return SUCCESS;
2336+
}
2337+
/* }}} */
2338+
2339+
/* {{{ PHP_RSHUTDOWN_FUNCTION */
2340+
static PHP_RSHUTDOWN_FUNCTION(snmp)
2341+
{
2342+
// Restore the output options
2343+
set_snmplib_output_options(&saved_snmp_settings);
2344+
2345+
// Restore MIB options
2346+
netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIB_PARSE_LABEL, saved_mib_allow_underscores);
2347+
netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIB_COMMENT_TERM, saved_mib_comment_term);
2348+
netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_MIB_REPLACE, saved_mib_replace);
2349+
2350+
return SUCCESS;
2351+
}
2352+
/* }}} */
2353+
23192354
/* {{{ PHP_MINFO_FUNCTION */
23202355
PHP_MINFO_FUNCTION(snmp)
23212356
{
@@ -2342,8 +2377,8 @@ zend_module_entry snmp_module_entry = {
23422377
ext_functions,
23432378
PHP_MINIT(snmp),
23442379
PHP_MSHUTDOWN(snmp),
2345-
NULL,
2346-
NULL,
2380+
PHP_RINIT(snmp),
2381+
PHP_RSHUTDOWN(snmp),
23472382
PHP_MINFO(snmp),
23482383
PHP_SNMP_VERSION,
23492384
PHP_MODULE_GLOBALS(snmp),

0 commit comments

Comments
 (0)