Beispiel #1
0
int main(void) {
    FILE *fp_mail;
    char *status = (char *)alloca(200);
    int b, d, m;
    b = BATTERY_INTERVAL;
    d = DATE_INTERVAL;
    m = MAIL_INTERVAL;

    struct timespec interval = {
        .tv_sec  = UPDATE_INTERVAL,
        .tv_nsec = 0 };
    int sockfd = socket(AF_INET, SOCK_DGRAM, 0);

    for ( ; ; nanosleep(&interval, NULL)) {
        if (++b > BATTERY_INTERVAL) {
            print_battery();
            b = 0; }
        if (++d > DATE_INTERVAL) {
            print_time();
            d = 0; }
        if (++m > MAIL_INTERVAL) {
            if (print_mail(fp_mail) == 0) {
                m = 0; }
            if (errno == EBADF) {
                fp_mail = mail_init(); } }
        if (sockfd != -1) {
            print_iw(sockfd); }
        strncpy(_root, print_free("/"), _FREE_LEN);
        strncpy(_home, print_free("/home"), _FREE_LEN);
        print_time();
        print_cpu();
        print_memory();
        snprintf(status, 200, "%s %s | %s | %s | %s | %s | %s | %s"
                            , _root, _home, _iw, _battery, _mail, _cpu
                            , _mem, _date);
        printf("%s\n", status);

        }//break; }

    pclose(fp_mail);
    cleanup(sockfd); }

double get_battery_stats(const char *path) {
    FILE *stats;
    double value = 0;

    if ((stats = fopen(path, "r"))== NULL) {
        return -1; }
    fscanf(stats, "%lf", &value);
    fclose(stats);

    return value; }
Beispiel #2
0
u32 mail_syscall_init(void* buff, u32 size)
{
    u32 err_id;
    (void)buff;
    (void)size;
    err_id = mail_pool_init();
    if(ERROR_SUCCESS != err_id)
    {
        return ERR_MAIL_FILTER;
    } 
	err_id = mail_del_policy(buff,size);
	if(ERROR_SUCCESS != err_id)
    {
        return ERR_MAIL_FILTER;
    } 
    mail_init();
    
    return ERROR_SUCCESS;
}
Beispiel #3
0
int main(int argc, char *argv[])
{
    int run_as_daemon;
    int debug;
    pid_t pid = 0;
    FILE *file_out;
    struct sigaction sv;

#if WITH_MALLOC_BOEHM_GC
    GC_find_leak = 1;
    GC_set_warn_proc(gc_warn_proc);
    GC_enable_incremental();
#endif

    run_as_daemon = 1;
    debug = 0;
    tools_init();

    /* set up some signal handlers */
    memset(&sv, 0, sizeof(sv));
    sigemptyset(&sv.sa_mask);
    sv.sa_handler = SIG_IGN;
    sigaction(SIGPIPE, &sv, NULL);
    sv.sa_handler = sigaction_rehash;
    sigaction(SIGHUP, &sv, NULL);
    sv.sa_handler = sigaction_writedb;
    sigaction(SIGINT, &sv, NULL);
    sv.sa_handler = sigaction_exit;
    sigaction(SIGQUIT, &sv, NULL);
    sv.sa_handler = sigaction_wait;
    sigaction(SIGCHLD, &sv, NULL);

    if (argc > 1) { /* parse command line, if any */
        int c;
        struct option options[] =
        {
            {"config", 1, 0, 'c'},
            {"debug", 0, 0, 'd'},
            {"foreground", 0, 0, 'f'},
            {"help", 0, 0, 'h'},
            {"check", 0, 0, 'k'},
            {"replay", 1, 0, 'r'},
            {"version", 0, 0, 'v'},
            {0, 0, 0, 0}
        };

        while ((c = getopt_long(argc, argv, "c:dfhkr:v", options, NULL)) != -1) {
            switch (c) {
            case 'c':
                services_config = optarg;
                break;
            case 'k':
                if (conf_read(services_config)) {
                    printf("%s appears to be a valid configuration file.\n", services_config);
                } else {
                    printf("%s is an invalid configuration file.\n", services_config);
                }
                exit(0);
            case 'r':
                replay_file = fopen(optarg, "r");
                if (!replay_file) {
                    fprintf(stderr, "Could not open %s for reading: %s (%d)\n",
                            optarg, strerror(errno), errno);
                    exit(0);
                }
                break;
            case 'd':
                debug = 1;
                break;
            case 'f':
                run_as_daemon = 0;
                break;
            case 'v':
                version();
                license();
                exit(0);
            case 'h':
            default:
                usage(argv[0]);
                exit(0);
            }
        }
    }

    version();

    if (replay_file) {
        /* We read a line here to "prime" the replay file parser, but
         * mostly to get the right value of "now" for when we do the
         * irc_introduce. */
        replay_read_line();
    } else {
        now = time(NULL);
    }
    boot_time = now;

    fprintf(stdout, "Initializing daemon...\n");
    if (!conf_read(services_config)) {
        fprintf(stderr, "Unable to read %s.\n", services_config);
        exit(1);
    }

    conf_register_reload(uplink_compile);

    if (run_as_daemon) {
        /* Attempt to fork into the background if daemon mode is on. */
        pid = fork();
        if (pid < 0) {
            fprintf(stderr, "Unable to fork: %s\n", strerror(errno));
        } else if (pid > 0) {
            fprintf(stdout, "Forking into the background (pid: %d)...\n", pid);
            exit(0);
        }
        setsid();
    }

    file_out = fopen(PID_FILE, "w");
    if (file_out == NULL) {
        /* Create the main process' pid file */
        fprintf(stderr, "Unable to create PID file: %s", strerror(errno));
    } else {
        fprintf(file_out, "%i\n", (int)getpid());
        fclose(file_out);
    }

    if (run_as_daemon) {
        /* Close these since we should not use them from now on. */
        fclose(stdin);
        fclose(stdout);
        fclose(stderr);
    }

    services_argc = argc;
    services_argv = argv;

    atexit(call_exit_funcs);
    reg_exit_func(main_shutdown, NULL);

    log_init();
    MAIN_LOG = log_register_type("x3", "file:main.log");
    if (debug)
        log_debug();
    ioset_init();
    init_structs();
    init_parse();
    modcmd_init();
    saxdb_init();
    sar_init();
    gline_init();
    shun_init();
    mail_init();
    helpfile_init();
    conf_globals(); /* initializes the core services */
    conf_rlimits();
    modules_init();
    message_register_table(msgtab);
    modcmd_finalize();
    saxdb_finalize();
    helpfile_finalize();
    modules_finalize();

    /* The first exit func to be called *should* be saxdb_write_all(). */
    reg_exit_func(saxdb_write_all, NULL);
    if (replay_file) {
        char *msg;
        log_module(MAIN_LOG, LOG_INFO, "Beginning replay...");
        srand(now);
        replay_event_loop();
        if ((msg = dict_sanity_check(clients))) {
            log_module(MAIN_LOG, LOG_ERROR, "Clients insanity: %s", msg);
            free(msg);
        }
        if ((msg = dict_sanity_check(channels))) {
            log_module(MAIN_LOG, LOG_ERROR, "Channels insanity: %s", msg);
            free(msg);
        }
        if ((msg = dict_sanity_check(servers))) {
            log_module(MAIN_LOG, LOG_ERROR, "Servers insanity: %s", msg);
            free(msg);
        }
    } else {
        now = time(NULL);
        srand(now);
        ioset_run();
    }
    return 0;
}