예제 #1
0
void
aim_log_vcommon(aim_log_t* l, aim_log_flag_t flag,
                aim_ratelimiter_t* rl, uint64_t time,
                const char* fname, const char* file, int line,
                const char* fmt, va_list vargs)
{
    const char* color = NULL;

    if(flag == AIM_LOG_FLAG_MSG || flag == AIM_LOG_FLAG_FATAL ||
       aim_log_enabled(l, flag)) {
        if(rl == NULL || aim_ratelimiter_limit(rl, time) == 0) {

            if(aim_pvs_isatty(l->pvs) == 1) {
                if((color = aim_log_flag_color__(flag))) {
                    aim_printf(l->pvs, color);
                }
            }

            aim_log_output__(l, fname, file, line, fmt, vargs);

            if(color) {
                aim_printf(l->pvs, color_reset__);
            }
        }
    }
}
예제 #2
0
파일: aim_pvs.c 프로젝트: jnealtowns/infra
void
aim_pvs_logf(void* cookie, aim_log_flag_t flag, const char* str)
{
    const char* color = NULL;
    aim_pvs_t* pvs = (aim_pvs_t*)cookie;

    if(pvs && aim_pvs_isatty(pvs) == 1) {
        if((color = aim_log_flag_color__(flag))) {
            aim_printf(pvs, color);
        }
    }

    aim_printf(pvs, "%s", str);

    if(color) {
        aim_printf(pvs, color_reset__);
    }
}
예제 #3
0
        -help\n\
\n";


int
faultd_main(int argc, char* argv[])
{
    char** arg;

    char* pidfile = NULL;
    int daemonize = 0;
    int restart = 0;
    int test = 0;
    char* pipename = FAULTD_CONFIG_MAIN_PIPENAME;

    aim_pvs_t* aim_pvs_syslog = NULL;
    faultd_server_t* faultd_server = NULL;
    int sid = -1;


    for(arg = argv+1; *arg; arg++) {
        if(!strcmp(*arg, "-dr")) {
            daemonize=1;
            restart=1;
        }
        else if(!strcmp(*arg, "-d")) {
            daemonize=1;
            restart=0;
        }
        else if(!strcmp(*arg, "-pid")) {
            arg++;
            pidfile = *arg;
            if(!pidfile) {
                fprintf(stderr, "-pid requires an argument.\n");
                exit(1);
            }
        }
        else if(!strcmp(*arg, "-p")) {
            arg++;
            pipename = *arg;
            if(!pipename) {
                fprintf(stderr, "-p requires an argument.\n");
                exit(1);
            }
        }
        else if(!strcmp(*arg, "-t")) {
            test = 1;
        }
        else if(!strcmp(*arg, "-h") || !strcmp(*arg, "--help")) {
            printf(help__, FAULTD_CONFIG_MAIN_PIPENAME);
            exit(0);
        }
    }

    if(test) {
        return test__(argv[0], pipename);
    }

    /**
     * Start Server
     */
    aim_pvs_syslog = aim_pvs_syslog_open("faultd", LOG_PID, LOG_DAEMON);
    aim_printf(aim_pvs_syslog, "faultd starting");
    faultd_server_create(&faultd_server);
    sid = faultd_server_add(faultd_server, pipename);

    if(sid < 0) {
        perror("server_add:");
        abort();
    }

    if(daemonize) {
        aim_daemon_restart_config_t rconfig;
        aim_daemon_config_t config;

        memset(&config, 0, sizeof(config));
        aim_daemon_restart_config_init(&rconfig, 1, 1);
        AIM_BITMAP_CLR(&rconfig.signal_restarts, SIGTERM);
        AIM_BITMAP_CLR(&rconfig.signal_restarts, SIGKILL);
        rconfig.maximum_restarts=0;
        rconfig.pvs = aim_pvs_syslog_get();

        config.wd = "/";
        if(restart) {
            aim_daemonize(&config, &rconfig);
        }
        else {
            aim_daemonize(&config, NULL);
        }
    }

    /*
     * Write our PID file if requested.
     */
    if(pidfile) {
        FILE* fp = fopen(pidfile, "w");
        if(fp == NULL) {
            int e = errno;
            aim_printf(aim_pvs_syslog, "fatal: open(%s): %s\n",
                       pidfile, strerror(e));
            aim_printf(&aim_pvs_stderr, "fatal: open(%s): %s\n",
                       pidfile, strerror(e));

            /* Don't attempt restart */
            raise(SIGTERM);
        }
        fprintf(fp, "%d\n", getpid());
        fclose(fp);
    }

    /**
     * Process Fault Messages
     */
    for(;;) {
        faultd_info_t faultd_info;
        memset(&faultd_info, 0, sizeof(faultd_info));
        if(faultd_server_read(faultd_server, &faultd_info, sid) >= 0) {
            faultd_info_show(&faultd_info, aim_pvs_syslog, 0);
            if(aim_pvs_isatty(&aim_pvs_stderr)) {
                faultd_info_show(&faultd_info, &aim_pvs_stderr, 0);
            }
        }
    }
}