Esempio n. 1
0
static void async_ipc_free(async_ipc_t *aipc)
{
    aipc->cb = NULL;
    if (aipc->e)
	estream_close(aipc->e);

    while (aipc->queue)
	async_ipc_remove_op(&aipc->queue);
    nfree(aipc->sync);
    free(aipc);
}
Esempio n. 2
0
void ekey_fd_activity(int fd, short events, void *pw)
{
    econ_state_t *econ = pw;
    econ_run(econ);
    if (econ_state(econ) == ESTATE_CLOSE) {
        ekeyfd_rm(econ_get_rd_fd(econ));
        estream_close(econ->key_stream);
        econ->key_stream = NULL;
        lstate_inform_about_key(econ);
    }
}
Esempio n. 3
0
static void async_ipc_estream_timed_out(void *context)
{
    async_ipc_t *aipc = context;

    estream_close(aipc->e);
}
Esempio n. 4
0
int main(int argc, char **argv)
{
    int res;
    int opt;
    char *configfile;
    char *pidfile;

    configfile = strdup(CONFIGFILE);
    pidfile = strdup(PIDFILE);

    while ((opt = getopt(argc, argv, "vhf:p:")) != -1) {
        switch (opt) {
        case 'f':
            free(configfile);
            configfile = strdup(optarg);
            break;

        case 'p':
            free(pidfile);
            pidfile = strdup(optarg);
            break;

        case 'v':
            printf("%s: Version %s\n", argv[0], EKEYD_VERSION_S);
            return 0;

        case 'h':
        default:
            fprintf(stderr, usage, argv[0]);
            return 1;
        }
    }

    if (optind != argc) {
        fprintf(stderr, "Unexpected argument\n");
        fprintf(stderr, usage, argv[0]);
        return 1;
    }


    if (lstate_init() == false) {
        return 1;
    }

    if (!lstate_runconfig(configfile)) {
        /* Failed to run the configuration */
        return 1;
    }

    /* Everything is good, daemonise */
    if (lstate_request_daemonise())
        do_daemonise(pidfile, false);

    /* now we are a daemon, start system logging */
    openlog("ekeyd", LOG_ODELAY, LOG_DAEMON);

    syslog(LOG_INFO, "Starting Entropy Key Daemon");

    while (true) {
        res = ekeyfd_poll(-1);
        if (res == 0)
            break; /* no more fd open, finish */

        if (res < 0) {
            if ((errno == EINTR) || (errno == EWOULDBLOCK))
                continue; /* these errors are ok and the poll is retried */

            syslog(LOG_ERR, "Unhandled error in poll %s, exiting", strerror(errno));

            break;
        }

        if (lua_fd_ready) {
            lstate_controlbytes();
            lua_fd_ready = false;
        }
    }

    lstate_finalise();

    estream_close(output_stream);

    close_nonce();

    unlink(pidfile);

    free(configfile);
    free(pidfile);

    syslog(LOG_INFO, "Entropy Key Daemon Stopping");

    closelog();

    return 0;
}