Annotation of mqtt/src/dl.c, revision 1.1.2.2

1.1.2.1   misho       1: #include "global.h"
                      2: #include "rtlm.h"
                      3: 
                      4: 
                      5: static void *acc_rtlm, *pub_rtlm;
                      6: 
                      7: 
                      8: /*
                      9:  * mqttLog() Log message to syslog
                     10:  *
                     11:  * @fmt = format string
                     12:  * @... = argument list
                     13:  * return: none
                     14:  */
                     15: void
                     16: mqttLog(const char *fmt, ...)
                     17: {
                     18:        va_list lst;
                     19: 
                     20:        va_start(lst, fmt);
                     21:        vsyslog(LOG_ERR, fmt, lst);
                     22:        va_end(lst);
                     23: }
                     24: 
                     25: void *
                     26: mqttLoadRTLM(sl_config *cfg, int modtype)
                     27: {
                     28:        char *str;
                     29:        void *rtlm = NULL;
                     30: 
                     31:        if (!cfg)
                     32:                return NULL;
                     33: 
                     34:        str = CFG(cfg_GetAttribute(cfg, CFG("mqttd"), CFG(modtype ? "pub_file" : "acc_file")));
                     35:        if (!str) {
                     36:                mqttLog("Error:: RTL module not found\n");
                     37:                return NULL;
                     38:        }
                     39: 
                     40:        rtlm = dlopen(str, RTLD_LAZY);
                     41:        if (!rtlm) {
                     42:                mqttLog("Error:: RTL module not found %s\n", dlerror());
                     43:                return NULL;
                     44:        }
                     45: 
                     46:        mqttOpenDB = dlsym(rtlm, "mqtt_db_open");
                     47:        if (!mqttOpenDB) {
                     48:                mqttLog("Error:: Can't found mqtt_db_open call\n");
                     49:                dlclose(rtlm);
                     50:                return NULL;
                     51:        }
                     52:        mqttCloseDB = dlsym(rtlm, "mqtt_db_close");
                     53:        if (!mqttCloseDB) {
                     54:                mqttLog("Error:: Can't found mqtt_db_close call\n");
                     55:                dlclose(rtlm);
                     56:                return NULL;
                     57:        }
                     58: 
                     59:        if (modtype) {
                     60:                pub_rtlm = rtlm;
                     61:        } else {
                     62:                acc_rtlm = rtlm;
                     63:        }
                     64: 
                     65:        return rtlm;
                     66: }
                     67: 
                     68: void
                     69: mqttUnloadRTLM(int modtype)
                     70: {
                     71:        dlclose((modtype ? pub_rtlm : acc_rtlm));
                     72: }
1.1.2.2 ! misho      73: 
        !            74: inline int
        !            75: mqttMkDir(sl_config *cfg)
        !            76: {
        !            77:        char *str;
        !            78: 
        !            79:        if (!cfg)
        !            80:                return -1;
        !            81: 
        !            82:        str = CFG(cfg_GetAttribute(cfg, CFG("mqttd"), CFG("statedir")));
        !            83:        if (!str)
        !            84:                return -1;
        !            85: 
        !            86:        if (mkdir(str, 0600) == -1 && errno != EEXIST)
        !            87:                return -1;
        !            88: 
        !            89:        return 0;
        !            90: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>