This source file includes following definitions.
- main
#include <sys/epoll.h>
#include <sys/socket.h>
#include <errno.h>
#include <unistd.h>
#include "systemd/sd-journal.h"
#include "systemd/sd-messages.h"
#include "systemd/sd-daemon.h"
#include "journal-authenticate.h"
#include "journald-server.h"
#include "journald-kmsg.h"
#include "journald-syslog.h"
int main(int argc, char *argv[]) {
Server server;
int r;
if (argc > 1) {
log_error("This program does not take arguments.");
return EXIT_FAILURE;
}
log_set_target(LOG_TARGET_SAFE);
log_set_facility(LOG_SYSLOG);
log_parse_environment();
log_open();
umask(0022);
r = server_init(&server);
if (r < 0)
goto finish;
server_vacuum(&server);
server_flush_to_var(&server);
server_flush_dev_kmsg(&server);
log_debug("systemd-journald running as pid "PID_FMT, getpid());
server_driver_message(&server, SD_MESSAGE_JOURNAL_START, "Journal started");
sd_notify(false,
"READY=1\n"
"STATUS=Processing requests...");
for (;;) {
usec_t t = USEC_INFINITY, n;
r = sd_event_get_state(server.event);
if (r < 0)
goto finish;
if (r == SD_EVENT_FINISHED)
break;
n = now(CLOCK_REALTIME);
if (server.max_retention_usec > 0 && server.oldest_file_usec > 0) {
if (server.oldest_file_usec + server.max_retention_usec < n) {
log_info("Retention time reached.");
server_rotate(&server);
server_vacuum(&server);
continue;
}
t = server.oldest_file_usec + server.max_retention_usec - n;
}
#ifdef HAVE_GCRYPT
if (server.system_journal) {
usec_t u;
if (journal_file_next_evolve_usec(server.system_journal, &u)) {
if (n >= u)
t = 0;
else
t = MIN(t, u - n);
}
}
#endif
r = sd_event_run(server.event, t);
if (r < 0) {
log_error("Failed to run event loop: %s", strerror(-r));
goto finish;
}
server_maybe_append_tags(&server);
server_maybe_warn_forward_syslog_missed(&server);
}
log_debug("systemd-journald stopped as pid "PID_FMT, getpid());
server_driver_message(&server, SD_MESSAGE_JOURNAL_STOP, "Journal stopped");
finish:
sd_notify(false,
"STOPPING=1\n"
"STATUS=Shutting down...");
server_done(&server);
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}