Re: Segmentation fault problem

"Miljen Mikić" <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
Thank you for your help, but unfortunately it didnt solve the problem. I put
HANDLER_CAN_RONLY (HANDLER_CAN_READ causes compile-time error) but there is
still segmentation fault.
There are two things that are maybe interesting to mention:

1) Segmentation fault arises even if I avoid handlers, for instance this
code snippet also suffers from the same problem:

void sm_sessions_register()
{
        int retval;

        retval = netsnmp_register_int_instance("Example1", // --> THIS IS
LINE 479!
                                session_oid,
                                OID_LENGTH(session_oid),
                                &demo_int, NULL);

        if(retval == MIB_REGISTERED_OK)
                snmp_log(LOG_INFO,"Variable registered\n");

        retval = netsnmp_register_int_instance("Example2",
                                session_oid2,
                                OID_LENGTH(session_oid2),
                                &demo_int2, NULL);

        if(retval == MIB_REGISTERED_OK)
                snmp_log(LOG_INFO,"Variable2 registered\n");
}

Demo_int and demo_int2 are globals. Backtrace is now more detailed because I
have included CFLAGS=-ggdb before running ./configure of net-snmp:

(gdb) bt
#0  0x00a75b49 in snmp_resend_request (slp=0xb08e1ff0, rp=0xab63dfcc,
    incr_retries=1) at snmp_api.c:6137
#1  0x00a75e62 in snmp_sess_timeout (sessp=0xb08e1ff0) at snmp_api.c:6224
#2  0x00a75568 in snmp_timeout () at snmp_api.c:6018
#3  0x00a465ee in snmp_synch_response_cb (ss=0xb089df08, pdu=0xb0855f70,
    response=0xacb20198, pcb=0x35eaac <agentx_synch_input>)
    at snmp_client.c:1020
#4  0x0035ed55 in agentx_synch_response (ss=0xb089df08, pdu=0xb0855f70,
    response=0xacb20198) at mibgroup/agentx/client.c:112
#5  0x0035f410 in agentx_register (ss=0xb089df08, start=0xb0837fdc,
    startlen=9, priority=127, range_subid=0, range_ubound=0, timeout=0,
    flags=1 '\001', contextName=0x0) at mibgroup/agentx/client.c:220
#6  0x0034c94a in agentx_registration_callback (majorID=1, minorID=1,
    serverarg=0xacb20288, clientarg=0xb089df08)
    at mibgroup/agentx/subagent.c:624
#7  0x00a97ff7 in snmp_call_callbacks (major=1, minor=1,
caller_arg=0xacb20288)
    at callback.c:329
#8  0x0033ff7b in netsnmp_register_mib (moduleName=0xb0835ff0 "Example1",
    var=0x0, varsize=0, numvars=0, mibloc=0xb0837fdc, mibloclen=9,
    priority=127, range_subid=0, range_ubound=0, ss=0x0, context=0x0,
    timeout=0, flags=1, reginfo=0xb0833fd0, perform_callback=1)
    at agent_registry.c:731
#9  0x003464b0 in netsnmp_register_handler (reginfo=0xb0833fd0)
---Type <return> to continue, or q <return> to quit---
    at agent_handler.c:255
#10 0x002f8191 in netsnmp_register_serialize (reginfo=0xb0833fd0)
    at serialize.c:43
#11 0x002f3000 in netsnmp_register_instance (reginfo=0xb0833fd0)
    at instance.c:78
#12 0x002f39f2 in netsnmp_register_int_instance (
    name=0x8094a4c "Session state", reg_oid=0x80aa7a0, reg_oid_len=9,
    it=0x80aa7c4, subhandler=0) at instance.c:469
#13 0x0806897f in sm_sessions_register () at sm.c:479
#14 0x0806e00f in sm_main_thread (data=0xbfdae4a8) at sm.c:7778
#15 0x00c1a8ef in g_thread_create_full () from /usr/lib/libglib-2.0.so.0
#16 0x001c43b6 in start_thread () from /lib/libpthread.so.0
#17 0x008af33e in clone () from /lib/libc.so.6

I am also confused why is function snmp_resend_request() even been called..

2) I have mentioned that I get segmentation fault occasionally, not always.
The circumstances are specific:
- my program registers several variables and then I do few snmpwalks
(program is still active, it acts as a agentx subagent)
- after that, my program tries to register few more variables (see the code
above) and THEN I get segmentation fault

Again, I would highly appreciate any help.

Miljen

2008/7/11 Syed Mujtaba Ahmed Razvi <[email protected]>:

>
>
> Miljen, I think your code snippet is trying to access a memory location
> that it is not allowed to access. For e.g. you might be writing some illegal
> location using some pointer (may be one of them my_test,my_test2). Try
> changing the HANDLER_CAN_RWRITE in the declaration portion to
> HANDLER_CAN_READ (in both). Your pointers might be trying to access
> eachothers location.
>
>
>
> Hope it helps!
>
> Regards,
>
> Syed Mujtaba
>
> ------------------------------
> Date: Fri, 11 Jul 2008 15:52:31 +0200
> From: [email protected]
> To: [email protected]
> Subject: Segmentation fault problem
>
>
> Hi everyone,
>
> I am trying to add SNMP support in the IKEv2 project (
> http://sourceforge.net/projects/ikev2) and I am using net-snmp, 5.4.1.
>
> Firstly, there is a great number of variables which I plan to register. I
> am wondering whether is possible (or harmful) to use one oid variable as:
> oid session_oid[] = {.., 13, 1};
> and then change last element of this array (to 2,3,..etc.) before
> registering different variables? The alternative is to declare and use
> different oid array for each variable that I want to register.
>
> More importantly, there is a problem which gives me a headache - a
> segmentation fault occasionally happens. Here is a backtrace:
> (gdb) bt
> #0  0x080fc3e1 in snmp_sess_timeout ()
> #1  0x080fc579 in snmp_timeout ()
> #2  0x080d8cb5 in snmp_synch_response_cb ()
> #3  0x080c9f57 in agentx_synch_response ()
> #4  0x080ca702 in agentx_register ()
> #5  0x080ba735 in agentx_registration_callback ()
> #6  0x0811c0c9 in snmp_call_callbacks ()
> #7  0x080ab5b2 in netsnmp_register_mib ()
> #8  0x080b04cd in netsnmp_register_handler ()
> #9  0x080793aa in sm_sessions_register () at sm.c:441
> #10 0x0807e93f in sm_main_thread (data=0xbfd33c28) at sm.c:7778
> #11 0x00c1a8ef in g_thread_create_full () from /usr/lib/libglib-2.0.so.0
> #12 0x001b53b6 in start_thread () from /lib/libpthread.so.0
> #13 0x00b2933e in clone () from /lib/libc.so.6
>
> Function sm_sessions_register() is defined as:
>
> void sm_sessions_register()
> {
>         netsnmp_handler_registration *my_test;
>         netsnmp_handler_registration *my_test2;
>
>         my_test =
>                netsnmp_create_handler_registration("example",
>                                                 sm_sess_handle,
>                                                 session_oid,
>                                                 OID_LENGTH(session_oid),
>                                                 HANDLER_CAN_RWRITE);
>
>         netsnmp_register_instance(my_test); // --> THIS IS LINE 441!
>
>         my_test2 =
>                 netsnmp_create_handler_registration("example2",
>                                                 sm_sess_handle,
>                                                 session_oid2,
>                                                 OID_LENGTH(session_oid2),
>                                                 HANDLER_CAN_RWRITE);
>
>         netsnmp_register_instance(my_test2);
> }
>
> session_oid and session_oid2 are defined as:
>
> oid session_oid[] = { 1, 3, 6, 1, 3, 411249, 13, 2, 1 };
> oid session_oid2[] = { 1, 3, 6, 1, 3, 411249, 13, 2, 2 };
>
> and they are globals. Sm_sess_handle is written by example in your tutorial
> (delayed_instance.c) and I can include this code also if necessary.
>
> I would be very grateful for any help or hint!
>
> Miljen
>
> ------------------------------
> Connect to the next generation of MSN Messenger  Get it now!
> <http://imagine-msn.com/messenger/launch80/default.aspx?locale=en-us&source=wlmailtagline>
>

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08

_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.