Esempio n. 1
0
int
aim_log_handler_basic_init_all(const char* ident,
                           const char* debug_log,
                           int max_debug_log_size,
                           int max_debug_logs)
{
    aim_log_handler_config_t config;
    AIM_MEMSET(&config, 0, sizeof(config));

    if(isatty(1)) {
        /** Assume interactive and log to stdout */
        config.flags |= AIM_LOG_HANDLER_FLAG_TO_STDOUT;
    }
    else if(ident) {
        /** Assume daemonized and send to syslog */
        openlog(ident, LOG_PID, LOG_DAEMON);
        config.flags |= AIM_LOG_HANDLER_FLAG_TO_SYSLOG;
        config.syslog_facility = LOG_DAEMON;
    }

    if(debug_log) {
        /** Log to debug log file */
        config.flags |= AIM_LOG_HANDLER_FLAG_TO_DBGLOG;
        config.debug_log_name = aim_strdup(debug_log);
        config.max_debug_log_size = max_debug_log_size;
        config.max_debug_logs = max_debug_logs;
    }

    basic_handler__ = aim_log_handler_create(&config);
    aim_logf_set_all("{aim_log_handler}", aim_log_handler_logf, basic_handler__);
    aim_log_option_set_all(AIM_LOG_OPTION_TIMESTAMP, 0);
    return 0;
}
Esempio n. 2
0
int
aim_avsparse(char** args, aim_pvs_t* epvs,
             const char* fmt, aim_va_list_t* vargs)
{
    int rv;
    int i;
    const char* type;

    for(i = 0, type = fmt; *type; type++, i++) {
        char typeName[32];

        AIM_MEMSET(typeName, 0, sizeof(typeName));

        if(*type == '{') {
            /* Read type name */
            const char* src;
            char* dst;
            AIM_MEMSET(typeName, 0, sizeof(typeName));
            for(src = ++type, dst=typeName; *src && *src != '}';
                src++, dst++) {
                *dst = *src;
            }
            if(*src != '}') {
                /* Error in format string */
                return AIM_ERROR_PARAM;
            }
            else {
                /* next character is the next format specifier */
                type = src;
            }

            rv = aim_avsparse_type(args[i], epvs, 0, typeName, vargs);
            if(rv < 0) {
                return rv;
            }
        }
        else {
            rv = aim_avsparse_type(args[i], epvs, *type, NULL, vargs);
            if(rv < 0) {
                return rv;
            }
        }
    }

    return AIM_ERROR_NONE;
}
static int
onlp_snmp_sensor_register_oid__(onlp_oid_t oid, void* cookie)
{
    onlp_oid_hdr_t hdr;
    onlp_snmp_sensor_t s;

    onlp_oid_hdr_get(oid, &hdr);

    AIM_MEMSET(&s, 0x0, sizeof(onlp_snmp_sensor_t));
    switch(ONLP_OID_TYPE_GET(oid))
        {
        case ONLP_OID_TYPE_THERMAL:
#if ONLP_SNMP_CONFIG_INCLUDE_THERMALS == 1
            s.sensor_id = oid;
            sprintf(s.name, "%d - ", ONLP_OID_ID_GET(oid));
            aim_strlcpy(s.desc, hdr.description, sizeof(s.desc));
            if(onlp_snmp_sensor_reg__(ONLP_SNMP_SENSOR_TYPE_TEMP, &s) < 0) {
                AIM_LOG_ERROR("onlp_snmp_sensor_reg for OID 0x%x failed.", oid);
            }
#endif
            break;

        case ONLP_OID_TYPE_FAN:
#if ONLP_SNMP_CONFIG_INCLUDE_FANS == 1
            s.sensor_id = oid;
            sprintf(s.name, "%d - ", ONLP_OID_ID_GET(oid));
            aim_strlcpy(s.desc, hdr.description, sizeof(s.desc));
            if(onlp_snmp_sensor_reg__(ONLP_SNMP_SENSOR_TYPE_FAN, &s) < 0) {
                AIM_LOG_ERROR("onlp_snmp_sensor_reg for OID 0x%x failed.", oid);
            }
#endif
            break;

        case ONLP_OID_TYPE_PSU:
#if ONLP_SNMP_CONFIG_INCLUDE_PSUS == 1
            /* Register Sensors for VIN,VOUT,IIN,IOUT,PIN,POUT */
            s.sensor_id = oid;
            sprintf(s.name, "%d - ", ONLP_OID_ID_GET(oid));
            aim_strlcpy(s.desc, hdr.description, sizeof(s.desc));
            if(onlp_snmp_sensor_reg__(ONLP_SNMP_SENSOR_TYPE_PSU, &s) < 0) {
                AIM_LOG_ERROR("onlp_snmp_sensor_reg for OID 0x%x failed.", oid);
            }
#endif
            break;

        default:
            AIM_LOG_INFO("snmp type %s id %d unsupported",
                         onlp_oid_type_name(ONLP_OID_TYPE_GET(oid)),
                         ONLP_OID_ID_GET(oid));
            break;
    }

    return 0;
}
Esempio n. 4
0
void
aim_ratelimiter_init(aim_ratelimiter_t* rl, uint64_t interval,
                     uint64_t burst, aim_ratelimiter_monotonic_f monotonic)
{
    if(rl) {
        AIM_MEMSET(rl, 0, sizeof(*rl));
        rl->interval = interval;
        rl->burst = burst;
        rl->empty_time = 0;
        rl->monotonic = monotonic;
    }
}
Esempio n. 5
0
/*
 * Register a datatype handler
 */
int
aim_datatype_register(char c, const char* type, const char* desc,
                      aim_datatype_from_str_f froms, aim_datatype_to_str_f tos,
                      void* cookie)
{
    aim_datatype_t dt;
    AIM_MEMSET(&dt, 0, sizeof(dt));
    dt.c = c;
    dt.type = type;
    dt.desc = desc;
    dt.from_str = froms;
    dt.to_str = tos;
    dt.cookie = cookie;
    return aim_datatype_register_struct(&dt);
}
int
faultd_handler_register(int localfd, 
                        const char* pipename, 
                        const char* binaryname)
{
    int rv; 
    struct sigaction saction; 
    void* dummy_backtrace[1]; 
    int dummy_backtrace_size; 
    int fd; 

    if ( (rv = pthread_spin_init(&thread_lock__, 0)) ) { 
        return rv; 
    }

    /* 
     * These calls to backtrace are to assure that 
     * backtrace() and backtrace_symbols_fd() have actually 
     * been loaded into our process -- its possible they 
     * come from a dynamic library, and we don't want them
     * to get loaded at fault-time.
     */
    dummy_backtrace_size = backtrace(dummy_backtrace, 1); 
    
    /** Note - we could just pass an invalid descriptor here, but it 
     * it flags errors in valgrind. 
     */
    fd = open("/dev/null", O_WRONLY); 
    backtrace_symbols_fd(dummy_backtrace, dummy_backtrace_size, fd); 
    close(fd); 

    AIM_MEMSET(&faultd_info__, 0, sizeof(faultd_info__)); 
    if(!binaryname) { 
        binaryname = "Not specified."; 
    }
    aim_strlcpy(faultd_info__.binary, binaryname, sizeof(faultd_info__.binary)); 
                

    if(pipename) { 
        faultd_client_create(&faultd_client__, pipename); 
    }

    AIM_MEMSET(&saction, 0, sizeof(saction)); 
    saction.sa_sigaction = faultd_signal_handler__; 

    sigfillset(&saction.sa_mask); 
    saction.sa_flags = SA_SIGINFO | SA_RESETHAND; 
    
    rv = sigaction (SIGSEGV, &saction, NULL); 
    rv |= sigaction (SIGILL, &saction, NULL);
    rv |= sigaction (SIGFPE, &saction, NULL);  
    rv |= sigaction (SIGBUS, &saction, NULL);
    rv |= sigaction (SIGQUIT, &saction, NULL);
    rv |= sigaction (SIGALRM, &saction, NULL);

    /*
     * SIGUSR2 can be used to request a backtrace explicitly. 
     * In this case, we don't want to reset the handler. 
     */
    saction.sa_flags = SA_SIGINFO; 
    rv |= sigaction (SIGUSR2, &saction, NULL);  

    /*
     * The local fault handler will attempt to write a subset of
     * the fault information (signal type and backtrace) 
     * to the localfd descriptor if specified. 
     */
    localfd__ = localfd; 

    return rv;
}