epics-modules / autosave

APS BCDA synApps module: autosave
https://epics-modules.github.io/autosave/
Other
8 stars 31 forks source link

Segfault when `set_savefile_name` is called before `create_monitor_set` #54

Open ericonr opened 1 year ago

ericonr commented 1 year ago
Apr 24 13:55:57 de-23rabpm-co-iocsrv runFOFB.sh[21985]: set_savefile_name("fofb_ioc.req", "DE-23SL11:BS-FOFBCtrl:_settings.sav")
Apr 24 13:55:57 de-23rabpm-co-iocsrv runFOFB.sh[21985]: < "iocBoot/iocutca/autosave_post.cmd"
Apr 24 13:55:57 de-23rabpm-co-iocsrv kernel: st.cmd[22163]: segfault at 10 ip 00000000006b3430 sp 00007ffe4828f758 error 4 in utca[401000+4da000]

I hadn't called create_monitor_set for fofb_ioc.req yet.

ericonr commented 1 year ago
#0  epicsMutexLock (pmutexNode=0x0) at ../osi/epicsMutex.cpp:150
        status = <optimized out>
#1  0x00000000004623a1 in lockList () at ../save_restore.c:526
        caller_owns_lock = 0
#2  waitForListLock (secondsToWait=5) at ../save_restore.c:542
        secondsWaited = 0
        waitIncrement = 1
#3  set_savefile_name (filename=0x191c192 "fofb_ioc.req", save_filename=0x191c19f "DE-23SL11:BS-FOFBCtrl:_settings.sav") at ../save_restore.c:2300
        plist = <optimized out>
#4  0x00000000006a942f in iocshBody (pathname=pathname@entry=0x191afe0 "iocBoot/iocutca/autosave_post.cmd", commandLine=commandLine@entry=0x0, macros=macros@entry=0x0) at ../iocsh/iocsh.cpp:1207
        e = <optimized out>
        iarg = <optimized out>
        piocshFuncDef = 0xaa3c20 <set_savefile_name_FuncDef>
        pairs = {0x99f122 "", 0x9186fc "environ", 0x0, 0x0}
        argBuf = {<std::_Vector_base<iocshArgBuf, std::allocator<iocshArgBuf> >> = {_M_impl = {<std::allocator<iocshArgBuf>> = {<std::__new_allocator<iocshArgBuf>> = {<No data fields>}, <No data fields>}, <std::_Vector_base<iocshArgBuf, std::allocator<iocshArgBuf> >::_Vector_impl_data> = {_M_start = 0x191b0a0, 
                _M_finish = 0x191b0d0, _M_end_of_storage = 0x191b0d0}, <No data fields>}}, <No data fields>}
        readline = {context = 0x191b010, prev_rl_readline_name = 0x9187f2 "iocsh", prev_rl_basic_word_break_characters = 0x9187f8 "\t (),", prev_rl_completer_word_break_characters = 0x9187f8 "\t (),", prev_rl_basic_quote_characters = 0x8efb0c "\"", prev_rl_completer_quote_characters = 0x8efb0c "\"", 
          prev_rl_attempted_completion_function = 0x6a79f0 <(anonymous namespace)::iocsh_attempt_completion(char const*, int, int)>}
        scope = {outer = 0x7fffffffdd20, onerr = Continue, timeout = 0, errored = false, interactive = false}
        tokenize = {argv = {<std::_Vector_base<char const*, std::allocator<char const*> >> = {_M_impl = {<std::allocator<char const*>> = {<std::__new_allocator<char const*>> = {<No data fields>}, <No data fields>}, <std::_Vector_base<char const*, std::allocator<char const*> >::_Vector_impl_data> = {
                  _M_start = 0x191c3b0, _M_finish = 0x191c3d0, _M_end_of_storage = 0x191c3d0}, <No data fields>}}, <No data fields>}, redirects = {_M_t = {
              _M_impl = {<std::allocator<std::_Rb_tree_node<std::pair<int const, (anonymous namespace)::iocshRedirect> > >> = {<std::__new_allocator<std::_Rb_tree_node<std::pair<int const, (anonymous namespace)::iocshRedirect> > >> = {<No data fields>}, <No data fields>}, <std::_Rb_tree_key_compare<std::less<int> >> = {_M_key_compare = {<std::binary_function<int, int, bool>> = {<No data fields>}, <No data fields>}}, <std::_Rb_tree_header> = {_M_header = {_M_color = std::_S_red, _M_parent = 0x0, _M_left = 0x7fffffffdc00, _M_right = 0x7fffffffdc00}, _M_node_count = 0}, <No data fields>}}}, redirect = 0x0, noise = true}
        fp = 0xb110e0
        filename = 0x191aff0 "autosave_post.cmd"
        raw = 0x191c0f0 "set_savefile_name(\"fofb_ioc.req\", \"${P}${R}_settings.sav\")"
        line = 0x191c180 "set_savefile_name"
        lineno = 1
        prompt = 0x0
        defines = <optimized out>
        ret = 0
        context = 0xb0e3c0
        handle = 0xb0e7b8
        wasOkToBlock = 1
        icin = <optimized out>
        c = <optimized out>
        found = 0x191c192
#5  0x00000000006a900f in iocshBody (pathname=<optimized out>, commandLine=0x0, macros=0x9184bc "\201\r\331\377\036\016\331\377\366\f\331\377\246\016\331\377\346\017\331\377a\016\331\377\366\f\331\377\366\f\331\377iocshRegister") at ../iocsh/iocsh.cpp:1170
        commandFile = 0x191afe0 "iocBoot/iocutca/autosave_post.cmd"
        pairs = {0x99f122 "", 0x9186fc "environ", 0x0, 0x0}
        argBuf = {<std::_Vector_base<iocshArgBuf, std::allocator<iocshArgBuf> >> = {_M_impl = {<std::allocator<iocshArgBuf>> = {<std::__new_allocator<iocshArgBuf>> = {<No data fields>}, <No data fields>}, <std::_Vector_base<iocshArgBuf, std::allocator<iocshArgBuf> >::_Vector_impl_data> = {_M_start = 0xafb2c0, 
                _M_finish = 0xafb2d0, _M_end_of_storage = 0xafb300}, <No data fields>}}, <No data fields>}
        readline = {context = 0xb0e360, prev_rl_readline_name = 0x9203ee "other", prev_rl_basic_word_break_characters = 0x91fe44 " \t\n\"\\'`@$><=;|&{(", prev_rl_completer_word_break_characters = 0x0, prev_rl_basic_quote_characters = 0x91fe41 "\"'", prev_rl_completer_quote_characters = 0x0, 
          prev_rl_attempted_completion_function = 0x0}
        scope = {outer = 0x0, onerr = Continue, timeout = 0, errored = false, interactive = false}
        tokenize = {argv = {<std::_Vector_base<char const*, std::allocator<char const*> >> = {_M_impl = {<std::allocator<char const*>> = {<std::__new_allocator<char const*>> = {<No data fields>}, <No data fields>}, <std::_Vector_base<char const*, std::allocator<char const*> >::_Vector_impl_data> = {
                  _M_start = 0xb16d20, _M_finish = 0xb16d28, _M_end_of_storage = 0xb16d40}, <No data fields>}}, <No data fields>}, redirects = {_M_t = {
              _M_impl = {<std::allocator<std::_Rb_tree_node<std::pair<int const, (anonymous namespace)::iocshRedirect> > >> = {<std::__new_allocator<std::_Rb_tree_node<std::pair<int const, (anonymous namespace)::iocshRedirect> > >> = {<No data fields>}, <No data fields>}, <std::_Rb_tree_key_compare<std::less<int> >> = {_M_key_compare = {<std::binary_function<int, int, bool>> = {<No data fields>}, <No data fields>}}, <std::_Rb_tree_header> = {_M_header = {_M_color = std::_S_red, _M_parent = 0xbcc970, _M_left = 0xbcc970, _M_right = 0xbcc970}, _M_node_count = 1}, <No data fields>}}}, redirect = 0x0, noise = true}
        fp = 0xb0e180
        filename = 0x7fffffffe3b9 "st.cmd"
        raw = 0x1015520 "< \"iocBoot/${IOC}/autosave_post.cmd\""
        line = 0x191afe0 "iocBoot/iocutca/autosave_post.cmd"
        lineno = 36
        prompt = 0x0
        defines = <optimized out>
        ret = 0
        context = 0xb0e3c0
        handle = 0xb0e7b8
        wasOkToBlock = 1
        icin = <optimized out>
        c = <optimized out>
        found = <optimized out>
#6  0x0000000000412b3f in main (argc=<optimized out>, argv=0x191c19f) at ../utcaMain.cpp:17

This seems to happen because sr_mutex is initialized in create_data_set, which will be called by create_monitor_set.

Should lockList() skip locking if sr_mutex==NULL, or should we just print an error message if things haven't been initialized yet, or...?