Пример #1
0
static int journal_get_fd (lua_State *L) {
	sd_journal *j = check_journal(L, 1);
	int err = sd_journal_get_fd(j);
	if (err < 0) return handle_error(L, -err);
	lua_pushinteger(L, err);
	return 1;
}
Пример #2
0
int open_journal_for_upload(Uploader *u,
                            sd_journal *j,
                            const char *cursor,
                            bool after_cursor,
                            bool follow) {
    int fd, r, events;

    u->journal = j;

    sd_journal_set_data_threshold(j, 0);

    if (follow) {
        fd = sd_journal_get_fd(j);
        if (fd < 0)
            return log_error_errno(fd, "sd_journal_get_fd failed: %m");

        events = sd_journal_get_events(j);

        r = sd_journal_reliable_fd(j);
        assert(r >= 0);
        if (r > 0)
            u->timeout = -1;
        else
            u->timeout = JOURNAL_UPLOAD_POLL_TIMEOUT;

        r = sd_event_add_io(u->events, &u->input_event,
                            fd, events, dispatch_journal_input, u);
        if (r < 0)
            return log_error_errno(r, "Failed to register input event: %m");

        log_debug("Listening for journal events on fd:%d, timeout %d",
                  fd, u->timeout == (uint64_t) -1 ? -1 : (int) u->timeout);
    } else
        log_debug("Not listening for journal events.");

    if (cursor) {
        r = sd_journal_seek_cursor(j, cursor);
        if (r < 0) {
            return log_error_errno(r, "Failed to seek to cursor %s: %m",
                                   cursor);
        }
    }

    return process_journal_input(u, 1 + !!after_cursor);
}
Пример #3
0
void
systemd_init(pmdaInterface *dp)
{
    int sts;
    int journal_fd;

    dp->version.six.desc = systemd_desc;
    dp->version.six.fetch = systemd_fetch;
    dp->version.six.text = systemd_text;
    dp->version.six.attribute = systemd_contextAttributeCallBack;
    pmdaSetFetchCallBack(dp, systemd_fetchCallBack);
    pmdaSetEndContextCallBack(dp, systemd_end_contextCallBack);
    pmdaInit(dp, NULL, 0, metrictab, sizeof(metrictab)/sizeof(metrictab[0]));

    /* Initialize the systemd side.  This is failure-tolerant.  */
    /* XXX: SD_JOURNAL_{LOCAL|RUNTIME|SYSTEM}_ONLY */
    sts = sd_journal_open(& journald_context, 0);
    if (sts < 0) {
        __pmNotifyErr(LOG_ERR, "sd_journal_open failure: %s",
                      strerror(-sts));
        dp->status = sts;
        return;
    }

    sts = sd_journal_open(& journald_context_seeky, 0);
    if (sts < 0) {
        __pmNotifyErr(LOG_ERR, "sd_journal_open #2 failure: %s",
                      strerror(-sts));
        dp->status = sts;
        return;
    }

    sts = sd_journal_seek_tail(journald_context);
    if (sts < 0) {
        __pmNotifyErr(LOG_ERR, "sd_journal_seek_tail failure: %s",
                      strerror(-sts));
    }

    /* Work around RHBZ979487. */
    sts = sd_journal_previous_skip(journald_context, 1);
    if (sts < 0) {
        __pmNotifyErr(LOG_ERR, "sd_journal_previous_skip failure: %s",
                      strerror(-sts));
    }

    /* Arrange to wake up for journal events. */
    journal_fd = sd_journal_get_fd(journald_context);
    if (journal_fd < 0) {
        __pmNotifyErr(LOG_ERR, "sd_journal_get_fd failure: %s",
                      strerror(-journal_fd));
        /* NB: not a fatal error; the select() loop will still time out and
           periodically poll.  This makes it ok for sd_journal_reliable_fd()
           to be 0. */
    } else  {
        FD_SET(journal_fd, &fds);
        if (journal_fd > maxfd) maxfd = journal_fd;
    }

    /* NB: One queue is used for both .records and .records_raw; they
       just use different decoder callbacks. */
    queue_entries = pmdaEventNewQueue("systemd", maxmem);
    if (queue_entries < 0)
        __pmNotifyErr(LOG_ERR, "pmdaEventNewQueue failure: %s",
                      pmErrStr(queue_entries));
}