]>
Commit | Line | Data |
---|---|---|
87d2c1ff LP |
1 | /*** |
2 | This file is part of systemd. | |
3 | ||
4 | Copyright 2011 Lennart Poettering | |
5 | ||
6 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
7 | under the terms of the GNU Lesser General Public License as published by |
8 | the Free Software Foundation; either version 2.1 of the License, or | |
87d2c1ff LP |
9 | (at your option) any later version. |
10 | ||
11 | systemd is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
5430f7f2 | 14 | Lesser General Public License for more details. |
87d2c1ff | 15 | |
5430f7f2 | 16 | You should have received a copy of the GNU Lesser General Public License |
87d2c1ff LP |
17 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
18 | ***/ | |
19 | ||
87d2c1ff | 20 | #include <unistd.h> |
87d2c1ff | 21 | |
8580d1f7 | 22 | #include "sd-daemon.h" |
cf0fbc49 | 23 | #include "sd-messages.h" |
81527be1 | 24 | |
f97b34a6 | 25 | #include "format-util.h" |
89fef990 | 26 | #include "journal-authenticate.h" |
ef63833d | 27 | #include "journald-kmsg.h" |
cf0fbc49 | 28 | #include "journald-server.h" |
35e2e347 | 29 | #include "journald-syslog.h" |
fa6ac760 LP |
30 | #include "sigbus.h" |
31 | ||
87d2c1ff LP |
32 | int main(int argc, char *argv[]) { |
33 | Server server; | |
34 | int r; | |
35 | ||
87d2c1ff LP |
36 | if (argc > 1) { |
37 | log_error("This program does not take arguments."); | |
38 | return EXIT_FAILURE; | |
39 | } | |
40 | ||
a6903061 | 41 | log_set_target(LOG_TARGET_SAFE); |
3eff4208 | 42 | log_set_facility(LOG_SYSLOG); |
87d2c1ff LP |
43 | log_parse_environment(); |
44 | log_open(); | |
45 | ||
46 | umask(0022); | |
47 | ||
fa6ac760 LP |
48 | sigbus_install(); |
49 | ||
87d2c1ff LP |
50 | r = server_init(&server); |
51 | if (r < 0) | |
52 | goto finish; | |
53 | ||
3a19f215 | 54 | server_vacuum(&server, false); |
e6960940 | 55 | server_flush_to_var(&server); |
51abe64c | 56 | server_flush_dev_kmsg(&server); |
e6960940 | 57 | |
de0671ee | 58 | log_debug("systemd-journald running as pid "PID_FMT, getpid()); |
8a03c9ef ZJS |
59 | server_driver_message(&server, SD_MESSAGE_JOURNAL_START, |
60 | LOG_MESSAGE("Journal started"), | |
61 | NULL); | |
87d2c1ff | 62 | |
18e758bf FB |
63 | /* Make sure to send the usage message *after* flushing the |
64 | * journal so entries from the runtime journals are ordered | |
65 | * before this message. See #4190 for some details. */ | |
66 | server_space_usage_message(&server, NULL); | |
67 | ||
87d2c1ff | 68 | for (;;) { |
3a43da28 | 69 | usec_t t = USEC_INFINITY, n; |
87d2c1ff | 70 | |
565a9388 LP |
71 | r = sd_event_get_state(server.event); |
72 | if (r < 0) | |
73 | goto finish; | |
74 | if (r == SD_EVENT_FINISHED) | |
75 | break; | |
76 | ||
fb0951b0 | 77 | n = now(CLOCK_REALTIME); |
89fef990 | 78 | |
fb0951b0 | 79 | if (server.max_retention_usec > 0 && server.oldest_file_usec > 0) { |
89fef990 | 80 | |
fb0951b0 LP |
81 | /* The retention time is reached, so let's vacuum! */ |
82 | if (server.oldest_file_usec + server.max_retention_usec < n) { | |
83 | log_info("Retention time reached."); | |
84 | server_rotate(&server); | |
3a19f215 | 85 | server_vacuum(&server, false); |
fb0951b0 LP |
86 | continue; |
87 | } | |
89fef990 | 88 | |
fb0951b0 | 89 | /* Calculate when to rotate the next time */ |
f9a810be | 90 | t = server.oldest_file_usec + server.max_retention_usec - n; |
fb0951b0 LP |
91 | } |
92 | ||
93 | #ifdef HAVE_GCRYPT | |
94 | if (server.system_journal) { | |
95 | usec_t u; | |
96 | ||
97 | if (journal_file_next_evolve_usec(server.system_journal, &u)) { | |
98 | if (n >= u) | |
99 | t = 0; | |
100 | else | |
f9a810be | 101 | t = MIN(t, u - n); |
fb0951b0 LP |
102 | } |
103 | } | |
89fef990 | 104 | #endif |
89fef990 | 105 | |
f9a810be | 106 | r = sd_event_run(server.event, t); |
87d2c1ff | 107 | if (r < 0) { |
da927ba9 | 108 | log_error_errno(r, "Failed to run event loop: %m"); |
87d2c1ff | 109 | goto finish; |
89fef990 | 110 | } |
87d2c1ff | 111 | |
99add6fd | 112 | server_maybe_append_tags(&server); |
178cc770 | 113 | server_maybe_warn_forward_syslog_missed(&server); |
87d2c1ff LP |
114 | } |
115 | ||
de0671ee | 116 | log_debug("systemd-journald stopped as pid "PID_FMT, getpid()); |
8a03c9ef ZJS |
117 | server_driver_message(&server, SD_MESSAGE_JOURNAL_STOP, |
118 | LOG_MESSAGE("Journal stopped"), | |
119 | NULL); | |
fe652127 | 120 | |
87d2c1ff | 121 | finish: |
87d2c1ff LP |
122 | server_done(&server); |
123 | ||
124 | return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; | |
125 | } |