[OpenWrt-Devel] uci API wrong

魏艳艳 wyygrowing1224 at 163.com
Wed Jun 3 04:06:24 EDT 2020


Dear!
    I've tried to write configurations using UCI API in my projects, but they often cause my processes to crash, I don't know why?I hope you can help me。
1、platform:X86
This is the information that my Program crashed
(gdb) where
#0  0x00007fef72046277 in raise () from /lib64/libc.so.6
#1  0x00007fef72047968 in abort () from /lib64/libc.so.6
#2  0x00007fef72088d37 in __libc_message () from /lib64/libc.so.6
#3  0x00007fef72091499 in _int_free () from /lib64/libc.so.6
#4  0x00007fef723df3ef in uci_free_element (e=0xa63d50) at /home/uci/list.c:72
#5  0x00007fef723df573 in uci_free_package (package=package at entry=0xa63380) at /home/uci/list.c:283
#6  0x00007fef723dfb0d in uci_cleanup (ctx=0xa64300) at /home/uci/libuci.c:126
#7  0x00007fef723dfb6b in uci_free_context (ctx=0xa64300) at /home/uci/libuci.c:80
#8  0x0000000000402876 in uci_set_value (path=0x40cf59 "/tmp/DataCollection/MODMAN", config=0x40cf51 "rundata", section=0x40cf43 "modmanruninfo",
    option=0x40cfbf "akMODMANVTxMuteOpenAMIP", value=0x61b780 <g_Mcastinfo> "0") at ft_uci.c:446
#9  0x0000000000403dec in Write_Mcast_Data (def=1) at ft_daq.c:166
#10 0x000000000040426e in main (argc=1, argv=0x7ffe84fa78c8) at ft_daq.c:264


2、This is the function that writes the configuration file,My program calls uci_set_value function 20 times for 1s.
/*****************************************************************/
void uci_set_value(char *path, char *config, char *section, char *option, char *value)
{
    struct uci_context *ctx = NULL;
    struct uci_ptr ptr;
    int ret = UCI_OK;
    char str[128] = {0};
    char filepath[128] = {0};

    ctx = uci_alloc_context();
    if (!ctx)
    {
        ULOG_ERR("uci_alloc_context error, config=%s,section=%s,option=%s,value=%s\n", config, section, option, value);
        return;
    }
    if (NULL != path)
    {
        uci_set_confdir(ctx, path);
    }
   
    memset(&ptr, 0, sizeof(ptr));
    memset(str, 0 , sizeof(str));
    sprintf(str, "%s.%s.%s=%s", config, section, option, value);
   
    if (uci_lookup_ptr(ctx, &ptr, str, true) != 0)
    {
        ULOG_ERR("uci_lookup_ptr error, str=%s\n", str);
        uci_free_context(ctx);
        return;
    }
    memset(filepath, 0, sizeof(filepath));
    sprintf(filepath, "%s/%s", path, config);
 
    if ((0 != strcmp(ctx->confdir, path)) || (0 != strcmp(filepath, ptr.p->path)))
    {
        if (ptr.p)
        {
            uci_unload(ctx, ptr.p);   
        }
        uci_free_context(ctx);
        return;
    }
   
    ret = uci_set(ctx, &ptr);
    if (0 == ret)
    {
        ret = uci_commit(ctx, &ptr.p, false);
    }
    else
    {
        ULOG_ERR("uci_set error, str=%s\n", str);
    }
   
    if (ptr.p)
    {
        uci_unload(ctx, ptr.p);   
    }
// Program terminated with signal 6, Aborted.

    uci_free_context(ctx);

    return ;
}
/*****************************************************************/


3、My config file
config modman 'modmanruninfo'
        option akTestDID 'unknown'
        option akTestUptime 'unknown'
        option akTestSatelliteNetworkID 'unknown'

        akMODMANVTxMuteOpenAMIP 'unknown'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/openwrt-devel/attachments/20200603/29a8cca4/attachment.htm>
-------------- next part --------------
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list