1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2011 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 #include "systemd/sd-messages.h"
25 #include "systemd/sd-daemon.h"
27 #include "journal-authenticate.h"
28 #include "journald-server.h"
29 #include "journald-kmsg.h"
30 #include "journald-syslog.h"
34 int main(int argc, char *argv[]) {
39 log_error("This program does not take arguments.");
43 log_set_target(LOG_TARGET_SAFE);
44 log_set_facility(LOG_SYSLOG);
45 log_parse_environment();
52 r = server_init(&server);
56 server_vacuum(&server);
57 server_flush_to_var(&server);
58 server_flush_dev_kmsg(&server);
60 log_debug("systemd-journald running as pid "PID_FMT, getpid());
61 server_driver_message(&server, SD_MESSAGE_JOURNAL_START, "Journal started");
65 "STATUS=Processing requests...");
68 usec_t t = USEC_INFINITY, n;
70 r = sd_event_get_state(server.event);
73 if (r == SD_EVENT_FINISHED)
76 n = now(CLOCK_REALTIME);
78 if (server.max_retention_usec > 0 && server.oldest_file_usec > 0) {
80 /* The retention time is reached, so let's vacuum! */
81 if (server.oldest_file_usec + server.max_retention_usec < n) {
82 log_info("Retention time reached.");
83 server_rotate(&server);
84 server_vacuum(&server);
88 /* Calculate when to rotate the next time */
89 t = server.oldest_file_usec + server.max_retention_usec - n;
93 if (server.system_journal) {
96 if (journal_file_next_evolve_usec(server.system_journal, &u)) {
105 r = sd_event_run(server.event, t);
107 log_error_errno(r, "Failed to run event loop: %m");
111 server_maybe_append_tags(&server);
112 server_maybe_warn_forward_syslog_missed(&server);
115 log_debug("systemd-journald stopped as pid "PID_FMT, getpid());
116 server_driver_message(&server, SD_MESSAGE_JOURNAL_STOP, "Journal stopped");
121 "STATUS=Shutting down...");
123 server_done(&server);
125 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;