int main(int argc, char *argv[]) { unsigned n = 0; _cleanup_journal_close_ sd_journal*j = NULL; log_set_max_level(LOG_DEBUG); assert_se(sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY) >= 0); assert_se(sd_journal_add_match(j, "_TRANSPORT=syslog", 0) >= 0); assert_se(sd_journal_add_match(j, "_UID=0", 0) >= 0); SD_JOURNAL_FOREACH_BACKWARDS(j) { const void *d; size_t l; assert_se(sd_journal_get_data(j, "MESSAGE", &d, &l) >= 0); printf("%.*s\n", (int) l, (char*) d); n ++; if (n >= 10) break; } return 0; }
int main(int argc, char *argv[]) { int r; sd_journal *j; r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); if (r < 0) { fprintf(stderr, "Failed to open journal: %s\n", strerror(-r)); return 1; } for (;;) { const void *d; size_t l; r = sd_journal_next(j); if (r < 0) { fprintf(stderr, "Failed to iterate to next entry: %s\n", strerror(-r)); break; } if (r == 0) { /* Reached the end, let's wait for changes, and try again */ r = sd_journal_wait(j, (uint64_t) -1); if (r < 0) { fprintf(stderr, "Failed to wait for changes: %s\n", strerror(-r)); break; } continue; } r = sd_journal_get_data(j, "MESSAGE", &d, &l); if (r < 0) { fprintf(stderr, "Failed to read message field: %s\n", strerror(-r)); continue; } printf("%.*s\n", (int) l, (const char*) d); } sd_journal_close(j); return 0; }
static int Journal_init(Journal *self, PyObject *args, PyObject *keywds) { int flags=SD_JOURNAL_LOCAL_ONLY; char *path=NULL; PyObject *default_call=NULL, *call_dict=NULL; static char *kwlist[] = {"flags", "default_call", "call_dict", "path", NULL}; if (! PyArg_ParseTupleAndKeywords(args, keywds, "|iOOs", kwlist, &flags, &default_call, &call_dict, &path)) return 1; if (default_call) { if (PyCallable_Check(default_call) || default_call == Py_None) { Py_DECREF(self->default_call); self->default_call = default_call; Py_INCREF(self->default_call); } else { PyErr_SetString(PyExc_TypeError, "Default call not callable"); return 1; } } if (call_dict) { if (PyDict_Check(call_dict)) { Py_DECREF(self->call_dict); self->call_dict = call_dict; Py_INCREF(self->call_dict); } else if (call_dict == Py_None) { Py_DECREF(self->call_dict); self->call_dict = PyDict_New(); } else { PyErr_SetString(PyExc_TypeError, "Call dictionary must be dict type"); return 1; } } int r; if (path) { r = sd_journal_open_directory(&self->j, path, 0); } else { Py_BEGIN_ALLOW_THREADS r = sd_journal_open(&self->j, flags); Py_END_ALLOW_THREADS } if (r == -EINVAL) { PyErr_SetString(PyExc_ValueError, "Invalid flags or path"); return -1; } else if (r == -ENOMEM) { PyErr_SetString(PyExc_MemoryError, "Not enough memory"); return 1; } else if (r < 0) { PyErr_SetString(PyExc_RuntimeError, "Error opening journal"); return 1; } return 0; }
static int journal_open (lua_State *L) { int err; int flags = luaL_optinteger(L, 1, 0); sd_journal **j = lua_newuserdata(L, sizeof(sd_journal*)); err = sd_journal_open(j, flags); if (err != 0) return handle_error(L, -err); luaL_setmetatable(L, JOURNAL_METATABLE); return 1; }
static tlog_grc tlog_journal_json_reader_init(struct tlog_json_reader *reader, va_list ap) { struct tlog_journal_json_reader *journal_json_reader = (struct tlog_journal_json_reader*)reader; uint64_t since = va_arg(ap, uint64_t); uint64_t until = va_arg(ap, uint64_t); const char * const *match_sym_list = va_arg(ap, const char * const *); int sd_rc; tlog_grc grc; /* Create JSON tokener */ journal_json_reader->tok = json_tokener_new(); if (journal_json_reader->tok == NULL) { grc = TLOG_GRC_ERRNO; goto error; } /* Open journal */ sd_rc = sd_journal_open(&journal_json_reader->journal, 0); if (sd_rc < 0) { grc = TLOG_GRC_FROM(systemd, sd_rc); goto error; } /* Add matches */ sd_rc = tlog_journal_add_match_sym_list(journal_json_reader->journal, match_sym_list); if (sd_rc < 0) { grc = TLOG_GRC_FROM(systemd, sd_rc); goto error; } /* Seek to "since" timestamp */ sd_rc = sd_journal_seek_realtime_usec(journal_json_reader->journal, since); if (sd_rc < 0) { grc = TLOG_GRC_FROM(systemd, sd_rc); goto error; } /* Store "until" timestamp */ journal_json_reader->until = until; return TLOG_RC_OK; error: tlog_journal_json_reader_cleanup(reader); return grc; }
int main(int argc, char *argv[]) { _cleanup_(sd_journal_closep) sd_journal *j = NULL; _cleanup_free_ char *t; test_setup_logging(LOG_DEBUG); assert_se(sd_journal_open(&j, 0) >= 0); assert_se(sd_journal_add_match(j, "foobar", 0) < 0); assert_se(sd_journal_add_match(j, "foobar=waldo", 0) < 0); assert_se(sd_journal_add_match(j, "", 0) < 0); assert_se(sd_journal_add_match(j, "=", 0) < 0); assert_se(sd_journal_add_match(j, "=xxxxx", 0) < 0); assert_se(sd_journal_add_match(j, (uint8_t[4]){'A', '=', '\1', '\2'}, 4) >= 0); assert_se(sd_journal_add_match(j, (uint8_t[5]){'B', '=', 'C', '\0', 'D'}, 5) >= 0); assert_se(sd_journal_add_match(j, "HALLO=WALDO", 0) >= 0); assert_se(sd_journal_add_match(j, "QUUX=mmmm", 0) >= 0); assert_se(sd_journal_add_match(j, "QUUX=xxxxx", 0) >= 0); assert_se(sd_journal_add_match(j, "HALLO=", 0) >= 0); assert_se(sd_journal_add_match(j, "QUUX=xxxxx", 0) >= 0); assert_se(sd_journal_add_match(j, "QUUX=yyyyy", 0) >= 0); assert_se(sd_journal_add_match(j, "PIFF=paff", 0) >= 0); assert_se(sd_journal_add_disjunction(j) >= 0); assert_se(sd_journal_add_match(j, "ONE=one", 0) >= 0); assert_se(sd_journal_add_match(j, "ONE=two", 0) >= 0); assert_se(sd_journal_add_match(j, "TWO=two", 0) >= 0); assert_se(sd_journal_add_conjunction(j) >= 0); assert_se(sd_journal_add_match(j, "L4_1=yes", 0) >= 0); assert_se(sd_journal_add_match(j, "L4_1=ok", 0) >= 0); assert_se(sd_journal_add_match(j, "L4_2=yes", 0) >= 0); assert_se(sd_journal_add_match(j, "L4_2=ok", 0) >= 0); assert_se(sd_journal_add_disjunction(j) >= 0); assert_se(sd_journal_add_match(j, "L3=yes", 0) >= 0); assert_se(sd_journal_add_match(j, "L3=ok", 0) >= 0); assert_se(t = journal_make_match_string(j)); printf("resulting match expression is: %s\n", t); assert_se(streq(t, "(((L3=ok OR L3=yes) OR ((L4_2=ok OR L4_2=yes) AND (L4_1=ok OR L4_1=yes))) AND ((TWO=two AND (ONE=two OR ONE=one)) OR (PIFF=paff AND (QUUX=yyyyy OR QUUX=xxxxx OR QUUX=mmmm) AND (HALLO= OR HALLO=WALDO) AND B=C\\000D AND A=\\001\\002)))")); return 0; }
int main(int argc, char *argv[]) { _cleanup_journal_close_ sd_journal*j; _cleanup_free_ char *t; log_set_max_level(LOG_DEBUG); assert_se(sd_journal_open(&j, 0) >= 0); assert_se(sd_journal_add_match(j, "foobar", 0) < 0); assert_se(sd_journal_add_match(j, "foobar=waldo", 0) < 0); assert_se(sd_journal_add_match(j, "", 0) < 0); assert_se(sd_journal_add_match(j, "=", 0) < 0); assert_se(sd_journal_add_match(j, "=xxxxx", 0) < 0); assert_se(sd_journal_add_match(j, "HALLO=WALDO", 0) >= 0); assert_se(sd_journal_add_match(j, "QUUX=mmmm", 0) >= 0); assert_se(sd_journal_add_match(j, "QUUX=xxxxx", 0) >= 0); assert_se(sd_journal_add_match(j, "HALLO=", 0) >= 0); assert_se(sd_journal_add_match(j, "QUUX=xxxxx", 0) >= 0); assert_se(sd_journal_add_match(j, "QUUX=yyyyy", 0) >= 0); assert_se(sd_journal_add_match(j, "PIFF=paff", 0) >= 0); assert_se(sd_journal_add_disjunction(j) >= 0); assert_se(sd_journal_add_match(j, "ONE=one", 0) >= 0); assert_se(sd_journal_add_match(j, "ONE=two", 0) >= 0); assert_se(sd_journal_add_match(j, "TWO=two", 0) >= 0); assert_se(sd_journal_add_conjunction(j) >= 0); assert_se(sd_journal_add_match(j, "L4_1=yes", 0) >= 0); assert_se(sd_journal_add_match(j, "L4_1=ok", 0) >= 0); assert_se(sd_journal_add_match(j, "L4_2=yes", 0) >= 0); assert_se(sd_journal_add_match(j, "L4_2=ok", 0) >= 0); assert_se(sd_journal_add_disjunction(j) >= 0); assert_se(sd_journal_add_match(j, "L3=yes", 0) >= 0); assert_se(sd_journal_add_match(j, "L3=ok", 0) >= 0); assert_se(t = journal_make_match_string(j)); printf("resulting match expression is: %s\n", t); assert_se(streq(t, "(((L3=ok OR L3=yes) OR ((L4_2=ok OR L4_2=yes) AND (L4_1=ok OR L4_1=yes))) AND ((TWO=two AND (ONE=two OR ONE=one)) OR (PIFF=paff AND (QUUX=yyyyy OR QUUX=xxxxx OR QUUX=mmmm) AND (HALLO= OR HALLO=WALDO))))")); return 0; }
int main(int argc, char *argv[]) { _cleanup_free_ char *fn = NULL; char dn[] = "/var/tmp/test-journal-flush.XXXXXX"; JournalFile *new_journal = NULL; sd_journal *j = NULL; unsigned n = 0; int r; assert_se(mkdtemp(dn)); fn = strappend(dn, "/test.journal"); r = journal_file_open(-1, fn, O_CREAT|O_RDWR, 0644, false, false, NULL, NULL, NULL, NULL, &new_journal); assert_se(r >= 0); r = sd_journal_open(&j, 0); assert_se(r >= 0); sd_journal_set_data_threshold(j, 0); SD_JOURNAL_FOREACH(j) { Object *o; JournalFile *f; f = j->current_file; assert_se(f && f->current_offset > 0); r = journal_file_move_to_object(f, OBJECT_ENTRY, f->current_offset, &o); assert_se(r >= 0); r = journal_file_copy_entry(f, new_journal, o, f->current_offset, NULL, NULL, NULL); assert_se(r >= 0); n++; if (n > 10000) break; } sd_journal_close(j); (void) journal_file_close(new_journal); unlink(fn); assert_se(rmdir(dn) == 0); return 0; }
int main(int argc, char *argv[]) { sd_journal *j; int r, i, I = 100; char t[] = "/var/tmp/journal-stream-XXXXXX"; test_setup_logging(LOG_DEBUG); if (argc >= 2) { r = safe_atoi(argv[1], &I); if (r < 0) log_info("Could not parse loop count argument. Using default."); } log_info("Running %d loops", I); assert_se(mkdtemp(t)); (void) chattr_path(t, FS_NOCOW_FL, FS_NOCOW_FL, NULL); for (i = 0; i < I; i++) { r = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); assert_se(r == 0); sd_journal_close(j); r = sd_journal_open_directory(&j, t, 0); assert_se(r == 0); sd_journal_close(j); j = NULL; r = sd_journal_open_directory(&j, t, SD_JOURNAL_LOCAL_ONLY); assert_se(r == -EINVAL); assert_se(j == NULL); } assert_se(rm_rf(t, REMOVE_ROOT|REMOVE_PHYSICAL) >= 0); return 0; }
int main(int argc, char** argv){ int r; char* end; sd_journal *j; riemann_client_t *c; riemann_message_t *req, *res; riemann_event_t *event; int after_wait = 0; r = sd_journal_open(&j, 0); assert(r == 0); if(argc != 3 && argc != 6){ fprintf(stderr,"usage: journal2riemann <host> <port> [<ca-file> <cert-file> <key-file>]\n"); fprintf(stderr,"example: journal2riemann 127.0.0.1 5555\n"); exit(1); } long port = strtol(argv[2],&end,10); if(argc >= 6){ c = riemann_client_create ( RIEMANN_CLIENT_TLS, argv[1], port, RIEMANN_CLIENT_OPTION_TLS_CA_FILE, argv[3], RIEMANN_CLIENT_OPTION_TLS_CERT_FILE, argv[4], RIEMANN_CLIENT_OPTION_TLS_KEY_FILE, argv[5], RIEMANN_CLIENT_OPTION_TLS_HANDSHAKE_TIMEOUT, 10000, RIEMANN_CLIENT_OPTION_NONE); }else{ c = riemann_client_create (RIEMANN_CLIENT_TCP, argv[1], port); } r = sd_journal_seek_tail(j); assert(r == 0); for (;;) { const void *field; size_t len; r = sd_journal_next(j); assert (r >= 0); if (r == 0) { // if no more log available, wait for new ones r = sd_journal_wait(j, (uint64_t) -1); assert (r >= 0); after_wait = 1; continue; } else if (!after_wait){ // skip all logs before the first wait continue; } event = riemann_event_create(RIEMANN_EVENT_FIELD_NONE); strncpy(servicename,"journal",8); SD_JOURNAL_FOREACH_DATA(j, field, len){ char* attr = ""; enum RiemannType type; void* val; int matched = NOMATCH; MATCH(F,RIEMANN_EVENT_FIELD_DESCRIPTION , STRING , "MESSAGE=") MATCH(A,"message_id" , STRING , "MESSAGE_ID=") MATCH(F,RIEMANN_EVENT_FIELD_STATE , STATE , "PRIORITY=") MATCH(F,MATCHNOTHING , STRING , "CODE_FILE=") MATCH(F,MATCHNOTHING , STRING , "CODE_LINE=") MATCH(F,MATCHNOTHING , STRING , "CODE_FUNC=") MATCH(F,MATCHNOTHING , STRING , "ERRNO=") MATCH(F,MATCHNOTHING , STRING , "SYSLOG_FACILITY=") MATCH(F,MATCHNOTHING , STRING , "SYSLOG_IDENTIFIER=") MATCH(F,MATCHNOTHING , STRING , "SYSLOG_PID=") MATCH(F,MATCHNOTHING , STRING , "_PID=") MATCH(F,MATCHNOTHING , STRING , "_UID=") MATCH(F,MATCHNOTHING , STRING , "_GID=") MATCH(F,MATCHNOTHING , STRING , "_COMM=") MATCH(F,MATCHNOTHING , STRING , "_EXE=") MATCH(A,"command_line" , STRING , "_CMDLINE=") MATCH(F,MATCHNOTHING , STRING , "_CAP_EFFECTIVE=") MATCH(F,MATCHNOTHING , STRING , "_AUDIT_SESSION=") MATCH(F,MATCHNOTHING , STRING , "_AUDIT_LOGINUID=") MATCH(F,MATCHNOTHING , STRING , "_SYSTEMD_CGROUP=") MATCH(F,MATCHNOTHING , STRING , "_SYSTEMD_SESSION=") MATCH(F,SERVICEPART , STRING , "_SYSTEMD_UNIT=") MATCH(F,MATCHNOTHING , STRING , "_SYSTEMD_USER_UNIT=") MATCH(F,MATCHNOTHING , STRING , "_SYSTEMD_OWNER_UID=") MATCH(F,MATCHNOTHING , STRING , "_SYSTEMD_SLICE=") MATCH(F,MATCHNOTHING , STRING , "_SELINUX_CONTEXT=") MATCH(F,RIEMANN_EVENT_FIELD_TIME , TIME , "_SOURCE_REALTIME_TIMESTAMP=") MATCH(F,MATCHNOTHING , STRING , "_BOOT_ID=") MATCH(F,MATCHNOTHING , STRING , "_MACHINE_ID=") MATCH(F,RIEMANN_EVENT_FIELD_HOST , STRING , "_HOSTNAME=") MATCH(F,MATCHNOTHING , STRING , "_TRANSPORT=") MATCH(F,MATCHNOTHING , STRING , "_KERNEL_DEVICE=") MATCH(F,MATCHNOTHING , STRING , "_KERNEL_SUBSYSTEM=") MATCH(F,MATCHNOTHING , STRING , "_UDEV_SYSNAME=") MATCH(F,MATCHNOTHING , STRING , "_UDEV_DEVNODE=") MATCH(F,MATCHNOTHING , STRING , "_UDEV_DEVLINK=") MATCH(F,MATCHNOTHING , STRING , "COREDUMP_UNIT=") MATCH(F,MATCHNOTHING , STRING , "COREDUMP_USER_UNIT=") MATCH(F,MATCHNOTHING , STRING , "OBJECT_UID=") MATCH(F,MATCHNOTHING , STRING , "OBJECT_GID=") MATCH(F,MATCHNOTHING , STRING , "OBJECT_COMM=") MATCH(F,MATCHNOTHING , STRING , "OBJECT_EXE=") MATCH(F,MATCHNOTHING , STRING , "OBJECT_CMDLINE=") MATCH(F,MATCHNOTHING , STRING , "OBJECT_AUDIT_SESSION=") MATCH(F,MATCHNOTHING , STRING , "OBJECT_AUDIT_LOGINUID=") MATCH(F,MATCHNOTHING , STRING , "OBJECT_SYSTEMD_CGROUP=") MATCH(F,MATCHNOTHING , STRING , "OBJECT_SYSTEMD_SESSION=") MATCH(F,MATCHNOTHING , STRING , "OBJECT_SYSTEMD_OWNER_UID=") MATCH(F,MATCHNOTHING , STRING , "OBJECT_SYSTEMD_UNIT=") MATCH(F,MATCHNOTHING , STRING , "OBJECT_SYSTEMD_USER_UNIT=") MATCH(F,MATCHNOTHING , STRING , "__CURSOR=") MATCH(F,MATCHNOTHING , STRING , "__REALTIME_TIMESTAMP=") MATCH(F,MATCHNOTHING , STRING , "__MONOTONIC_TIMESTAMP=") if(matched != MATCHNOTHING && matched != NOMATCH){ memcpy(valuebuf,field,len); *(valuebuf+len) = 0; switch(type){ case STATE: val = (void*) states[atoi(valuebuf)]; break; case TIME: *(valuebuf+len-6) = 0; long t = strtol(valuebuf,&end,10); val = (int64_t) t; break; default: val = (void*) valuebuf; } switch(matched){ case ATTRIBUTE: riemann_event_string_attribute_add(event,attr,valuebuf); break; case TAG: riemann_event_tag_add(event,valuebuf); break; case SERVICEPART: if(len > 0){ strncat(servicename," ",2); strncat(servicename,valuebuf,len+1); } break; default: riemann_event_set(event,matched,val,RIEMANN_EVENT_FIELD_NONE); } } } riemann_event_set(event,RIEMANN_EVENT_FIELD_SERVICE,servicename,RIEMANN_EVENT_FIELD_NONE); req = riemann_message_create_with_events(event, NULL); res = riemann_communicate(c, req); if (!res) { fprintf (stderr, "Error communicating with Riemann: %s\n", strerror (errno)); exit (1); } if (res->error) { fprintf (stderr, "Error communicating with Riemann: %s\n", res->error); exit (1); } if (res->has_ok && !res->ok) { fprintf (stderr, "Error communicating with Riemann: %s\n", strerror (errno)); exit (1); } riemann_message_free(res); }
QStringList UnitModel::getLastJrnlEntries(QString unit) const { QString match1, match2; int r, jflags; QStringList reply; const void *data; size_t length; uint64_t time; sd_journal *journal; if (!userBus.isEmpty()) { match1 = QString("USER_UNIT=" + unit); jflags = (SD_JOURNAL_LOCAL_ONLY | SD_JOURNAL_CURRENT_USER); } else { match1 = QString("_SYSTEMD_UNIT=" + unit); match2 = QString("UNIT=" + unit); jflags = (SD_JOURNAL_LOCAL_ONLY | SD_JOURNAL_SYSTEM); } r = sd_journal_open(&journal, jflags); if (r != 0) { qDebug() << "Failed to open journal"; return reply; } sd_journal_flush_matches(journal); r = sd_journal_add_match(journal, match1.toUtf8(), 0); if (r != 0) return reply; if (!match2.isEmpty()) { sd_journal_add_disjunction(journal); r = sd_journal_add_match(journal, match2.toUtf8(), 0); if (r != 0) return reply; } r = sd_journal_seek_tail(journal); if (r != 0) return reply; // Fetch the last 5 entries for (int i = 0; i < 5; ++i) { r = sd_journal_previous(journal); if (r == 1) { QString line; // Get the date and time r = sd_journal_get_realtime_usec(journal, &time); if (r == 0) { QDateTime date; date.setMSecsSinceEpoch(time/1000); line.append(date.toString("yyyy.MM.dd hh:mm")); } // Color messages according to priority r = sd_journal_get_data(journal, "PRIORITY", &data, &length); if (r == 0) { int prio = QString::fromUtf8((const char *)data, length).section('=',1).toInt(); if (prio <= 3) line.append("<span style='color:tomato;'>"); else if (prio == 4) line.append("<span style='color:khaki;'>"); else line.append("<span style='color:palegreen;'>"); } // Get the message itself r = sd_journal_get_data(journal, "MESSAGE", &data, &length); if (r == 0) { line.append(": " + QString::fromUtf8((const char *)data, length).section('=',1) + "</span>"); if (line.length() > 195) line = QString(line.left(195) + "..." + "</span>"); reply << line; } } else // previous failed, no more entries return reply; } sd_journal_close(journal); return reply; }
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)); }
int main(int argc, char *argv[]) { int r; sd_journal *j = NULL; unsigned line = 0; bool need_seek = false; sd_id128_t previous_boot_id; bool previous_boot_id_valid = false; bool have_pager; log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) goto finish; if (arg_new_id128) { r = generate_new_id128(); goto finish; } #ifdef HAVE_ACL if (!arg_quiet && geteuid() != 0 && in_group("adm") <= 0) log_warning("Showing user generated messages only. Users in the group 'adm' can see all messages. Pass -q to turn this message off."); #endif if (arg_directory) r = sd_journal_open_directory(&j, arg_directory, 0); else r = sd_journal_open(&j, arg_local ? SD_JOURNAL_LOCAL_ONLY : 0); if (r < 0) { log_error("Failed to open journal: %s", strerror(-r)); goto finish; } if (arg_print_header) { journal_print_header(j); r = 0; goto finish; } r = add_this_boot(j); if (r < 0) goto finish; r = add_matches(j, argv + optind); if (r < 0) goto finish; if (!arg_quiet) { usec_t start, end; char start_buf[FORMAT_TIMESTAMP_MAX], end_buf[FORMAT_TIMESTAMP_MAX]; r = sd_journal_get_cutoff_realtime_usec(j, &start, &end); if (r < 0) { log_error("Failed to get cutoff: %s", strerror(-r)); goto finish; } if (r > 0) { if (arg_follow) printf("Logs begin at %s.\n", format_timestamp(start_buf, sizeof(start_buf), start)); else printf("Logs begin at %s, end at %s.\n", format_timestamp(start_buf, sizeof(start_buf), start), format_timestamp(end_buf, sizeof(end_buf), end)); } } if (arg_lines >= 0) { r = sd_journal_seek_tail(j); if (r < 0) { log_error("Failed to seek to tail: %s", strerror(-r)); goto finish; } r = sd_journal_previous_skip(j, arg_lines); } else { r = sd_journal_seek_head(j); if (r < 0) { log_error("Failed to seek to head: %s", strerror(-r)); goto finish; } r = sd_journal_next(j); } if (r < 0) { log_error("Failed to iterate through journal: %s", strerror(-r)); goto finish; } have_pager = !arg_no_pager && !arg_follow; if (have_pager) { columns(); pager_open(); } if (arg_output == OUTPUT_JSON) { fputc('[', stdout); fflush(stdout); } for (;;) { for (;;) { sd_id128_t boot_id; int flags = (arg_show_all*OUTPUT_SHOW_ALL | have_pager*OUTPUT_FULL_WIDTH); if (need_seek) { r = sd_journal_next(j); if (r < 0) { log_error("Failed to iterate through journal: %s", strerror(-r)); goto finish; } } if (r == 0) break; r = sd_journal_get_monotonic_usec(j, NULL, &boot_id); if (r >= 0) { if (previous_boot_id_valid && !sd_id128_equal(boot_id, previous_boot_id)) printf(ANSI_HIGHLIGHT_ON "----- Reboot -----" ANSI_HIGHLIGHT_OFF "\n"); previous_boot_id = boot_id; previous_boot_id_valid = true; } line ++; r = output_journal(j, arg_output, line, 0, flags); if (r < 0) goto finish; need_seek = true; } if (!arg_follow) break; r = sd_journal_wait(j, (uint64_t) -1); if (r < 0) { log_error("Couldn't wait for log event: %s", strerror(-r)); goto finish; } } if (arg_output == OUTPUT_JSON) fputs("\n]\n", stdout); finish: if (j) sd_journal_close(j); pager_close(); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }