Bug Summary

File:build-scan/../src/journal/journald-server.c
Warning:line 778, column 25
Value stored to 'cmdline1' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name journald-server.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -fdenormal-fp-math=preserve-sign,preserve-sign -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/12.0.0 -include config.h -I test-tables.p -I . -I .. -I src/basic -I ../src/basic -I src/shared -I ../src/shared -I src/systemd -I ../src/systemd -I src/journal -I ../src/journal -I src/journal-remote -I ../src/journal-remote -I src/nspawn -I ../src/nspawn -I src/resolve -I ../src/resolve -I src/timesync -I ../src/timesync -I ../src/time-wait-sync -I src/login -I ../src/login -I src/udev -I ../src/udev -I src/libudev -I ../src/libudev -I src/core -I ../src/core -I ../src/libsystemd/sd-bus -I ../src/libsystemd/sd-device -I ../src/libsystemd/sd-hwdb -I ../src/libsystemd/sd-id128 -I ../src/libsystemd/sd-netlink -I ../src/libsystemd/sd-network -I src/libsystemd-network -I ../src/libsystemd-network -I ../src/udev/net -I /usr/include/libmount -I /usr/include/blkid -D _FILE_OFFSET_BITS=64 -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/12.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wwrite-strings -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused-result -Wno-format-signedness -Wno-error=nonnull -std=gnu99 -fconst-strings -fdebug-compilation-dir /home/mrc0mmand/repos/@redhat-plumbers/systemd-rhel8/build-scan -ferror-limit 19 -fvisibility hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -analyzer-output=html -faddrsig -o /tmp/scan-build-2021-07-16-221226-1465241-1 -x c ../src/journal/journald-server.c
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
3#if HAVE_SELINUX1
4#include <selinux/selinux.h>
5#endif
6#include <sys/ioctl.h>
7#include <sys/mman.h>
8#include <sys/signalfd.h>
9#include <sys/statvfs.h>
10#include <linux1/sockios.h>
11
12#include "libudev.h"
13#include "sd-daemon.h"
14#include "sd-journal.h"
15#include "sd-messages.h"
16
17#include "acl-util.h"
18#include "alloc-util.h"
19#include "audit-util.h"
20#include "cgroup-util.h"
21#include "conf-parser.h"
22#include "dirent-util.h"
23#include "extract-word.h"
24#include "fd-util.h"
25#include "fileio.h"
26#include "format-util.h"
27#include "fs-util.h"
28#include "hashmap.h"
29#include "hostname-util.h"
30#include "id128-util.h"
31#include "io-util.h"
32#include "journal-authenticate.h"
33#include "journal-file.h"
34#include "journal-internal.h"
35#include "journal-vacuum.h"
36#include "journald-audit.h"
37#include "journald-context.h"
38#include "journald-kmsg.h"
39#include "journald-native.h"
40#include "journald-rate-limit.h"
41#include "journald-server.h"
42#include "journald-stream.h"
43#include "journald-syslog.h"
44#include "log.h"
45#include "missing.h"
46#include "mkdir.h"
47#include "parse-util.h"
48#include "proc-cmdline.h"
49#include "process-util.h"
50#include "rm-rf.h"
51#include "selinux-util.h"
52#include "signal-util.h"
53#include "socket-util.h"
54#include "stdio-util.h"
55#include "string-table.h"
56#include "string-util.h"
57#include "syslog-util.h"
58#include "user-util.h"
59
60#define USER_JOURNALS_MAX1024 1024
61
62#define DEFAULT_SYNC_INTERVAL_USEC(5*((usec_t) (60ULL*((usec_t) 1000000ULL)))) (5*USEC_PER_MINUTE((usec_t) (60ULL*((usec_t) 1000000ULL))))
63#define DEFAULT_RATE_LIMIT_INTERVAL(30*((usec_t) 1000000ULL)) (30*USEC_PER_SEC((usec_t) 1000000ULL))
64#define DEFAULT_RATE_LIMIT_BURST10000 10000
65#define DEFAULT_MAX_FILE_USEC((usec_t) (2629800ULL*((usec_t) 1000000ULL))) USEC_PER_MONTH((usec_t) (2629800ULL*((usec_t) 1000000ULL)))
66
67#define RECHECK_SPACE_USEC(30*((usec_t) 1000000ULL)) (30*USEC_PER_SEC((usec_t) 1000000ULL))
68
69#define NOTIFY_SNDBUF_SIZE(8*1024*1024) (8*1024*1024)
70
71/* The period to insert between posting changes for coalescing */
72#define POST_CHANGE_TIMER_INTERVAL_USEC(250*((usec_t) 1000ULL)) (250*USEC_PER_MSEC((usec_t) 1000ULL))
73
74/* Pick a good default that is likely to fit into AF_UNIX and AF_INET SOCK_DGRAM datagrams, and even leaves some room
75 * for a bit of additional metadata. */
76#define DEFAULT_LINE_MAX(48*1024) (48*1024)
77
78static int determine_path_usage(Server *s, const char *path, uint64_t *ret_used, uint64_t *ret_free) {
79 _cleanup_closedir___attribute__((cleanup(closedirp))) DIR *d = NULL((void*)0);
80 struct dirent *de;
81 struct statvfs ss;
82
83 assert(ret_used)do { if ((__builtin_expect(!!(!(ret_used)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("ret_used"), "../src/journal/journald-server.c"
, 83, __PRETTY_FUNCTION__); } while (0)
;
84 assert(ret_free)do { if ((__builtin_expect(!!(!(ret_free)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("ret_free"), "../src/journal/journald-server.c"
, 84, __PRETTY_FUNCTION__); } while (0)
;
85
86 d = opendir(path);
87 if (!d)
88 return log_full_errno(errno == ENOENT ? LOG_DEBUG : LOG_ERR,({ int _level = (((*__errno_location ()) == 2 ? 7 : 3)), _e =
(((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm
(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((
_realm) << 10 | (_level)), _e, "../src/journal/journald-server.c"
, 89, __func__, "Failed to open %s: %m", path) : -abs(_e); })
89 errno, "Failed to open %s: %m", path)({ int _level = (((*__errno_location ()) == 2 ? 7 : 3)), _e =
(((*__errno_location ()))), _realm = (LOG_REALM_SYSTEMD); (log_get_max_level_realm
(_realm) >= ((_level) & 0x07)) ? log_internal_realm(((
_realm) << 10 | (_level)), _e, "../src/journal/journald-server.c"
, 89, __func__, "Failed to open %s: %m", path) : -abs(_e); })
;
90
91 if (fstatvfs(dirfd(d), &ss) < 0)
92 return log_error_errno(errno, "Failed to fstatvfs(%s): %m", path)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/journal/journald-server.c", 92, __func__
, "Failed to fstatvfs(%s): %m", path) : -abs(_e); })
;
93
94 *ret_free = ss.f_bsize * ss.f_bavail;
95 *ret_used = 0;
96 FOREACH_DIRENT_ALL(de, d, break)for ((*__errno_location ()) = 0, de = readdir(d);; (*__errno_location
()) = 0, de = readdir(d)) if (!de) { if ((*__errno_location (
)) > 0) { break; } break; } else
{
97 struct stat st;
98
99 if (!endswith(de->d_name, ".journal") &&
100 !endswith(de->d_name, ".journal~"))
101 continue;
102
103 if (fstatat(dirfd(d), de->d_name, &st, AT_SYMLINK_NOFOLLOW0x100) < 0) {
104 log_debug_errno(errno, "Failed to stat %s/%s, ignoring: %m", path, de->d_name)({ int _level = ((7)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/journal/journald-server.c", 104,
__func__, "Failed to stat %s/%s, ignoring: %m", path, de->
d_name) : -abs(_e); })
;
105 continue;
106 }
107
108 if (!S_ISREG(st.st_mode)((((st.st_mode)) & 0170000) == (0100000)))
109 continue;
110
111 *ret_used += (uint64_t) st.st_blocks * 512UL;
112 }
113
114 return 0;
115}
116
117static void cache_space_invalidate(JournalStorageSpace *space) {
118 zero(*space)(({ size_t _l_ = (sizeof(*space)); void *_x_ = (&(*space)
); _l_ == 0 ? _x_ : memset(_x_, 0, _l_); }))
;
119}
120
121static int cache_space_refresh(Server *s, JournalStorage *storage) {
122 JournalStorageSpace *space;
123 JournalMetrics *metrics;
124 uint64_t vfs_used, vfs_avail, avail;
125 usec_t ts;
126 int r;
127
128 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 128, __PRETTY_FUNCTION__); } while (0)
;
129
130 metrics = &storage->metrics;
131 space = &storage->space;
132
133 ts = now(CLOCK_MONOTONIC1);
134
135 if (space->timestamp != 0 && space->timestamp + RECHECK_SPACE_USEC(30*((usec_t) 1000000ULL)) > ts)
136 return 0;
137
138 r = determine_path_usage(s, storage->path, &vfs_used, &vfs_avail);
139 if (r < 0)
140 return r;
141
142 space->vfs_used = vfs_used;
143 space->vfs_available = vfs_avail;
144
145 avail = LESS_BY(vfs_avail, metrics->keep_free)__extension__ ({ const typeof((vfs_avail)) __unique_prefix_A43
= ((vfs_avail)); const typeof((metrics->keep_free)) __unique_prefix_B44
= ((metrics->keep_free)); __unique_prefix_A43 > __unique_prefix_B44
? __unique_prefix_A43 - __unique_prefix_B44 : 0; })
;
146
147 space->limit = MIN(MAX(vfs_used + avail, metrics->min_use), metrics->max_use)__extension__ ({ const typeof((__extension__ ({ const typeof(
(vfs_used + avail)) __unique_prefix_A45 = ((vfs_used + avail)
); const typeof((metrics->min_use)) __unique_prefix_B46 = (
(metrics->min_use)); __unique_prefix_A45 > __unique_prefix_B46
? __unique_prefix_A45 : __unique_prefix_B46; }))) __unique_prefix_A47
= ((__extension__ ({ const typeof((vfs_used + avail)) __unique_prefix_A45
= ((vfs_used + avail)); const typeof((metrics->min_use)) __unique_prefix_B46
= ((metrics->min_use)); __unique_prefix_A45 > __unique_prefix_B46
? __unique_prefix_A45 : __unique_prefix_B46; }))); const typeof
((metrics->max_use)) __unique_prefix_B48 = ((metrics->max_use
)); __unique_prefix_A47 < __unique_prefix_B48 ? __unique_prefix_A47
: __unique_prefix_B48; })
;
148 space->available = LESS_BY(space->limit, vfs_used)__extension__ ({ const typeof((space->limit)) __unique_prefix_A49
= ((space->limit)); const typeof((vfs_used)) __unique_prefix_B50
= ((vfs_used)); __unique_prefix_A49 > __unique_prefix_B50
? __unique_prefix_A49 - __unique_prefix_B50 : 0; })
;
149 space->timestamp = ts;
150 return 1;
151}
152
153static void patch_min_use(JournalStorage *storage) {
154 assert(storage)do { if ((__builtin_expect(!!(!(storage)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("storage"), "../src/journal/journald-server.c"
, 154, __PRETTY_FUNCTION__); } while (0)
;
155
156 /* Let's bump the min_use limit to the current usage on disk. We do
157 * this when starting up and first opening the journal files. This way
158 * sudden spikes in disk usage will not cause journald to vacuum files
159 * without bounds. Note that this means that only a restart of journald
160 * will make it reset this value. */
161
162 storage->metrics.min_use = MAX(storage->metrics.min_use, storage->space.vfs_used)__extension__ ({ const typeof((storage->metrics.min_use)) __unique_prefix_A51
= ((storage->metrics.min_use)); const typeof((storage->
space.vfs_used)) __unique_prefix_B52 = ((storage->space.vfs_used
)); __unique_prefix_A51 > __unique_prefix_B52 ? __unique_prefix_A51
: __unique_prefix_B52; })
;
163}
164
165static int determine_space(Server *s, uint64_t *available, uint64_t *limit) {
166 JournalStorage *js;
167 int r;
168
169 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 169, __PRETTY_FUNCTION__); } while (0)
;
170
171 js = s->system_journal ? &s->system_storage : &s->runtime_storage;
172
173 r = cache_space_refresh(s, js);
174 if (r >= 0) {
175 if (available)
176 *available = js->space.available;
177 if (limit)
178 *limit = js->space.limit;
179 }
180 return r;
181}
182
183void server_space_usage_message(Server *s, JournalStorage *storage) {
184 char fb1[FORMAT_BYTES_MAX8], fb2[FORMAT_BYTES_MAX8], fb3[FORMAT_BYTES_MAX8],
185 fb4[FORMAT_BYTES_MAX8], fb5[FORMAT_BYTES_MAX8], fb6[FORMAT_BYTES_MAX8];
186 JournalMetrics *metrics;
187
188 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 188, __PRETTY_FUNCTION__); } while (0)
;
189
190 if (!storage)
191 storage = s->system_journal ? &s->system_storage : &s->runtime_storage;
192
193 if (cache_space_refresh(s, storage) < 0)
194 return;
195
196 metrics = &storage->metrics;
197 format_bytes(fb1, sizeof(fb1), storage->space.vfs_used);
198 format_bytes(fb2, sizeof(fb2), metrics->max_use);
199 format_bytes(fb3, sizeof(fb3), metrics->keep_free);
200 format_bytes(fb4, sizeof(fb4), storage->space.vfs_available);
201 format_bytes(fb5, sizeof(fb5), storage->space.limit);
202 format_bytes(fb6, sizeof(fb6), storage->space.available);
203
204 server_driver_message(s, 0,
205 "MESSAGE_ID=" SD_MESSAGE_JOURNAL_USAGE_STR"ec" "38" "7f" "57" "7b" "84" "4b" "8f" "a9" "48" "f3" "3c" "ad"
"9a" "75" "e6"
,
206 LOG_MESSAGE("%s (%s) is %s, max %s, %s free.","MESSAGE=" "%s (%s) is %s, max %s, %s free.", storage->name
, storage->path, fb1, fb5, fb6
207 storage->name, storage->path, fb1, fb5, fb6)"MESSAGE=" "%s (%s) is %s, max %s, %s free.", storage->name
, storage->path, fb1, fb5, fb6
,
208 "JOURNAL_NAME=%s", storage->name,
209 "JOURNAL_PATH=%s", storage->path,
210 "CURRENT_USE=%"PRIu64"l" "u", storage->space.vfs_used,
211 "CURRENT_USE_PRETTY=%s", fb1,
212 "MAX_USE=%"PRIu64"l" "u", metrics->max_use,
213 "MAX_USE_PRETTY=%s", fb2,
214 "DISK_KEEP_FREE=%"PRIu64"l" "u", metrics->keep_free,
215 "DISK_KEEP_FREE_PRETTY=%s", fb3,
216 "DISK_AVAILABLE=%"PRIu64"l" "u", storage->space.vfs_available,
217 "DISK_AVAILABLE_PRETTY=%s", fb4,
218 "LIMIT=%"PRIu64"l" "u", storage->space.limit,
219 "LIMIT_PRETTY=%s", fb5,
220 "AVAILABLE=%"PRIu64"l" "u", storage->space.available,
221 "AVAILABLE_PRETTY=%s", fb6,
222 NULL((void*)0));
223}
224
225static bool_Bool uid_for_system_journal(uid_t uid) {
226
227 /* Returns true if the specified UID shall get its data stored in the system journal*/
228
229 return uid_is_system(uid) || uid_is_dynamic(uid) || uid == UID_NOBODY((uid_t) 65534U);
230}
231
232static void server_add_acls(JournalFile *f, uid_t uid) {
233#if HAVE_ACL1
234 int r;
235#endif
236 assert(f)do { if ((__builtin_expect(!!(!(f)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("f"), "../src/journal/journald-server.c"
, 236, __PRETTY_FUNCTION__); } while (0)
;
237
238#if HAVE_ACL1
239 if (uid_for_system_journal(uid))
240 return;
241
242 r = add_acls_for_user(f->fd, uid);
243 if (r < 0)
244 log_warning_errno(r, "Failed to set ACL on %s, ignoring: %m", f->path)({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 244, __func__, "Failed to set ACL on %s, ignoring: %m"
, f->path) : -abs(_e); })
;
245#endif
246}
247
248static int open_journal(
249 Server *s,
250 bool_Bool reliably,
251 const char *fname,
252 int flags,
253 bool_Bool seal,
254 JournalMetrics *metrics,
255 JournalFile **ret) {
256
257 _cleanup_(journal_file_closep)__attribute__((cleanup(journal_file_closep))) JournalFile *f = NULL((void*)0);
258 int r;
259
260 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 260, __PRETTY_FUNCTION__); } while (0)
;
261 assert(fname)do { if ((__builtin_expect(!!(!(fname)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("fname"), "../src/journal/journald-server.c"
, 261, __PRETTY_FUNCTION__); } while (0)
;
262 assert(ret)do { if ((__builtin_expect(!!(!(ret)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("ret"), "../src/journal/journald-server.c"
, 262, __PRETTY_FUNCTION__); } while (0)
;
263
264 if (reliably)
265 r = journal_file_open_reliably(fname, flags, 0640, s->compress.enabled, s->compress.threshold_bytes,
266 seal, metrics, s->mmap, s->deferred_closes, NULL((void*)0), &f);
267 else
268 r = journal_file_open(-1, fname, flags, 0640, s->compress.enabled, s->compress.threshold_bytes, seal,
269 metrics, s->mmap, s->deferred_closes, NULL((void*)0), &f);
270
271 if (r < 0)
272 return r;
273
274 r = journal_file_enable_post_change_timer(f, s->event, POST_CHANGE_TIMER_INTERVAL_USEC(250*((usec_t) 1000ULL)));
275 if (r < 0)
276 return r;
277
278 *ret = TAKE_PTR(f)({ typeof(f) _ptr_ = (f); (f) = ((void*)0); _ptr_; });
279 return r;
280}
281
282static bool_Bool flushed_flag_is_set(void) {
283 return access("/run/systemd/journal/flushed", F_OK0) >= 0;
284}
285
286static int system_journal_open(Server *s, bool_Bool flush_requested) {
287 const char *fn;
288 int r = 0;
289
290 if (!s->system_journal &&
291 IN_SET(s->storage, STORAGE_PERSISTENT, STORAGE_AUTO)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){STORAGE_PERSISTENT, STORAGE_AUTO})/sizeof
(int)]; switch(s->storage) { case STORAGE_PERSISTENT: case
STORAGE_AUTO: _found = 1; break; default: break; } _found; }
)
&&
292 (flush_requested || flushed_flag_is_set())) {
293
294 /* If in auto mode: first try to create the machine
295 * path, but not the prefix.
296 *
297 * If in persistent mode: create /var/log/journal and
298 * the machine path */
299
300 if (s->storage == STORAGE_PERSISTENT)
301 (void) mkdir_p("/var/log/journal/", 0755);
302
303 (void) mkdir(s->system_storage.path, 0755);
304
305 fn = strjoina(s->system_storage.path, "/system.journal")({ const char *_appendees_[] = { s->system_storage.path, "/system.journal"
}; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ =
0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_
)/sizeof((_appendees_)[0]), ((void)0))) && _appendees_
[_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca
(_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; })
;
306 r = open_journal(s, true1, fn, O_RDWR02|O_CREAT0100, s->seal, &s->system_storage.metrics, &s->system_journal);
307 if (r >= 0) {
308 server_add_acls(s->system_journal, 0);
309 (void) cache_space_refresh(s, &s->system_storage);
310 patch_min_use(&s->system_storage);
311 } else if (r < 0) {
312 if (!IN_SET(r, -ENOENT, -EROFS)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){-2, -30})/sizeof(int)]; switch(r) { case
-2: case -30: _found = 1; break; default: break; } _found; }
)
)
313 log_warning_errno(r, "Failed to open system journal: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 313, __func__, "Failed to open system journal: %m"
) : -abs(_e); })
;
314
315 r = 0;
316 }
317
318 /* If the runtime journal is open, and we're post-flush, we're
319 * recovering from a failed system journal rotate (ENOSPC)
320 * for which the runtime journal was reopened.
321 *
322 * Perform an implicit flush to var, leaving the runtime
323 * journal closed, now that the system journal is back.
324 */
325 if (!flush_requested)
326 (void) server_flush_to_var(s, true1);
327 }
328
329 if (!s->runtime_journal &&
330 (s->storage != STORAGE_NONE)) {
331
332 fn = strjoina(s->runtime_storage.path, "/system.journal")({ const char *_appendees_[] = { s->runtime_storage.path, "/system.journal"
}; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ =
0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_
)/sizeof((_appendees_)[0]), ((void)0))) && _appendees_
[_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca
(_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; })
;
333
334 if (s->system_journal) {
335
336 /* Try to open the runtime journal, but only
337 * if it already exists, so that we can flush
338 * it into the system journal */
339
340 r = open_journal(s, false0, fn, O_RDWR02, false0, &s->runtime_storage.metrics, &s->runtime_journal);
341 if (r < 0) {
342 if (r != -ENOENT2)
343 log_warning_errno(r, "Failed to open runtime journal: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 343, __func__, "Failed to open runtime journal: %m"
) : -abs(_e); })
;
344
345 r = 0;
346 }
347
348 } else {
349
350 /* OK, we really need the runtime journal, so create
351 * it if necessary. */
352
353 (void) mkdir("/run/log", 0755);
354 (void) mkdir("/run/log/journal", 0755);
355 (void) mkdir_parents(fn, 0750);
356
357 r = open_journal(s, true1, fn, O_RDWR02|O_CREAT0100, false0, &s->runtime_storage.metrics, &s->runtime_journal);
358 if (r < 0)
359 return log_error_errno(r, "Failed to open runtime journal: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 359, __func__, "Failed to open runtime journal: %m"
) : -abs(_e); })
;
360 }
361
362 if (s->runtime_journal) {
363 server_add_acls(s->runtime_journal, 0);
364 (void) cache_space_refresh(s, &s->runtime_storage);
365 patch_min_use(&s->runtime_storage);
366 }
367 }
368
369 return r;
370}
371
372static JournalFile* find_journal(Server *s, uid_t uid) {
373 _cleanup_free___attribute__((cleanup(freep))) char *p = NULL((void*)0);
374 int r;
375 JournalFile *f;
376 sd_id128_t machine;
377
378 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 378, __PRETTY_FUNCTION__); } while (0)
;
379
380 /* A rotate that fails to create the new journal (ENOSPC) leaves the
381 * rotated journal as NULL. Unless we revisit opening, even after
382 * space is made available we'll continue to return NULL indefinitely.
383 *
384 * system_journal_open() is a noop if the journals are already open, so
385 * we can just call it here to recover from failed rotates (or anything
386 * else that's left the journals as NULL).
387 *
388 * Fixes https://github.com/systemd/systemd/issues/3968 */
389 (void) system_journal_open(s, false0);
390
391 /* We split up user logs only on /var, not on /run. If the
392 * runtime file is open, we write to it exclusively, in order
393 * to guarantee proper order as soon as we flush /run to
394 * /var and close the runtime file. */
395
396 if (s->runtime_journal)
397 return s->runtime_journal;
398
399 if (uid_for_system_journal(uid))
400 return s->system_journal;
401
402 r = sd_id128_get_machine(&machine);
403 if (r < 0)
404 return s->system_journal;
405
406 f = ordered_hashmap_get(s->user_journals, UID_TO_PTR(uid)((void*) (((uintptr_t) (uid))+1)));
407 if (f)
408 return f;
409
410 if (asprintf(&p, "/var/log/journal/" SD_ID128_FORMAT_STR"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" "/user-"UID_FMT"%" "u"".journal",
411 SD_ID128_FORMAT_VAL(machine)(machine).bytes[0], (machine).bytes[1], (machine).bytes[2], (
machine).bytes[3], (machine).bytes[4], (machine).bytes[5], (machine
).bytes[6], (machine).bytes[7], (machine).bytes[8], (machine)
.bytes[9], (machine).bytes[10], (machine).bytes[11], (machine
).bytes[12], (machine).bytes[13], (machine).bytes[14], (machine
).bytes[15]
, uid) < 0)
412 return s->system_journal;
413
414 while (ordered_hashmap_size(s->user_journals) >= USER_JOURNALS_MAX1024) {
415 /* Too many open? Then let's close one */
416 f = ordered_hashmap_steal_first(s->user_journals);
417 assert(f)do { if ((__builtin_expect(!!(!(f)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("f"), "../src/journal/journald-server.c"
, 417, __PRETTY_FUNCTION__); } while (0)
;
418 (void) journal_file_close(f);
419 }
420
421 r = open_journal(s, true1, p, O_RDWR02|O_CREAT0100, s->seal, &s->system_storage.metrics, &f);
422 if (r < 0)
423 return s->system_journal;
424
425 server_add_acls(f, uid);
426
427 r = ordered_hashmap_put(s->user_journals, UID_TO_PTR(uid)((void*) (((uintptr_t) (uid))+1)), f);
428 if (r < 0) {
429 (void) journal_file_close(f);
430 return s->system_journal;
431 }
432
433 return f;
434}
435
436static int do_rotate(
437 Server *s,
438 JournalFile **f,
439 const char* name,
440 bool_Bool seal,
441 uint32_t uid) {
442
443 int r;
444 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 444, __PRETTY_FUNCTION__); } while (0)
;
445
446 if (!*f)
447 return -EINVAL22;
448
449 r = journal_file_rotate(f, s->compress.enabled, s->compress.threshold_bytes, seal, s->deferred_closes);
450 if (r < 0) {
451 if (*f)
452 return log_error_errno(r, "Failed to rotate %s: %m", (*f)->path)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 452, __func__, "Failed to rotate %s: %m"
, (*f)->path) : -abs(_e); })
;
453 else
454 return log_error_errno(r, "Failed to create new %s journal: %m", name)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 454, __func__, "Failed to create new %s journal: %m"
, name) : -abs(_e); })
;
455 }
456
457 server_add_acls(*f, uid);
458
459 return r;
460}
461
462void server_rotate(Server *s) {
463 JournalFile *f;
464 void *k;
465 Iterator i;
466 int r;
467
468 log_debug("Rotating...")({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 468, __func__, "Rotating..."
) : -abs(_e); })
;
469
470 (void) do_rotate(s, &s->runtime_journal, "runtime", false0, 0);
471 (void) do_rotate(s, &s->system_journal, "system", s->seal, 0);
472
473 ORDERED_HASHMAP_FOREACH_KEY(f, k, s->user_journals, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); ordered_hashmap_iterate((s->user_journals
), &(i), (void**)&(f), (const void**) &(k)); )
{
474 r = do_rotate(s, &f, "user", s->seal, PTR_TO_UID(k)((uid_t) (((uintptr_t) (k))-1)));
475 if (r >= 0)
476 ordered_hashmap_replace(s->user_journals, k, f);
477 else if (!f)
478 /* Old file has been closed and deallocated */
479 ordered_hashmap_remove(s->user_journals, k);
480 }
481
482 /* Perform any deferred closes which aren't still offlining. */
483 SET_FOREACH(f, s->deferred_closes, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); set_iterate((s->deferred_closes)
, &(i), (void**)&(f)); )
484 if (!journal_file_is_offlining(f)) {
485 (void) set_remove(s->deferred_closes, f);
486 (void) journal_file_close(f);
487 }
488}
489
490void server_sync(Server *s) {
491 JournalFile *f;
492 Iterator i;
493 int r;
494
495 if (s->system_journal) {
496 r = journal_file_set_offline(s->system_journal, false0);
497 if (r < 0)
498 log_warning_errno(r, "Failed to sync system journal, ignoring: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 498, __func__, "Failed to sync system journal, ignoring: %m"
) : -abs(_e); })
;
499 }
500
501 ORDERED_HASHMAP_FOREACH(f, s->user_journals, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); ordered_hashmap_iterate((s->user_journals
), &(i), (void**)&(f), ((void*)0)); )
{
502 r = journal_file_set_offline(f, false0);
503 if (r < 0)
504 log_warning_errno(r, "Failed to sync user journal, ignoring: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 504, __func__, "Failed to sync user journal, ignoring: %m"
) : -abs(_e); })
;
505 }
506
507 if (s->sync_event_source) {
508 r = sd_event_source_set_enabled(s->sync_event_source, SD_EVENT_OFF);
509 if (r < 0)
510 log_error_errno(r, "Failed to disable sync timer source: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 510, __func__, "Failed to disable sync timer source: %m"
) : -abs(_e); })
;
511 }
512
513 s->sync_scheduled = false0;
514}
515
516static void do_vacuum(Server *s, JournalStorage *storage, bool_Bool verbose) {
517
518 int r;
519
520 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 520, __PRETTY_FUNCTION__); } while (0)
;
521 assert(storage)do { if ((__builtin_expect(!!(!(storage)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("storage"), "../src/journal/journald-server.c"
, 521, __PRETTY_FUNCTION__); } while (0)
;
522
523 (void) cache_space_refresh(s, storage);
524
525 if (verbose)
526 server_space_usage_message(s, storage);
527
528 r = journal_directory_vacuum(storage->path, storage->space.limit,
529 storage->metrics.n_max_files, s->max_retention_usec,
530 &s->oldest_file_usec, verbose);
531 if (r < 0 && r != -ENOENT2)
532 log_warning_errno(r, "Failed to vacuum %s, ignoring: %m", storage->path)({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 532, __func__, "Failed to vacuum %s, ignoring: %m"
, storage->path) : -abs(_e); })
;
533
534 cache_space_invalidate(&storage->space);
535}
536
537int server_vacuum(Server *s, bool_Bool verbose) {
538 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 538, __PRETTY_FUNCTION__); } while (0)
;
539
540 log_debug("Vacuuming...")({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 540, __func__, "Vacuuming..."
) : -abs(_e); })
;
541
542 s->oldest_file_usec = 0;
543
544 if (s->system_journal)
545 do_vacuum(s, &s->system_storage, verbose);
546 if (s->runtime_journal)
547 do_vacuum(s, &s->runtime_storage, verbose);
548
549 return 0;
550}
551
552static void server_cache_machine_id(Server *s) {
553 sd_id128_t id;
554 int r;
555
556 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 556, __PRETTY_FUNCTION__); } while (0)
;
557
558 r = sd_id128_get_machine(&id);
559 if (r < 0)
560 return;
561
562 sd_id128_to_string(id, stpcpy(s->machine_id_field, "_MACHINE_ID="));
563}
564
565static void server_cache_boot_id(Server *s) {
566 sd_id128_t id;
567 int r;
568
569 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 569, __PRETTY_FUNCTION__); } while (0)
;
570
571 r = sd_id128_get_boot(&id);
572 if (r < 0)
573 return;
574
575 sd_id128_to_string(id, stpcpy(s->boot_id_field, "_BOOT_ID="));
576}
577
578static void server_cache_hostname(Server *s) {
579 _cleanup_free___attribute__((cleanup(freep))) char *t = NULL((void*)0);
580 char *x;
581
582 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 582, __PRETTY_FUNCTION__); } while (0)
;
583
584 t = gethostname_malloc();
585 if (!t)
586 return;
587
588 x = strappend("_HOSTNAME=", t);
589 if (!x)
590 return;
591
592 free(s->hostname_field);
593 s->hostname_field = x;
594}
595
596static bool_Bool shall_try_append_again(JournalFile *f, int r) {
597 switch(r) {
598
599 case -E2BIG7: /* Hit configured limit */
600 case -EFBIG27: /* Hit fs limit */
601 case -EDQUOT122: /* Quota limit hit */
602 case -ENOSPC28: /* Disk full */
603 log_debug("%s: Allocation limit reached, rotating.", f->path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 603, __func__, "%s: Allocation limit reached, rotating."
, f->path) : -abs(_e); })
;
604 return true1;
605
606 case -EIO5: /* I/O error of some kind (mmap) */
607 log_warning("%s: IO error, rotating.", f->path)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 607, __func__, "%s: IO error, rotating."
, f->path) : -abs(_e); })
;
608 return true1;
609
610 case -EHOSTDOWN112: /* Other machine */
611 log_info("%s: Journal file from other machine, rotating.", f->path)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 611, __func__, "%s: Journal file from other machine, rotating."
, f->path) : -abs(_e); })
;
612 return true1;
613
614 case -EBUSY16: /* Unclean shutdown */
615 log_info("%s: Unclean shutdown, rotating.", f->path)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 615, __func__, "%s: Unclean shutdown, rotating."
, f->path) : -abs(_e); })
;
616 return true1;
617
618 case -EPROTONOSUPPORT93: /* Unsupported feature */
619 log_info("%s: Unsupported feature, rotating.", f->path)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 619, __func__, "%s: Unsupported feature, rotating."
, f->path) : -abs(_e); })
;
620 return true1;
621
622 case -EBADMSG74: /* Corrupted */
623 case -ENODATA61: /* Truncated */
624 case -ESHUTDOWN108: /* Already archived */
625 log_warning("%s: Journal file corrupted, rotating.", f->path)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 625, __func__, "%s: Journal file corrupted, rotating."
, f->path) : -abs(_e); })
;
626 return true1;
627
628 case -EIDRM43: /* Journal file has been deleted */
629 log_warning("%s: Journal file has been deleted, rotating.", f->path)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 629, __func__, "%s: Journal file has been deleted, rotating."
, f->path) : -abs(_e); })
;
630 return true1;
631
632 case -ETXTBSY26: /* Journal file is from the future */
633 log_warning("%s: Journal file is from the future, rotating.", f->path)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 633, __func__, "%s: Journal file is from the future, rotating."
, f->path) : -abs(_e); })
;
634 return true1;
635
636 default:
637 return false0;
638 }
639}
640
641static void write_to_journal(Server *s, uid_t uid, struct iovec *iovec, size_t n, int priority) {
642 bool_Bool vacuumed = false0, rotate = false0;
643 struct dual_timestamp ts;
644 JournalFile *f;
645 int r;
646
647 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 647, __PRETTY_FUNCTION__); } while (0)
;
648 assert(iovec)do { if ((__builtin_expect(!!(!(iovec)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("iovec"), "../src/journal/journald-server.c"
, 648, __PRETTY_FUNCTION__); } while (0)
;
649 assert(n > 0)do { if ((__builtin_expect(!!(!(n > 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("n > 0"), "../src/journal/journald-server.c"
, 649, __PRETTY_FUNCTION__); } while (0)
;
650
651 /* Get the closest, linearized time we have for this log event from the event loop. (Note that we do not use
652 * the source time, and not even the time the event was originally seen, but instead simply the time we started
653 * processing it, as we want strictly linear ordering in what we write out.) */
654 assert_se(sd_event_now(s->event, CLOCK_REALTIME, &ts.realtime) >= 0)do { if ((__builtin_expect(!!(!(sd_event_now(s->event, 0, &
ts.realtime) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("sd_event_now(s->event, CLOCK_REALTIME, &ts.realtime) >= 0"
), "../src/journal/journald-server.c", 654, __PRETTY_FUNCTION__
); } while (0)
;
655 assert_se(sd_event_now(s->event, CLOCK_MONOTONIC, &ts.monotonic) >= 0)do { if ((__builtin_expect(!!(!(sd_event_now(s->event, 1, &
ts.monotonic) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("sd_event_now(s->event, CLOCK_MONOTONIC, &ts.monotonic) >= 0"
), "../src/journal/journald-server.c", 655, __PRETTY_FUNCTION__
); } while (0)
;
656
657 if (ts.realtime < s->last_realtime_clock) {
658 /* When the time jumps backwards, let's immediately rotate. Of course, this should not happen during
659 * regular operation. However, when it does happen, then we should make sure that we start fresh files
660 * to ensure that the entries in the journal files are strictly ordered by time, in order to ensure
661 * bisection works correctly. */
662
663 log_debug("Time jumped backwards, rotating.")({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 663, __func__, "Time jumped backwards, rotating."
) : -abs(_e); })
;
664 rotate = true1;
665 } else {
666
667 f = find_journal(s, uid);
668 if (!f)
669 return;
670
671 if (journal_file_rotate_suggested(f, s->max_file_usec)) {
672 log_debug("%s: Journal header limits reached or header out-of-date, rotating.", f->path)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 672, __func__, "%s: Journal header limits reached or header out-of-date, rotating."
, f->path) : -abs(_e); })
;
673 rotate = true1;
674 }
675 }
676
677 if (rotate) {
678 server_rotate(s);
679 server_vacuum(s, false0);
680 vacuumed = true1;
681
682 f = find_journal(s, uid);
683 if (!f)
684 return;
685 }
686
687 s->last_realtime_clock = ts.realtime;
688
689 r = journal_file_append_entry(f, &ts, NULL((void*)0), iovec, n, &s->seqnum, NULL((void*)0), NULL((void*)0));
690 if (r >= 0) {
691 server_schedule_sync(s, priority);
692 return;
693 }
694
695 if (vacuumed || !shall_try_append_again(f, r)) {
696 log_error_errno(r, "Failed to write entry (%zu items, %zu bytes), ignoring: %m", n, IOVEC_TOTAL_SIZE(iovec, n))({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 696, __func__, "Failed to write entry (%zu items, %zu bytes), ignoring: %m"
, n, IOVEC_TOTAL_SIZE(iovec, n)) : -abs(_e); })
;
697 return;
698 }
699
700 server_rotate(s);
701 server_vacuum(s, false0);
702
703 f = find_journal(s, uid);
704 if (!f)
705 return;
706
707 log_debug("Retrying write.")({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 707, __func__, "Retrying write."
) : -abs(_e); })
;
708 r = journal_file_append_entry(f, &ts, NULL((void*)0), iovec, n, &s->seqnum, NULL((void*)0), NULL((void*)0));
709 if (r < 0)
710 log_error_errno(r, "Failed to write entry (%zu items, %zu bytes) despite vacuuming, ignoring: %m", n, IOVEC_TOTAL_SIZE(iovec, n))({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 710, __func__, "Failed to write entry (%zu items, %zu bytes) despite vacuuming, ignoring: %m"
, n, IOVEC_TOTAL_SIZE(iovec, n)) : -abs(_e); })
;
711 else
712 server_schedule_sync(s, priority);
713}
714
715#define IOVEC_ADD_NUMERIC_FIELD(iovec, n, value, type, isset, format, field)if (isset) { char *k; k = ({ do { if ((__builtin_expect(!!(!(
!size_multiply_overflow(sizeof(char), (sizeof(""field "=""") -
1) + (2+(sizeof(type) <= 1 ? 3 : sizeof(type) <= 2 ? 5
: sizeof(type) <= 4 ? 10 : sizeof(type) <= 8 ? 20 : sizeof
(int[-2*(sizeof(type) > 8)]))) + 1))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"field \"=\"\"\") - 1) + (2+(sizeof(type) <= 1 ? 3 : sizeof(type) <= 2 ? 5 : sizeof(type) <= 4 ? 10 : sizeof(type) <= 8 ? 20 : sizeof(int[-2*(sizeof(type) > 8)]))) + 1)"
), "../src/journal/journald-server.c", 715, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
(""field "=""") - 1) + (2+(sizeof(type) <= 1 ? 3 : sizeof(
type) <= 2 ? 5 : sizeof(type) <= 4 ? 10 : sizeof(type) <=
8 ? 20 : sizeof(int[-2*(sizeof(type) > 8)]))) + 1)); }); sprintf
(k, field "=" format, value); iovec[n++] = (struct iovec) { .
iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
\
716 if (isset(value)) { \
717 char *k; \
718 k = newa(char, STRLEN(field "=") + DECIMAL_STR_MAX(type) + 1)({ do { if ((__builtin_expect(!!(!(!size_multiply_overflow(sizeof
(char), (sizeof(""field "=""") - 1) + (2+(sizeof(type) <= 1
? 3 : sizeof(type) <= 2 ? 5 : sizeof(type) <= 4 ? 10 :
sizeof(type) <= 8 ? 20 : sizeof(int[-2*(sizeof(type) >
8)]))) + 1))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"field \"=\"\"\") - 1) + (2+(sizeof(type) <= 1 ? 3 : sizeof(type) <= 2 ? 5 : sizeof(type) <= 4 ? 10 : sizeof(type) <= 8 ? 20 : sizeof(int[-2*(sizeof(type) > 8)]))) + 1)"
), "../src/journal/journald-server.c", 718, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
(""field "=""") - 1) + (2+(sizeof(type) <= 1 ? 3 : sizeof(
type) <= 2 ? 5 : sizeof(type) <= 4 ? 10 : sizeof(type) <=
8 ? 20 : sizeof(int[-2*(sizeof(type) > 8)]))) + 1)); })
; \
719 sprintf(k, field "=" format, value); \
720 iovec[n++] = IOVEC_MAKE_STRING(k)(struct iovec) { .iov_base = ((char*) k), .iov_len = (strlen(
k)) }
; \
721 }
722
723#define IOVEC_ADD_STRING_FIELD(iovec, n, value, field)if (!isempty(value)) { char *k; k = ({ const char *_appendees_
[] = { field "=", value }; char *_d_, *_p_; size_t _len_ = 0;
size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _len_ += strlen
(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1);
for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr(
!__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); iovec[n++] = (struct
iovec) { .iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
\
724 if (!isempty(value)) { \
725 char *k; \
726 k = strjoina(field "=", value)({ const char *_appendees_[] = { field "=", value }; char *_d_
, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__
(__builtin_choose_expr( !__builtin_types_compatible_p(typeof
(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_
)/sizeof((_appendees_)[0]), ((void)0))) && _appendees_
[_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca
(_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; })
; \
727 iovec[n++] = IOVEC_MAKE_STRING(k)(struct iovec) { .iov_base = ((char*) k), .iov_len = (strlen(
k)) }
; \
728 }
729
730#define IOVEC_ADD_ID128_FIELD(iovec, n, value, field)if (!sd_id128_is_null(value)) { char *k; k = ({ do { if ((__builtin_expect
(!!(!(!size_multiply_overflow(sizeof(char), (sizeof(""field "="
"") - 1) + 33))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"field \"=\"\"\") - 1) + 33)"
), "../src/journal/journald-server.c", 730, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
(""field "=""") - 1) + 33)); }); sd_id128_to_string(value, stpcpy
(k, field "=")); iovec[n++] = (struct iovec) { .iov_base = ((
char*) k), .iov_len = (strlen(k)) }; }
\
731 if (!sd_id128_is_null(value)) { \
732 char *k; \
733 k = newa(char, STRLEN(field "=") + SD_ID128_STRING_MAX)({ do { if ((__builtin_expect(!!(!(!size_multiply_overflow(sizeof
(char), (sizeof(""field "=""") - 1) + 33))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"field \"=\"\"\") - 1) + 33)"
), "../src/journal/journald-server.c", 733, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
(""field "=""") - 1) + 33)); })
; \
734 sd_id128_to_string(value, stpcpy(k, field "=")); \
735 iovec[n++] = IOVEC_MAKE_STRING(k)(struct iovec) { .iov_base = ((char*) k), .iov_len = (strlen(
k)) }
; \
736 }
737
738#define IOVEC_ADD_SIZED_FIELD(iovec, n, value, value_size, field)if (value_size > 0) { char *k; k = ({ do { if ((__builtin_expect
(!!(!(!size_multiply_overflow(sizeof(char), (sizeof(""field "="
"") - 1) + value_size + 1))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"field \"=\"\"\") - 1) + value_size + 1)"
), "../src/journal/journald-server.c", 738, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
(""field "=""") - 1) + value_size + 1)); }); *((char*) mempcpy
(stpcpy(k, field "="), value, value_size)) = 0; iovec[n++] = (
struct iovec) { .iov_base = ((char*) k), .iov_len = (strlen(k
)) }; }
\
739 if (value_size > 0) { \
740 char *k; \
741 k = newa(char, STRLEN(field "=") + value_size + 1)({ do { if ((__builtin_expect(!!(!(!size_multiply_overflow(sizeof
(char), (sizeof(""field "=""") - 1) + value_size + 1))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"field \"=\"\"\") - 1) + value_size + 1)"
), "../src/journal/journald-server.c", 741, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
(""field "=""") - 1) + value_size + 1)); })
; \
742 *((char*) mempcpy(stpcpy(k, field "="), value, value_size)) = 0; \
743 iovec[n++] = IOVEC_MAKE_STRING(k)(struct iovec) { .iov_base = ((char*) k), .iov_len = (strlen(
k)) }
; \
744 } \
745
746static void dispatch_message_real(
747 Server *s,
748 struct iovec *iovec, size_t n, size_t m,
749 const ClientContext *c,
750 const struct timeval *tv,
751 int priority,
752 pid_t object_pid) {
753
754 char source_time[sizeof("_SOURCE_REALTIME_TIMESTAMP=") + DECIMAL_STR_MAX(usec_t)(2+(sizeof(usec_t) <= 1 ? 3 : sizeof(usec_t) <= 2 ? 5 :
sizeof(usec_t) <= 4 ? 10 : sizeof(usec_t) <= 8 ? 20 : sizeof
(int[-2*(sizeof(usec_t) > 8)])))
];
755 _cleanup_free___attribute__((cleanup(freep))) char *cmdline1 = NULL((void*)0), *cmdline2 = NULL((void*)0);
756 uid_t journal_uid;
757 ClientContext *o;
758
759 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 759, __PRETTY_FUNCTION__); } while (0)
;
760 assert(iovec)do { if ((__builtin_expect(!!(!(iovec)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("iovec"), "../src/journal/journald-server.c"
, 760, __PRETTY_FUNCTION__); } while (0)
;
761 assert(n > 0)do { if ((__builtin_expect(!!(!(n > 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("n > 0"), "../src/journal/journald-server.c"
, 761, __PRETTY_FUNCTION__); } while (0)
;
762 assert(n +do { if ((__builtin_expect(!!(!(n + 22 + (pid_is_valid(object_pid
) ? 18 : 0) + client_context_extra_fields_n_iovec(c) <= m)
),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("n + N_IOVEC_META_FIELDS + (pid_is_valid(object_pid) ? N_IOVEC_OBJECT_FIELDS : 0) + client_context_extra_fields_n_iovec(c) <= m"
), "../src/journal/journald-server.c", 765, __PRETTY_FUNCTION__
); } while (0)
763 N_IOVEC_META_FIELDS +do { if ((__builtin_expect(!!(!(n + 22 + (pid_is_valid(object_pid
) ? 18 : 0) + client_context_extra_fields_n_iovec(c) <= m)
),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("n + N_IOVEC_META_FIELDS + (pid_is_valid(object_pid) ? N_IOVEC_OBJECT_FIELDS : 0) + client_context_extra_fields_n_iovec(c) <= m"
), "../src/journal/journald-server.c", 765, __PRETTY_FUNCTION__
); } while (0)
764 (pid_is_valid(object_pid) ? N_IOVEC_OBJECT_FIELDS : 0) +do { if ((__builtin_expect(!!(!(n + 22 + (pid_is_valid(object_pid
) ? 18 : 0) + client_context_extra_fields_n_iovec(c) <= m)
),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("n + N_IOVEC_META_FIELDS + (pid_is_valid(object_pid) ? N_IOVEC_OBJECT_FIELDS : 0) + client_context_extra_fields_n_iovec(c) <= m"
), "../src/journal/journald-server.c", 765, __PRETTY_FUNCTION__
); } while (0)
765 client_context_extra_fields_n_iovec(c) <= m)do { if ((__builtin_expect(!!(!(n + 22 + (pid_is_valid(object_pid
) ? 18 : 0) + client_context_extra_fields_n_iovec(c) <= m)
),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("n + N_IOVEC_META_FIELDS + (pid_is_valid(object_pid) ? N_IOVEC_OBJECT_FIELDS : 0) + client_context_extra_fields_n_iovec(c) <= m"
), "../src/journal/journald-server.c", 765, __PRETTY_FUNCTION__
); } while (0)
;
766
767 if (c) {
768 IOVEC_ADD_NUMERIC_FIELD(iovec, n, c->pid, pid_t, pid_is_valid, PID_FMT, "_PID")if (pid_is_valid(c->pid)) { char *k; k = ({ do { if ((__builtin_expect
(!!(!(!size_multiply_overflow(sizeof(char), (sizeof("""_PID" "="
"") - 1) + (2+(sizeof(pid_t) <= 1 ? 3 : sizeof(pid_t) <=
2 ? 5 : sizeof(pid_t) <= 4 ? 10 : sizeof(pid_t) <= 8 ?
20 : sizeof(int[-2*(sizeof(pid_t) > 8)]))) + 1))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"\"_PID\" \"=\"\"\") - 1) + (2+(sizeof(pid_t) <= 1 ? 3 : sizeof(pid_t) <= 2 ? 5 : sizeof(pid_t) <= 4 ? 10 : sizeof(pid_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(pid_t) > 8)]))) + 1)"
), "../src/journal/journald-server.c", 768, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
("""_PID" "=""") - 1) + (2+(sizeof(pid_t) <= 1 ? 3 : sizeof
(pid_t) <= 2 ? 5 : sizeof(pid_t) <= 4 ? 10 : sizeof(pid_t
) <= 8 ? 20 : sizeof(int[-2*(sizeof(pid_t) > 8)]))) + 1
)); }); sprintf(k, "_PID" "=" "%" "i", c->pid); iovec[n++]
= (struct iovec) { .iov_base = ((char*) k), .iov_len = (strlen
(k)) }; }
;
769 IOVEC_ADD_NUMERIC_FIELD(iovec, n, c->uid, uid_t, uid_is_valid, UID_FMT, "_UID")if (uid_is_valid(c->uid)) { char *k; k = ({ do { if ((__builtin_expect
(!!(!(!size_multiply_overflow(sizeof(char), (sizeof("""_UID" "="
"") - 1) + (2+(sizeof(uid_t) <= 1 ? 3 : sizeof(uid_t) <=
2 ? 5 : sizeof(uid_t) <= 4 ? 10 : sizeof(uid_t) <= 8 ?
20 : sizeof(int[-2*(sizeof(uid_t) > 8)]))) + 1))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"\"_UID\" \"=\"\"\") - 1) + (2+(sizeof(uid_t) <= 1 ? 3 : sizeof(uid_t) <= 2 ? 5 : sizeof(uid_t) <= 4 ? 10 : sizeof(uid_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(uid_t) > 8)]))) + 1)"
), "../src/journal/journald-server.c", 769, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
("""_UID" "=""") - 1) + (2+(sizeof(uid_t) <= 1 ? 3 : sizeof
(uid_t) <= 2 ? 5 : sizeof(uid_t) <= 4 ? 10 : sizeof(uid_t
) <= 8 ? 20 : sizeof(int[-2*(sizeof(uid_t) > 8)]))) + 1
)); }); sprintf(k, "_UID" "=" "%" "u", c->uid); iovec[n++]
= (struct iovec) { .iov_base = ((char*) k), .iov_len = (strlen
(k)) }; }
;
770 IOVEC_ADD_NUMERIC_FIELD(iovec, n, c->gid, gid_t, gid_is_valid, GID_FMT, "_GID")if (gid_is_valid(c->gid)) { char *k; k = ({ do { if ((__builtin_expect
(!!(!(!size_multiply_overflow(sizeof(char), (sizeof("""_GID" "="
"") - 1) + (2+(sizeof(gid_t) <= 1 ? 3 : sizeof(gid_t) <=
2 ? 5 : sizeof(gid_t) <= 4 ? 10 : sizeof(gid_t) <= 8 ?
20 : sizeof(int[-2*(sizeof(gid_t) > 8)]))) + 1))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"\"_GID\" \"=\"\"\") - 1) + (2+(sizeof(gid_t) <= 1 ? 3 : sizeof(gid_t) <= 2 ? 5 : sizeof(gid_t) <= 4 ? 10 : sizeof(gid_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(gid_t) > 8)]))) + 1)"
), "../src/journal/journald-server.c", 770, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
("""_GID" "=""") - 1) + (2+(sizeof(gid_t) <= 1 ? 3 : sizeof
(gid_t) <= 2 ? 5 : sizeof(gid_t) <= 4 ? 10 : sizeof(gid_t
) <= 8 ? 20 : sizeof(int[-2*(sizeof(gid_t) > 8)]))) + 1
)); }); sprintf(k, "_GID" "=" "%" "u", c->gid); iovec[n++]
= (struct iovec) { .iov_base = ((char*) k), .iov_len = (strlen
(k)) }; }
;
771
772 IOVEC_ADD_STRING_FIELD(iovec, n, c->comm, "_COMM")if (!isempty(c->comm)) { char *k; k = ({ const char *_appendees_
[] = { "_COMM" "=", c->comm }; char *_d_, *_p_; size_t _len_
= 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _len_ += strlen
(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1);
for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr(
!__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); iovec[n++] = (struct
iovec) { .iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
; /* At most TASK_COMM_LENGTH (16 bytes) */
773 IOVEC_ADD_STRING_FIELD(iovec, n, c->exe, "_EXE")if (!isempty(c->exe)) { char *k; k = ({ const char *_appendees_
[] = { "_EXE" "=", c->exe }; char *_d_, *_p_; size_t _len_
= 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _len_ += strlen
(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca (_len_ + 1);
for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr(
!__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); iovec[n++] = (struct
iovec) { .iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
; /* A path, so at most PATH_MAX (4096 bytes) */
774
775 if (c->cmdline)
776 /* At most _SC_ARG_MAX (2MB usually), which is too much to put on stack.
777 * Let's use a heap allocation for this one. */
778 cmdline1 = set_iovec_string_field(iovec, &n, "_CMDLINE=", c->cmdline);
Value stored to 'cmdline1' is never read
779
780 IOVEC_ADD_STRING_FIELD(iovec, n, c->capeff, "_CAP_EFFECTIVE")if (!isempty(c->capeff)) { char *k; k = ({ const char *_appendees_
[] = { "_CAP_EFFECTIVE" "=", c->capeff }; char *_d_, *_p_;
size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__
(__builtin_choose_expr( !__builtin_types_compatible_p(typeof
(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_
)/sizeof((_appendees_)[0]), ((void)0))) && _appendees_
[_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca
(_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); iovec[n++] = (struct
iovec) { .iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
; /* Read from /proc/.../status */
781 IOVEC_ADD_SIZED_FIELD(iovec, n, c->label, c->label_size, "_SELINUX_CONTEXT")if (c->label_size > 0) { char *k; k = ({ do { if ((__builtin_expect
(!!(!(!size_multiply_overflow(sizeof(char), (sizeof("""_SELINUX_CONTEXT"
"=""") - 1) + c->label_size + 1))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"\"_SELINUX_CONTEXT\" \"=\"\"\") - 1) + c->label_size + 1)"
), "../src/journal/journald-server.c", 781, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
("""_SELINUX_CONTEXT" "=""") - 1) + c->label_size + 1)); }
); *((char*) mempcpy(stpcpy(k, "_SELINUX_CONTEXT" "="), c->
label, c->label_size)) = 0; iovec[n++] = (struct iovec) { .
iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
;
782 IOVEC_ADD_NUMERIC_FIELD(iovec, n, c->auditid, uint32_t, audit_session_is_valid, "%" PRIu32, "_AUDIT_SESSION")if (audit_session_is_valid(c->auditid)) { char *k; k = ({ do
{ if ((__builtin_expect(!!(!(!size_multiply_overflow(sizeof(
char), (sizeof("""_AUDIT_SESSION" "=""") - 1) + (2+(sizeof(uint32_t
) <= 1 ? 3 : sizeof(uint32_t) <= 2 ? 5 : sizeof(uint32_t
) <= 4 ? 10 : sizeof(uint32_t) <= 8 ? 20 : sizeof(int[-
2*(sizeof(uint32_t) > 8)]))) + 1))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"\"_AUDIT_SESSION\" \"=\"\"\") - 1) + (2+(sizeof(uint32_t) <= 1 ? 3 : sizeof(uint32_t) <= 2 ? 5 : sizeof(uint32_t) <= 4 ? 10 : sizeof(uint32_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(uint32_t) > 8)]))) + 1)"
), "../src/journal/journald-server.c", 782, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
("""_AUDIT_SESSION" "=""") - 1) + (2+(sizeof(uint32_t) <= 1
? 3 : sizeof(uint32_t) <= 2 ? 5 : sizeof(uint32_t) <= 4
? 10 : sizeof(uint32_t) <= 8 ? 20 : sizeof(int[-2*(sizeof
(uint32_t) > 8)]))) + 1)); }); sprintf(k, "_AUDIT_SESSION"
"=" "%" "u", c->auditid); iovec[n++] = (struct iovec) { .
iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
;
783 IOVEC_ADD_NUMERIC_FIELD(iovec, n, c->loginuid, uid_t, uid_is_valid, UID_FMT, "_AUDIT_LOGINUID")if (uid_is_valid(c->loginuid)) { char *k; k = ({ do { if (
(__builtin_expect(!!(!(!size_multiply_overflow(sizeof(char), (
sizeof("""_AUDIT_LOGINUID" "=""") - 1) + (2+(sizeof(uid_t) <=
1 ? 3 : sizeof(uid_t) <= 2 ? 5 : sizeof(uid_t) <= 4 ? 10
: sizeof(uid_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(uid_t) >
8)]))) + 1))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"\"_AUDIT_LOGINUID\" \"=\"\"\") - 1) + (2+(sizeof(uid_t) <= 1 ? 3 : sizeof(uid_t) <= 2 ? 5 : sizeof(uid_t) <= 4 ? 10 : sizeof(uid_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(uid_t) > 8)]))) + 1)"
), "../src/journal/journald-server.c", 783, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
("""_AUDIT_LOGINUID" "=""") - 1) + (2+(sizeof(uid_t) <= 1 ?
3 : sizeof(uid_t) <= 2 ? 5 : sizeof(uid_t) <= 4 ? 10 :
sizeof(uid_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(uid_t) >
8)]))) + 1)); }); sprintf(k, "_AUDIT_LOGINUID" "=" "%" "u", c
->loginuid); iovec[n++] = (struct iovec) { .iov_base = ((char
*) k), .iov_len = (strlen(k)) }; }
;
784
785 IOVEC_ADD_STRING_FIELD(iovec, n, c->cgroup, "_SYSTEMD_CGROUP")if (!isempty(c->cgroup)) { char *k; k = ({ const char *_appendees_
[] = { "_SYSTEMD_CGROUP" "=", c->cgroup }; char *_d_, *_p_
; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__
(__builtin_choose_expr( !__builtin_types_compatible_p(typeof
(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_
)/sizeof((_appendees_)[0]), ((void)0))) && _appendees_
[_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca
(_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); iovec[n++] = (struct
iovec) { .iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
; /* A path */
786 IOVEC_ADD_STRING_FIELD(iovec, n, c->session, "_SYSTEMD_SESSION")if (!isempty(c->session)) { char *k; k = ({ const char *_appendees_
[] = { "_SYSTEMD_SESSION" "=", c->session }; char *_d_, *_p_
; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__
(__builtin_choose_expr( !__builtin_types_compatible_p(typeof
(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_
)/sizeof((_appendees_)[0]), ((void)0))) && _appendees_
[_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca
(_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); iovec[n++] = (struct
iovec) { .iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
;
787 IOVEC_ADD_NUMERIC_FIELD(iovec, n, c->owner_uid, uid_t, uid_is_valid, UID_FMT, "_SYSTEMD_OWNER_UID")if (uid_is_valid(c->owner_uid)) { char *k; k = ({ do { if (
(__builtin_expect(!!(!(!size_multiply_overflow(sizeof(char), (
sizeof("""_SYSTEMD_OWNER_UID" "=""") - 1) + (2+(sizeof(uid_t)
<= 1 ? 3 : sizeof(uid_t) <= 2 ? 5 : sizeof(uid_t) <=
4 ? 10 : sizeof(uid_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(
uid_t) > 8)]))) + 1))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"\"_SYSTEMD_OWNER_UID\" \"=\"\"\") - 1) + (2+(sizeof(uid_t) <= 1 ? 3 : sizeof(uid_t) <= 2 ? 5 : sizeof(uid_t) <= 4 ? 10 : sizeof(uid_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(uid_t) > 8)]))) + 1)"
), "../src/journal/journald-server.c", 787, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
("""_SYSTEMD_OWNER_UID" "=""") - 1) + (2+(sizeof(uid_t) <=
1 ? 3 : sizeof(uid_t) <= 2 ? 5 : sizeof(uid_t) <= 4 ? 10
: sizeof(uid_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(uid_t) >
8)]))) + 1)); }); sprintf(k, "_SYSTEMD_OWNER_UID" "=" "%" "u"
, c->owner_uid); iovec[n++] = (struct iovec) { .iov_base =
((char*) k), .iov_len = (strlen(k)) }; }
;
788 IOVEC_ADD_STRING_FIELD(iovec, n, c->unit, "_SYSTEMD_UNIT")if (!isempty(c->unit)) { char *k; k = ({ const char *_appendees_
[] = { "_SYSTEMD_UNIT" "=", c->unit }; char *_d_, *_p_; size_t
_len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (
__builtin_choose_expr( !__builtin_types_compatible_p(typeof(_appendees_
), typeof(&*(_appendees_))), sizeof(_appendees_)/sizeof((
_appendees_)[0]), ((void)0))) && _appendees_[_i_]; _i_
++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca
(_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); iovec[n++] = (struct
iovec) { .iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
; /* Unit names are bounded by UNIT_NAME_MAX */
789 IOVEC_ADD_STRING_FIELD(iovec, n, c->user_unit, "_SYSTEMD_USER_UNIT")if (!isempty(c->user_unit)) { char *k; k = ({ const char *
_appendees_[] = { "_SYSTEMD_USER_UNIT" "=", c->user_unit }
; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0
; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_
)/sizeof((_appendees_)[0]), ((void)0))) && _appendees_
[_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca
(_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); iovec[n++] = (struct
iovec) { .iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
;
790 IOVEC_ADD_STRING_FIELD(iovec, n, c->slice, "_SYSTEMD_SLICE")if (!isempty(c->slice)) { char *k; k = ({ const char *_appendees_
[] = { "_SYSTEMD_SLICE" "=", c->slice }; char *_d_, *_p_; size_t
_len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (
__builtin_choose_expr( !__builtin_types_compatible_p(typeof(_appendees_
), typeof(&*(_appendees_))), sizeof(_appendees_)/sizeof((
_appendees_)[0]), ((void)0))) && _appendees_[_i_]; _i_
++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca
(_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); iovec[n++] = (struct
iovec) { .iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
;
791 IOVEC_ADD_STRING_FIELD(iovec, n, c->user_slice, "_SYSTEMD_USER_SLICE")if (!isempty(c->user_slice)) { char *k; k = ({ const char *
_appendees_[] = { "_SYSTEMD_USER_SLICE" "=", c->user_slice
}; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ =
0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_
)/sizeof((_appendees_)[0]), ((void)0))) && _appendees_
[_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca
(_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); iovec[n++] = (struct
iovec) { .iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
;
792
793 IOVEC_ADD_ID128_FIELD(iovec, n, c->invocation_id, "_SYSTEMD_INVOCATION_ID")if (!sd_id128_is_null(c->invocation_id)) { char *k; k = ({
do { if ((__builtin_expect(!!(!(!size_multiply_overflow(sizeof
(char), (sizeof("""_SYSTEMD_INVOCATION_ID" "=""") - 1) + 33))
),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"\"_SYSTEMD_INVOCATION_ID\" \"=\"\"\") - 1) + 33)"
), "../src/journal/journald-server.c", 793, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
("""_SYSTEMD_INVOCATION_ID" "=""") - 1) + 33)); }); sd_id128_to_string
(c->invocation_id, stpcpy(k, "_SYSTEMD_INVOCATION_ID" "=")
); iovec[n++] = (struct iovec) { .iov_base = ((char*) k), .iov_len
= (strlen(k)) }; }
;
794
795 if (c->extra_fields_n_iovec > 0) {
796 memcpy(iovec + n, c->extra_fields_iovec, c->extra_fields_n_iovec * sizeof(struct iovec));
797 n += c->extra_fields_n_iovec;
798 }
799 }
800
801 assert(n <= m)do { if ((__builtin_expect(!!(!(n <= m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("n <= m"), "../src/journal/journald-server.c"
, 801, __PRETTY_FUNCTION__); } while (0)
;
802
803 if (pid_is_valid(object_pid) && client_context_get(s, object_pid, NULL((void*)0), NULL((void*)0), 0, NULL((void*)0), &o) >= 0) {
804
805 IOVEC_ADD_NUMERIC_FIELD(iovec, n, o->pid, pid_t, pid_is_valid, PID_FMT, "OBJECT_PID")if (pid_is_valid(o->pid)) { char *k; k = ({ do { if ((__builtin_expect
(!!(!(!size_multiply_overflow(sizeof(char), (sizeof("""OBJECT_PID"
"=""") - 1) + (2+(sizeof(pid_t) <= 1 ? 3 : sizeof(pid_t) <=
2 ? 5 : sizeof(pid_t) <= 4 ? 10 : sizeof(pid_t) <= 8 ?
20 : sizeof(int[-2*(sizeof(pid_t) > 8)]))) + 1))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"\"OBJECT_PID\" \"=\"\"\") - 1) + (2+(sizeof(pid_t) <= 1 ? 3 : sizeof(pid_t) <= 2 ? 5 : sizeof(pid_t) <= 4 ? 10 : sizeof(pid_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(pid_t) > 8)]))) + 1)"
), "../src/journal/journald-server.c", 805, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
("""OBJECT_PID" "=""") - 1) + (2+(sizeof(pid_t) <= 1 ? 3 :
sizeof(pid_t) <= 2 ? 5 : sizeof(pid_t) <= 4 ? 10 : sizeof
(pid_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(pid_t) > 8)])
)) + 1)); }); sprintf(k, "OBJECT_PID" "=" "%" "i", o->pid)
; iovec[n++] = (struct iovec) { .iov_base = ((char*) k), .iov_len
= (strlen(k)) }; }
;
806 IOVEC_ADD_NUMERIC_FIELD(iovec, n, o->uid, uid_t, uid_is_valid, UID_FMT, "OBJECT_UID")if (uid_is_valid(o->uid)) { char *k; k = ({ do { if ((__builtin_expect
(!!(!(!size_multiply_overflow(sizeof(char), (sizeof("""OBJECT_UID"
"=""") - 1) + (2+(sizeof(uid_t) <= 1 ? 3 : sizeof(uid_t) <=
2 ? 5 : sizeof(uid_t) <= 4 ? 10 : sizeof(uid_t) <= 8 ?
20 : sizeof(int[-2*(sizeof(uid_t) > 8)]))) + 1))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"\"OBJECT_UID\" \"=\"\"\") - 1) + (2+(sizeof(uid_t) <= 1 ? 3 : sizeof(uid_t) <= 2 ? 5 : sizeof(uid_t) <= 4 ? 10 : sizeof(uid_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(uid_t) > 8)]))) + 1)"
), "../src/journal/journald-server.c", 806, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
("""OBJECT_UID" "=""") - 1) + (2+(sizeof(uid_t) <= 1 ? 3 :
sizeof(uid_t) <= 2 ? 5 : sizeof(uid_t) <= 4 ? 10 : sizeof
(uid_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(uid_t) > 8)])
)) + 1)); }); sprintf(k, "OBJECT_UID" "=" "%" "u", o->uid)
; iovec[n++] = (struct iovec) { .iov_base = ((char*) k), .iov_len
= (strlen(k)) }; }
;
807 IOVEC_ADD_NUMERIC_FIELD(iovec, n, o->gid, gid_t, gid_is_valid, GID_FMT, "OBJECT_GID")if (gid_is_valid(o->gid)) { char *k; k = ({ do { if ((__builtin_expect
(!!(!(!size_multiply_overflow(sizeof(char), (sizeof("""OBJECT_GID"
"=""") - 1) + (2+(sizeof(gid_t) <= 1 ? 3 : sizeof(gid_t) <=
2 ? 5 : sizeof(gid_t) <= 4 ? 10 : sizeof(gid_t) <= 8 ?
20 : sizeof(int[-2*(sizeof(gid_t) > 8)]))) + 1))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"\"OBJECT_GID\" \"=\"\"\") - 1) + (2+(sizeof(gid_t) <= 1 ? 3 : sizeof(gid_t) <= 2 ? 5 : sizeof(gid_t) <= 4 ? 10 : sizeof(gid_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(gid_t) > 8)]))) + 1)"
), "../src/journal/journald-server.c", 807, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
("""OBJECT_GID" "=""") - 1) + (2+(sizeof(gid_t) <= 1 ? 3 :
sizeof(gid_t) <= 2 ? 5 : sizeof(gid_t) <= 4 ? 10 : sizeof
(gid_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(gid_t) > 8)])
)) + 1)); }); sprintf(k, "OBJECT_GID" "=" "%" "u", o->gid)
; iovec[n++] = (struct iovec) { .iov_base = ((char*) k), .iov_len
= (strlen(k)) }; }
;
808
809 /* See above for size limits, only ->cmdline may be large, so use a heap allocation for it. */
810 IOVEC_ADD_STRING_FIELD(iovec, n, o->comm, "OBJECT_COMM")if (!isempty(o->comm)) { char *k; k = ({ const char *_appendees_
[] = { "OBJECT_COMM" "=", o->comm }; char *_d_, *_p_; size_t
_len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (
__builtin_choose_expr( !__builtin_types_compatible_p(typeof(_appendees_
), typeof(&*(_appendees_))), sizeof(_appendees_)/sizeof((
_appendees_)[0]), ((void)0))) && _appendees_[_i_]; _i_
++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca
(_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); iovec[n++] = (struct
iovec) { .iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
;
811 IOVEC_ADD_STRING_FIELD(iovec, n, o->exe, "OBJECT_EXE")if (!isempty(o->exe)) { char *k; k = ({ const char *_appendees_
[] = { "OBJECT_EXE" "=", o->exe }; char *_d_, *_p_; size_t
_len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__ (
__builtin_choose_expr( !__builtin_types_compatible_p(typeof(_appendees_
), typeof(&*(_appendees_))), sizeof(_appendees_)/sizeof((
_appendees_)[0]), ((void)0))) && _appendees_[_i_]; _i_
++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca
(_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); iovec[n++] = (struct
iovec) { .iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
;
812 if (o->cmdline)
813 cmdline2 = set_iovec_string_field(iovec, &n, "OBJECT_CMDLINE=", o->cmdline);
814
815 IOVEC_ADD_STRING_FIELD(iovec, n, o->capeff, "OBJECT_CAP_EFFECTIVE")if (!isempty(o->capeff)) { char *k; k = ({ const char *_appendees_
[] = { "OBJECT_CAP_EFFECTIVE" "=", o->capeff }; char *_d_,
*_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__
(__builtin_choose_expr( !__builtin_types_compatible_p(typeof
(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_
)/sizeof((_appendees_)[0]), ((void)0))) && _appendees_
[_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca
(_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); iovec[n++] = (struct
iovec) { .iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
;
816 IOVEC_ADD_SIZED_FIELD(iovec, n, o->label, o->label_size, "OBJECT_SELINUX_CONTEXT")if (o->label_size > 0) { char *k; k = ({ do { if ((__builtin_expect
(!!(!(!size_multiply_overflow(sizeof(char), (sizeof("""OBJECT_SELINUX_CONTEXT"
"=""") - 1) + o->label_size + 1))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"\"OBJECT_SELINUX_CONTEXT\" \"=\"\"\") - 1) + o->label_size + 1)"
), "../src/journal/journald-server.c", 816, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
("""OBJECT_SELINUX_CONTEXT" "=""") - 1) + o->label_size + 1
)); }); *((char*) mempcpy(stpcpy(k, "OBJECT_SELINUX_CONTEXT" "="
), o->label, o->label_size)) = 0; iovec[n++] = (struct iovec
) { .iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
;
817 IOVEC_ADD_NUMERIC_FIELD(iovec, n, o->auditid, uint32_t, audit_session_is_valid, "%" PRIu32, "OBJECT_AUDIT_SESSION")if (audit_session_is_valid(o->auditid)) { char *k; k = ({ do
{ if ((__builtin_expect(!!(!(!size_multiply_overflow(sizeof(
char), (sizeof("""OBJECT_AUDIT_SESSION" "=""") - 1) + (2+(sizeof
(uint32_t) <= 1 ? 3 : sizeof(uint32_t) <= 2 ? 5 : sizeof
(uint32_t) <= 4 ? 10 : sizeof(uint32_t) <= 8 ? 20 : sizeof
(int[-2*(sizeof(uint32_t) > 8)]))) + 1))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"\"OBJECT_AUDIT_SESSION\" \"=\"\"\") - 1) + (2+(sizeof(uint32_t) <= 1 ? 3 : sizeof(uint32_t) <= 2 ? 5 : sizeof(uint32_t) <= 4 ? 10 : sizeof(uint32_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(uint32_t) > 8)]))) + 1)"
), "../src/journal/journald-server.c", 817, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
("""OBJECT_AUDIT_SESSION" "=""") - 1) + (2+(sizeof(uint32_t) <=
1 ? 3 : sizeof(uint32_t) <= 2 ? 5 : sizeof(uint32_t) <=
4 ? 10 : sizeof(uint32_t) <= 8 ? 20 : sizeof(int[-2*(sizeof
(uint32_t) > 8)]))) + 1)); }); sprintf(k, "OBJECT_AUDIT_SESSION"
"=" "%" "u", o->auditid); iovec[n++] = (struct iovec) { .
iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
;
818 IOVEC_ADD_NUMERIC_FIELD(iovec, n, o->loginuid, uid_t, uid_is_valid, UID_FMT, "OBJECT_AUDIT_LOGINUID")if (uid_is_valid(o->loginuid)) { char *k; k = ({ do { if (
(__builtin_expect(!!(!(!size_multiply_overflow(sizeof(char), (
sizeof("""OBJECT_AUDIT_LOGINUID" "=""") - 1) + (2+(sizeof(uid_t
) <= 1 ? 3 : sizeof(uid_t) <= 2 ? 5 : sizeof(uid_t) <=
4 ? 10 : sizeof(uid_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(
uid_t) > 8)]))) + 1))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"\"OBJECT_AUDIT_LOGINUID\" \"=\"\"\") - 1) + (2+(sizeof(uid_t) <= 1 ? 3 : sizeof(uid_t) <= 2 ? 5 : sizeof(uid_t) <= 4 ? 10 : sizeof(uid_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(uid_t) > 8)]))) + 1)"
), "../src/journal/journald-server.c", 818, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
("""OBJECT_AUDIT_LOGINUID" "=""") - 1) + (2+(sizeof(uid_t) <=
1 ? 3 : sizeof(uid_t) <= 2 ? 5 : sizeof(uid_t) <= 4 ? 10
: sizeof(uid_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(uid_t) >
8)]))) + 1)); }); sprintf(k, "OBJECT_AUDIT_LOGINUID" "=" "%"
"u", o->loginuid); iovec[n++] = (struct iovec) { .iov_base
= ((char*) k), .iov_len = (strlen(k)) }; }
;
819
820 IOVEC_ADD_STRING_FIELD(iovec, n, o->cgroup, "OBJECT_SYSTEMD_CGROUP")if (!isempty(o->cgroup)) { char *k; k = ({ const char *_appendees_
[] = { "OBJECT_SYSTEMD_CGROUP" "=", o->cgroup }; char *_d_
, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__
(__builtin_choose_expr( !__builtin_types_compatible_p(typeof
(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_
)/sizeof((_appendees_)[0]), ((void)0))) && _appendees_
[_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca
(_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); iovec[n++] = (struct
iovec) { .iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
;
821 IOVEC_ADD_STRING_FIELD(iovec, n, o->session, "OBJECT_SYSTEMD_SESSION")if (!isempty(o->session)) { char *k; k = ({ const char *_appendees_
[] = { "OBJECT_SYSTEMD_SESSION" "=", o->session }; char *_d_
, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__
(__builtin_choose_expr( !__builtin_types_compatible_p(typeof
(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_
)/sizeof((_appendees_)[0]), ((void)0))) && _appendees_
[_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca
(_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); iovec[n++] = (struct
iovec) { .iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
;
822 IOVEC_ADD_NUMERIC_FIELD(iovec, n, o->owner_uid, uid_t, uid_is_valid, UID_FMT, "OBJECT_SYSTEMD_OWNER_UID")if (uid_is_valid(o->owner_uid)) { char *k; k = ({ do { if (
(__builtin_expect(!!(!(!size_multiply_overflow(sizeof(char), (
sizeof("""OBJECT_SYSTEMD_OWNER_UID" "=""") - 1) + (2+(sizeof(
uid_t) <= 1 ? 3 : sizeof(uid_t) <= 2 ? 5 : sizeof(uid_t
) <= 4 ? 10 : sizeof(uid_t) <= 8 ? 20 : sizeof(int[-2*(
sizeof(uid_t) > 8)]))) + 1))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"\"OBJECT_SYSTEMD_OWNER_UID\" \"=\"\"\") - 1) + (2+(sizeof(uid_t) <= 1 ? 3 : sizeof(uid_t) <= 2 ? 5 : sizeof(uid_t) <= 4 ? 10 : sizeof(uid_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(uid_t) > 8)]))) + 1)"
), "../src/journal/journald-server.c", 822, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
("""OBJECT_SYSTEMD_OWNER_UID" "=""") - 1) + (2+(sizeof(uid_t)
<= 1 ? 3 : sizeof(uid_t) <= 2 ? 5 : sizeof(uid_t) <=
4 ? 10 : sizeof(uid_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(
uid_t) > 8)]))) + 1)); }); sprintf(k, "OBJECT_SYSTEMD_OWNER_UID"
"=" "%" "u", o->owner_uid); iovec[n++] = (struct iovec) {
.iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
;
823 IOVEC_ADD_STRING_FIELD(iovec, n, o->unit, "OBJECT_SYSTEMD_UNIT")if (!isempty(o->unit)) { char *k; k = ({ const char *_appendees_
[] = { "OBJECT_SYSTEMD_UNIT" "=", o->unit }; char *_d_, *_p_
; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__
(__builtin_choose_expr( !__builtin_types_compatible_p(typeof
(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_
)/sizeof((_appendees_)[0]), ((void)0))) && _appendees_
[_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca
(_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); iovec[n++] = (struct
iovec) { .iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
;
824 IOVEC_ADD_STRING_FIELD(iovec, n, o->user_unit, "OBJECT_SYSTEMD_USER_UNIT")if (!isempty(o->user_unit)) { char *k; k = ({ const char *
_appendees_[] = { "OBJECT_SYSTEMD_USER_UNIT" "=", o->user_unit
}; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ =
0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_
)/sizeof((_appendees_)[0]), ((void)0))) && _appendees_
[_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca
(_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); iovec[n++] = (struct
iovec) { .iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
;
825 IOVEC_ADD_STRING_FIELD(iovec, n, o->slice, "OBJECT_SYSTEMD_SLICE")if (!isempty(o->slice)) { char *k; k = ({ const char *_appendees_
[] = { "OBJECT_SYSTEMD_SLICE" "=", o->slice }; char *_d_, *
_p_; size_t _len_ = 0; size_t _i_; for (_i_ = 0; _i_ < __extension__
(__builtin_choose_expr( !__builtin_types_compatible_p(typeof
(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_
)/sizeof((_appendees_)[0]), ((void)0))) && _appendees_
[_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca
(_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); iovec[n++] = (struct
iovec) { .iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
;
826 IOVEC_ADD_STRING_FIELD(iovec, n, o->user_slice, "OBJECT_SYSTEMD_USER_SLICE")if (!isempty(o->user_slice)) { char *k; k = ({ const char *
_appendees_[] = { "OBJECT_SYSTEMD_USER_SLICE" "=", o->user_slice
}; char *_d_, *_p_; size_t _len_ = 0; size_t _i_; for (_i_ =
0; _i_ < __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(_appendees_), typeof(&*(_appendees_))), sizeof(_appendees_
)/sizeof((_appendees_)[0]), ((void)0))) && _appendees_
[_i_]; _i_++) _len_ += strlen(_appendees_[_i_]); _p_ = _d_ = __builtin_alloca
(_len_ + 1); for (_i_ = 0; _i_ < __extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(_appendees_), typeof(&
*(_appendees_))), sizeof(_appendees_)/sizeof((_appendees_)[0]
), ((void)0))) && _appendees_[_i_]; _i_++) _p_ = stpcpy
(_p_, _appendees_[_i_]); *_p_ = 0; _d_; }); iovec[n++] = (struct
iovec) { .iov_base = ((char*) k), .iov_len = (strlen(k)) }; }
;
827
828 IOVEC_ADD_ID128_FIELD(iovec, n, o->invocation_id, "OBJECT_SYSTEMD_INVOCATION_ID=")if (!sd_id128_is_null(o->invocation_id)) { char *k; k = ({
do { if ((__builtin_expect(!!(!(!size_multiply_overflow(sizeof
(char), (sizeof("""OBJECT_SYSTEMD_INVOCATION_ID=" "=""") - 1)
+ 33))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!size_multiply_overflow(sizeof(char), (sizeof(\"\"\"OBJECT_SYSTEMD_INVOCATION_ID=\" \"=\"\"\") - 1) + 33)"
), "../src/journal/journald-server.c", 828, __PRETTY_FUNCTION__
); } while (0); (char*) __builtin_alloca (sizeof(char)*((sizeof
("""OBJECT_SYSTEMD_INVOCATION_ID=" "=""") - 1) + 33)); }); sd_id128_to_string
(o->invocation_id, stpcpy(k, "OBJECT_SYSTEMD_INVOCATION_ID="
"=")); iovec[n++] = (struct iovec) { .iov_base = ((char*) k)
, .iov_len = (strlen(k)) }; }
;
829 }
830
831 assert(n <= m)do { if ((__builtin_expect(!!(!(n <= m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("n <= m"), "../src/journal/journald-server.c"
, 831, __PRETTY_FUNCTION__); } while (0)
;
832
833 if (tv) {
834 sprintf(source_time, "_SOURCE_REALTIME_TIMESTAMP=" USEC_FMT"%" "l" "u", timeval_load(tv));
835 iovec[n++] = IOVEC_MAKE_STRING(source_time)(struct iovec) { .iov_base = ((char*) source_time), .iov_len =
(strlen(source_time)) }
;
836 }
837
838 /* Note that strictly speaking storing the boot id here is
839 * redundant since the entry includes this in-line
840 * anyway. However, we need this indexed, too. */
841 if (!isempty(s->boot_id_field))
842 iovec[n++] = IOVEC_MAKE_STRING(s->boot_id_field)(struct iovec) { .iov_base = ((char*) s->boot_id_field), .
iov_len = (strlen(s->boot_id_field)) }
;
843
844 if (!isempty(s->machine_id_field))
845 iovec[n++] = IOVEC_MAKE_STRING(s->machine_id_field)(struct iovec) { .iov_base = ((char*) s->machine_id_field)
, .iov_len = (strlen(s->machine_id_field)) }
;
846
847 if (!isempty(s->hostname_field))
848 iovec[n++] = IOVEC_MAKE_STRING(s->hostname_field)(struct iovec) { .iov_base = ((char*) s->hostname_field), .
iov_len = (strlen(s->hostname_field)) }
;
849
850 assert(n <= m)do { if ((__builtin_expect(!!(!(n <= m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("n <= m"), "../src/journal/journald-server.c"
, 850, __PRETTY_FUNCTION__); } while (0)
;
851
852 if (s->split_mode == SPLIT_UID && c && uid_is_valid(c->uid))
853 /* Split up strictly by (non-root) UID */
854 journal_uid = c->uid;
855 else if (s->split_mode == SPLIT_LOGIN && c && c->uid > 0 && uid_is_valid(c->owner_uid))
856 /* Split up by login UIDs. We do this only if the
857 * realuid is not root, in order not to accidentally
858 * leak privileged information to the user that is
859 * logged by a privileged process that is part of an
860 * unprivileged session. */
861 journal_uid = c->owner_uid;
862 else
863 journal_uid = 0;
864
865 write_to_journal(s, journal_uid, iovec, n, priority);
866}
867
868void server_driver_message(Server *s, pid_t object_pid, const char *message_id, const char *format, ...) {
869
870 struct iovec *iovec;
871 size_t n = 0, k, m;
872 va_list ap;
873 int r;
874
875 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 875, __PRETTY_FUNCTION__); } while (0)
;
876 assert(format)do { if ((__builtin_expect(!!(!(format)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("format"), "../src/journal/journald-server.c"
, 876, __PRETTY_FUNCTION__); } while (0)
;
877
878 m = N_IOVEC_META_FIELDS22 + 5 + N_IOVEC_PAYLOAD_FIELDS16 + client_context_extra_fields_n_iovec(s->my_context) + N_IOVEC_OBJECT_FIELDS18;
879 iovec = newa(struct iovec, m)({ do { if ((__builtin_expect(!!(!(!size_multiply_overflow(sizeof
(struct iovec), m))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("!size_multiply_overflow(sizeof(struct iovec), m)"), "../src/journal/journald-server.c"
, 879, __PRETTY_FUNCTION__); } while (0); (struct iovec*) __builtin_alloca
(sizeof(struct iovec)*(m)); })
;
880
881 assert_cc(3 == LOG_FAC(LOG_DAEMON))GCC diagnostic push ; GCC diagnostic ignored "-Wdeclaration-after-statement"
; struct _assert_struct_53 { char x[(3 == ((((3<<3)) &
0x03f8) >> 3)) ? 0 : -1]; }; GCC diagnostic pop
;
882 iovec[n++] = IOVEC_MAKE_STRING("SYSLOG_FACILITY=3")(struct iovec) { .iov_base = ((char*) "SYSLOG_FACILITY=3"), .
iov_len = (strlen("SYSLOG_FACILITY=3")) }
;
883 iovec[n++] = IOVEC_MAKE_STRING("SYSLOG_IDENTIFIER=systemd-journald")(struct iovec) { .iov_base = ((char*) "SYSLOG_IDENTIFIER=systemd-journald"
), .iov_len = (strlen("SYSLOG_IDENTIFIER=systemd-journald")) }
;
884
885 iovec[n++] = IOVEC_MAKE_STRING("_TRANSPORT=driver")(struct iovec) { .iov_base = ((char*) "_TRANSPORT=driver"), .
iov_len = (strlen("_TRANSPORT=driver")) }
;
886 assert_cc(6 == LOG_INFO)GCC diagnostic push ; GCC diagnostic ignored "-Wdeclaration-after-statement"
; struct _assert_struct_54 { char x[(6 == 6) ? 0 : -1]; }; GCC
diagnostic pop
;
887 iovec[n++] = IOVEC_MAKE_STRING("PRIORITY=6")(struct iovec) { .iov_base = ((char*) "PRIORITY=6"), .iov_len
= (strlen("PRIORITY=6")) }
;
888
889 if (message_id)
890 iovec[n++] = IOVEC_MAKE_STRING(message_id)(struct iovec) { .iov_base = ((char*) message_id), .iov_len =
(strlen(message_id)) }
;
891 k = n;
892
893 va_start(ap, format)__builtin_va_start(ap, format);
894 r = log_format_iovec(iovec, m, &n, false0, 0, format, ap);
895 /* Error handling below */
896 va_end(ap)__builtin_va_end(ap);
897
898 if (r >= 0)
899 dispatch_message_real(s, iovec, n, m, s->my_context, NULL((void*)0), LOG_INFO6, object_pid);
900
901 while (k < n)
902 free(iovec[k++].iov_base);
903
904 if (r < 0) {
905 /* We failed to format the message. Emit a warning instead. */
906 char buf[LINE_MAX2048];
907
908 xsprintf(buf, "MESSAGE=Entry printing failed: %s", strerror(-r))do { if ((__builtin_expect(!!(!(((size_t) snprintf(buf, __extension__
(__builtin_choose_expr( !__builtin_types_compatible_p(typeof
(buf), typeof(&*(buf))), sizeof(buf)/sizeof((buf)[0]), ((
void)0))), "MESSAGE=Entry printing failed: %s", strerror(-r))
< (__extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(buf), typeof(&*(buf))), sizeof(buf)/sizeof((buf)[
0]), ((void)0))))))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("xsprintf: " "buf" "[] must be big enough"), "../src/journal/journald-server.c"
, 908, __PRETTY_FUNCTION__); } while (0)
;
909
910 n = 3;
911 iovec[n++] = IOVEC_MAKE_STRING("PRIORITY=4")(struct iovec) { .iov_base = ((char*) "PRIORITY=4"), .iov_len
= (strlen("PRIORITY=4")) }
;
912 iovec[n++] = IOVEC_MAKE_STRING(buf)(struct iovec) { .iov_base = ((char*) buf), .iov_len = (strlen
(buf)) }
;
913 dispatch_message_real(s, iovec, n, m, s->my_context, NULL((void*)0), LOG_INFO6, object_pid);
914 }
915}
916
917void server_dispatch_message(
918 Server *s,
919 struct iovec *iovec, size_t n, size_t m,
920 ClientContext *c,
921 const struct timeval *tv,
922 int priority,
923 pid_t object_pid) {
924
925 uint64_t available = 0;
926 int rl;
927
928 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 928, __PRETTY_FUNCTION__); } while (0)
;
929 assert(iovec || n == 0)do { if ((__builtin_expect(!!(!(iovec || n == 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("iovec || n == 0"), "../src/journal/journald-server.c"
, 929, __PRETTY_FUNCTION__); } while (0)
;
930
931 if (n == 0)
932 return;
933
934 if (LOG_PRI(priority)((priority) & 0x07) > s->max_level_store)
935 return;
936
937 /* Stop early in case the information will not be stored
938 * in a journal. */
939 if (s->storage == STORAGE_NONE)
940 return;
941
942 if (c && c->unit) {
943 (void) determine_space(s, &available, NULL((void*)0));
944
945 rl = journal_rate_limit_test(s->rate_limit, c->unit, c->log_rate_limit_interval, c->log_rate_limit_burst, priority & LOG_PRIMASK0x07, available);
946 if (rl == 0)
947 return;
948
949 /* Write a suppression message if we suppressed something */
950 if (rl > 1)
951 server_driver_message(s, c->pid,
952 "MESSAGE_ID=" SD_MESSAGE_JOURNAL_DROPPED_STR"a5" "96" "d6" "fe" "7b" "fa" "49" "94" "82" "8e" "72" "30" "9e"
"95" "d6" "1e"
,
953 LOG_MESSAGE("Suppressed %i messages from %s", rl - 1, c->unit)"MESSAGE=" "Suppressed %i messages from %s", rl - 1, c->unit,
954 "N_DROPPED=%i", rl - 1,
955 NULL((void*)0));
956 }
957
958 dispatch_message_real(s, iovec, n, m, c, tv, priority, object_pid);
959}
960
961int server_flush_to_var(Server *s, bool_Bool require_flag_file) {
962 sd_id128_t machine;
963 sd_journal *j = NULL((void*)0);
964 char ts[FORMAT_TIMESPAN_MAX64];
965 usec_t start;
966 unsigned n = 0;
967 int r;
968
969 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 969, __PRETTY_FUNCTION__); } while (0)
;
970
971 if (!IN_SET(s->storage, STORAGE_AUTO, STORAGE_PERSISTENT)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){STORAGE_AUTO, STORAGE_PERSISTENT})/sizeof
(int)]; switch(s->storage) { case STORAGE_AUTO: case STORAGE_PERSISTENT
: _found = 1; break; default: break; } _found; })
)
972 return 0;
973
974 if (!s->runtime_journal)
975 return 0;
976
977 if (require_flag_file && !flushed_flag_is_set())
978 return 0;
979
980 (void) system_journal_open(s, true1);
981
982 if (!s->system_journal)
983 return 0;
984
985 log_debug("Flushing to /var...")({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 985, __func__, "Flushing to /var..."
) : -abs(_e); })
;
986
987 start = now(CLOCK_MONOTONIC1);
988
989 r = sd_id128_get_machine(&machine);
990 if (r < 0)
991 return r;
992
993 r = sd_journal_open(&j, SD_JOURNAL_RUNTIME_ONLY);
994 if (r < 0)
995 return log_error_errno(r, "Failed to read runtime journal: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 995, __func__, "Failed to read runtime journal: %m"
) : -abs(_e); })
;
996
997 sd_journal_set_data_threshold(j, 0);
998
999 SD_JOURNAL_FOREACH(j)if (sd_journal_seek_head(j) < 0) { } else while (sd_journal_next
(j) > 0)
{
1000 Object *o = NULL((void*)0);
1001 JournalFile *f;
1002
1003 f = j->current_file;
1004 assert(f && f->current_offset > 0)do { if ((__builtin_expect(!!(!(f && f->current_offset
> 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("f && f->current_offset > 0"
), "../src/journal/journald-server.c", 1004, __PRETTY_FUNCTION__
); } while (0)
;
1005
1006 n++;
1007
1008 r = journal_file_move_to_object(f, OBJECT_ENTRY, f->current_offset, &o);
1009 if (r < 0) {
1010 log_error_errno(r, "Can't read entry: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1010, __func__, "Can't read entry: %m"
) : -abs(_e); })
;
1011 goto finish;
1012 }
1013
1014 r = journal_file_copy_entry(f, s->system_journal, o, f->current_offset);
1015 if (r >= 0)
1016 continue;
1017
1018 if (!shall_try_append_again(s->system_journal, r)) {
1019 log_error_errno(r, "Can't write entry: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1019, __func__, "Can't write entry: %m"
) : -abs(_e); })
;
1020 goto finish;
1021 }
1022
1023 server_rotate(s);
1024 server_vacuum(s, false0);
1025
1026 if (!s->system_journal) {
1027 log_notice("Didn't flush runtime journal since rotation of system journal wasn't successful.")({ int _level = (((5))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1027, __func__, "Didn't flush runtime journal since rotation of system journal wasn't successful."
) : -abs(_e); })
;
1028 r = -EIO5;
1029 goto finish;
1030 }
1031
1032 log_debug("Retrying write.")({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1032, __func__, "Retrying write."
) : -abs(_e); })
;
1033 r = journal_file_copy_entry(f, s->system_journal, o, f->current_offset);
1034 if (r < 0) {
1035 log_error_errno(r, "Can't write entry: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1035, __func__, "Can't write entry: %m"
) : -abs(_e); })
;
1036 goto finish;
1037 }
1038 }
1039
1040 r = 0;
1041
1042finish:
1043 if (s->system_journal)
1044 journal_file_post_change(s->system_journal);
1045
1046 s->runtime_journal = journal_file_close(s->runtime_journal);
1047
1048 if (r >= 0)
1049 (void) rm_rf("/run/log/journal", REMOVE_ROOT);
1050
1051 sd_journal_close(j);
1052
1053 server_driver_message(s, 0, NULL((void*)0),
1054 LOG_MESSAGE("Time spent on flushing to /var is %s for %u entries.","MESSAGE=" "Time spent on flushing to /var is %s for %u entries."
, format_timespan(ts, sizeof(ts), now(1) - start, 0), n
1055 format_timespan(ts, sizeof(ts), now(CLOCK_MONOTONIC) - start, 0),"MESSAGE=" "Time spent on flushing to /var is %s for %u entries."
, format_timespan(ts, sizeof(ts), now(1) - start, 0), n
1056 n)"MESSAGE=" "Time spent on flushing to /var is %s for %u entries."
, format_timespan(ts, sizeof(ts), now(1) - start, 0), n
,
1057 NULL((void*)0));
1058
1059 return r;
1060}
1061
1062int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userdata) {
1063 Server *s = userdata;
1064 struct ucred *ucred = NULL((void*)0);
1065 struct timeval *tv = NULL((void*)0);
1066 struct cmsghdr *cmsg;
1067 char *label = NULL((void*)0);
1068 size_t label_len = 0, m;
1069 struct iovec iovec;
1070 ssize_t n;
1071 int *fds = NULL((void*)0), v = 0;
1072 size_t n_fds = 0;
1073
1074 union {
1075 struct cmsghdr cmsghdr;
1076
1077 /* We use NAME_MAX space for the SELinux label
1078 * here. The kernel currently enforces no
1079 * limit, but according to suggestions from
1080 * the SELinux people this will change and it
1081 * will probably be identical to NAME_MAX. For
1082 * now we use that, but this should be updated
1083 * one day when the final limit is known. */
1084 uint8_t buf[CMSG_SPACE(sizeof(struct ucred))((((sizeof(struct ucred)) + sizeof (size_t) - 1) & (size_t
) ~(sizeof (size_t) - 1)) + (((sizeof (struct cmsghdr)) + sizeof
(size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)))
+
1085 CMSG_SPACE(sizeof(struct timeval))((((sizeof(struct timeval)) + sizeof (size_t) - 1) & (size_t
) ~(sizeof (size_t) - 1)) + (((sizeof (struct cmsghdr)) + sizeof
(size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)))
+
1086 CMSG_SPACE(sizeof(int))((((sizeof(int)) + sizeof (size_t) - 1) & (size_t) ~(sizeof
(size_t) - 1)) + (((sizeof (struct cmsghdr)) + sizeof (size_t
) - 1) & (size_t) ~(sizeof (size_t) - 1)))
+ /* fd */
1087 CMSG_SPACE(NAME_MAX)((((255) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t
) - 1)) + (((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) &
(size_t) ~(sizeof (size_t) - 1)))
]; /* selinux label */
1088 } control = {};
1089
1090 union sockaddr_union sa = {};
1091
1092 struct msghdr msghdr = {
1093 .msg_iov = &iovec,
1094 .msg_iovlen = 1,
1095 .msg_control = &control,
1096 .msg_controllen = sizeof(control),
1097 .msg_name = &sa,
1098 .msg_namelen = sizeof(sa),
1099 };
1100
1101 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 1101, __PRETTY_FUNCTION__); } while (0)
;
1102 assert(fd == s->native_fd || fd == s->syslog_fd || fd == s->audit_fd)do { if ((__builtin_expect(!!(!(fd == s->native_fd || fd ==
s->syslog_fd || fd == s->audit_fd)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("fd == s->native_fd || fd == s->syslog_fd || fd == s->audit_fd"
), "../src/journal/journald-server.c", 1102, __PRETTY_FUNCTION__
); } while (0)
;
1103
1104 if (revents != EPOLLINEPOLLIN) {
1105 log_error("Got invalid event from epoll for datagram fd: %"PRIx32, revents)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1105, __func__, "Got invalid event from epoll for datagram fd: %"
"x", revents) : -abs(_e); })
;
1106 return -EIO5;
1107 }
1108
1109 /* Try to get the right size, if we can. (Not all sockets support SIOCINQ, hence we just try, but don't rely on
1110 * it.) */
1111 (void) ioctl(fd, SIOCINQ0x541B, &v);
1112
1113 /* Fix it up, if it is too small. We use the same fixed value as auditd here. Awful! */
1114 m = PAGE_ALIGN(MAX3((size_t) v + 1,ALIGN_TO((__extension__ ({ const typeof((size_t) v + 1) _c = __extension__
({ const typeof(((size_t) v + 1)) __unique_prefix_A55 = (((size_t
) v + 1)); const typeof(((size_t) 2048)) __unique_prefix_B56 =
(((size_t) 2048)); __unique_prefix_A55 > __unique_prefix_B56
? __unique_prefix_A55 : __unique_prefix_B56; }); __extension__
({ const typeof((_c)) __unique_prefix_A57 = ((_c)); const typeof
(((((sizeof(struct nlmsghdr)) + 7) & ~7) + ((((size_t) 8970
) + 7) & ~7))) __unique_prefix_B58 = (((((sizeof(struct nlmsghdr
)) + 7) & ~7) + ((((size_t) 8970) + 7) & ~7))); __unique_prefix_A57
> __unique_prefix_B58 ? __unique_prefix_A57 : __unique_prefix_B58
; }); }) + 1), page_size())
1115 (size_t) LINE_MAX,ALIGN_TO((__extension__ ({ const typeof((size_t) v + 1) _c = __extension__
({ const typeof(((size_t) v + 1)) __unique_prefix_A55 = (((size_t
) v + 1)); const typeof(((size_t) 2048)) __unique_prefix_B56 =
(((size_t) 2048)); __unique_prefix_A55 > __unique_prefix_B56
? __unique_prefix_A55 : __unique_prefix_B56; }); __extension__
({ const typeof((_c)) __unique_prefix_A57 = ((_c)); const typeof
(((((sizeof(struct nlmsghdr)) + 7) & ~7) + ((((size_t) 8970
) + 7) & ~7))) __unique_prefix_B58 = (((((sizeof(struct nlmsghdr
)) + 7) & ~7) + ((((size_t) 8970) + 7) & ~7))); __unique_prefix_A57
> __unique_prefix_B58 ? __unique_prefix_A57 : __unique_prefix_B58
; }); }) + 1), page_size())
1116 ALIGN(sizeof(struct nlmsghdr)) + ALIGN((size_t) MAX_AUDIT_MESSAGE_LENGTH)) + 1)ALIGN_TO((__extension__ ({ const typeof((size_t) v + 1) _c = __extension__
({ const typeof(((size_t) v + 1)) __unique_prefix_A55 = (((size_t
) v + 1)); const typeof(((size_t) 2048)) __unique_prefix_B56 =
(((size_t) 2048)); __unique_prefix_A55 > __unique_prefix_B56
? __unique_prefix_A55 : __unique_prefix_B56; }); __extension__
({ const typeof((_c)) __unique_prefix_A57 = ((_c)); const typeof
(((((sizeof(struct nlmsghdr)) + 7) & ~7) + ((((size_t) 8970
) + 7) & ~7))) __unique_prefix_B58 = (((((sizeof(struct nlmsghdr
)) + 7) & ~7) + ((((size_t) 8970) + 7) & ~7))); __unique_prefix_A57
> __unique_prefix_B58 ? __unique_prefix_A57 : __unique_prefix_B58
; }); }) + 1), page_size())
;
1117
1118 if (!GREEDY_REALLOC(s->buffer, s->buffer_size, m)greedy_realloc((void**) &(s->buffer), &(s->buffer_size
), (m), sizeof((s->buffer)[0]))
)
1119 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/journal/journald-server.c"
, 1119, __func__)
;
1120
1121 iovec.iov_base = s->buffer;
1122 iovec.iov_len = s->buffer_size - 1; /* Leave room for trailing NUL we add later */
1123
1124 n = recvmsg(fd, &msghdr, MSG_DONTWAITMSG_DONTWAIT|MSG_CMSG_CLOEXECMSG_CMSG_CLOEXEC);
1125 if (n < 0) {
1126 if (IN_SET(errno, EINTR, EAGAIN)({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){4, 11})/sizeof(int)]; switch((*__errno_location
())) { case 4: case 11: _found = 1; break; default: break; }
_found; })
)
1127 return 0;
1128
1129 return log_error_errno(errno, "recvmsg() failed: %m")({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/journal/journald-server.c", 1129
, __func__, "recvmsg() failed: %m") : -abs(_e); })
;
1130 }
1131
1132 CMSG_FOREACH(cmsg, &msghdr)for ((cmsg) = ((size_t) (&msghdr)->msg_controllen >=
sizeof (struct cmsghdr) ? (struct cmsghdr *) (&msghdr)->
msg_control : (struct cmsghdr *) 0); (cmsg); (cmsg) = __cmsg_nxthdr
((&msghdr), (cmsg)))
1133 if (cmsg->cmsg_level == SOL_SOCKET1 &&
1134 cmsg->cmsg_type == SCM_CREDENTIALSSCM_CREDENTIALS &&
1135 cmsg->cmsg_len == CMSG_LEN(sizeof(struct ucred))((((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t
) ~(sizeof (size_t) - 1)) + (sizeof(struct ucred)))
)
1136 ucred = (struct ucred*) CMSG_DATA(cmsg)((cmsg)->__cmsg_data);
1137 else if (cmsg->cmsg_level == SOL_SOCKET1 &&
1138 cmsg->cmsg_type == SCM_SECURITY0x03) {
1139 label = (char*) CMSG_DATA(cmsg)((cmsg)->__cmsg_data);
1140 label_len = cmsg->cmsg_len - CMSG_LEN(0)((((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t
) ~(sizeof (size_t) - 1)) + (0))
;
1141 } else if (cmsg->cmsg_level == SOL_SOCKET1 &&
1142 cmsg->cmsg_type == SO_TIMESTAMP29 &&
1143 cmsg->cmsg_len == CMSG_LEN(sizeof(struct timeval))((((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t
) ~(sizeof (size_t) - 1)) + (sizeof(struct timeval)))
)
1144 tv = (struct timeval*) CMSG_DATA(cmsg)((cmsg)->__cmsg_data);
1145 else if (cmsg->cmsg_level == SOL_SOCKET1 &&
1146 cmsg->cmsg_type == SCM_RIGHTSSCM_RIGHTS) {
1147 fds = (int*) CMSG_DATA(cmsg)((cmsg)->__cmsg_data);
1148 n_fds = (cmsg->cmsg_len - CMSG_LEN(0)((((sizeof (struct cmsghdr)) + sizeof (size_t) - 1) & (size_t
) ~(sizeof (size_t) - 1)) + (0))
) / sizeof(int);
1149 }
1150
1151 /* And a trailing NUL, just in case */
1152 s->buffer[n] = 0;
1153
1154 if (fd == s->syslog_fd) {
1155 if (n > 0 && n_fds == 0)
1156 server_process_syslog_message(s, s->buffer, n, ucred, tv, label, label_len);
1157 else if (n_fds > 0)
1158 log_warning("Got file descriptors via syslog socket. Ignoring.")({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1158, __func__, "Got file descriptors via syslog socket. Ignoring."
) : -abs(_e); })
;
1159
1160 } else if (fd == s->native_fd) {
1161 if (n > 0 && n_fds == 0)
1162 server_process_native_message(s, s->buffer, n, ucred, tv, label, label_len);
1163 else if (n == 0 && n_fds == 1)
1164 server_process_native_file(s, fds[0], ucred, tv, label, label_len);
1165 else if (n_fds > 0)
1166 log_warning("Got too many file descriptors via native socket. Ignoring.")({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1166, __func__, "Got too many file descriptors via native socket. Ignoring."
) : -abs(_e); })
;
1167
1168 } else {
1169 assert(fd == s->audit_fd)do { if ((__builtin_expect(!!(!(fd == s->audit_fd)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("fd == s->audit_fd"), "../src/journal/journald-server.c"
, 1169, __PRETTY_FUNCTION__); } while (0)
;
1170
1171 if (n > 0 && n_fds == 0)
1172 server_process_audit_message(s, s->buffer, n, ucred, &sa, msghdr.msg_namelen);
1173 else if (n_fds > 0)
1174 log_warning("Got file descriptors via audit socket. Ignoring.")({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1174, __func__, "Got file descriptors via audit socket. Ignoring."
) : -abs(_e); })
;
1175 }
1176
1177 close_many(fds, n_fds);
1178 return 0;
1179}
1180
1181static int dispatch_sigusr1(sd_event_source *es, const struct signalfd_siginfo *si, void *userdata) {
1182 Server *s = userdata;
1183 int r;
1184
1185 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 1185, __PRETTY_FUNCTION__); } while (0)
;
1186
1187 log_info("Received request to flush runtime journal from PID " PID_FMT, si->ssi_pid)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1187, __func__, "Received request to flush runtime journal from PID "
"%" "i", si->ssi_pid) : -abs(_e); })
;
1188
1189 (void) server_flush_to_var(s, false0);
1190 server_sync(s);
1191 server_vacuum(s, false0);
1192
1193 r = touch("/run/systemd/journal/flushed");
1194 if (r < 0)
1195 log_warning_errno(r, "Failed to touch /run/systemd/journal/flushed, ignoring: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1195, __func__, "Failed to touch /run/systemd/journal/flushed, ignoring: %m"
) : -abs(_e); })
;
1196
1197 server_space_usage_message(s, NULL((void*)0));
1198 return 0;
1199}
1200
1201static int dispatch_sigusr2(sd_event_source *es, const struct signalfd_siginfo *si, void *userdata) {
1202 Server *s = userdata;
1203 int r;
1204
1205 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 1205, __PRETTY_FUNCTION__); } while (0)
;
1206
1207 log_info("Received request to rotate journal from PID " PID_FMT, si->ssi_pid)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1207, __func__, "Received request to rotate journal from PID "
"%" "i", si->ssi_pid) : -abs(_e); })
;
1208 server_rotate(s);
1209 server_vacuum(s, true1);
1210
1211 if (s->system_journal)
1212 patch_min_use(&s->system_storage);
1213 if (s->runtime_journal)
1214 patch_min_use(&s->runtime_storage);
1215
1216 /* Let clients know when the most recent rotation happened. */
1217 r = write_timestamp_file_atomic("/run/systemd/journal/rotated", now(CLOCK_MONOTONIC1));
1218 if (r < 0)
1219 log_warning_errno(r, "Failed to write /run/systemd/journal/rotated, ignoring: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1219, __func__, "Failed to write /run/systemd/journal/rotated, ignoring: %m"
) : -abs(_e); })
;
1220
1221 return 0;
1222}
1223
1224static int dispatch_sigterm(sd_event_source *es, const struct signalfd_siginfo *si, void *userdata) {
1225 Server *s = userdata;
1226
1227 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 1227, __PRETTY_FUNCTION__); } while (0)
;
1228
1229 log_received_signal(LOG_INFO6, si);
1230
1231 sd_event_exit(s->event, 0);
1232 return 0;
1233}
1234
1235static int dispatch_sigrtmin1(sd_event_source *es, const struct signalfd_siginfo *si, void *userdata) {
1236 Server *s = userdata;
1237 int r;
1238
1239 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 1239, __PRETTY_FUNCTION__); } while (0)
;
1240
1241 log_debug("Received request to sync from PID " PID_FMT, si->ssi_pid)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1241, __func__, "Received request to sync from PID "
"%" "i", si->ssi_pid) : -abs(_e); })
;
1242
1243 server_sync(s);
1244
1245 /* Let clients know when the most recent sync happened. */
1246 r = write_timestamp_file_atomic("/run/systemd/journal/synced", now(CLOCK_MONOTONIC1));
1247 if (r < 0)
1248 log_warning_errno(r, "Failed to write /run/systemd/journal/synced, ignoring: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1248, __func__, "Failed to write /run/systemd/journal/synced, ignoring: %m"
) : -abs(_e); })
;
1249
1250 return 0;
1251}
1252
1253static int setup_signals(Server *s) {
1254 int r;
1255
1256 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 1256, __PRETTY_FUNCTION__); } while (0)
;
1257
1258 assert_se(sigprocmask_many(SIG_SETMASK, NULL, SIGINT, SIGTERM, SIGUSR1, SIGUSR2, SIGRTMIN+1, -1) >= 0)do { if ((__builtin_expect(!!(!(sigprocmask_many(2, ((void*)0
), 2, 15, 10, 12, (__libc_current_sigrtmin ())+1, -1) >= 0
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("sigprocmask_many(SIG_SETMASK, NULL, SIGINT, SIGTERM, SIGUSR1, SIGUSR2, SIGRTMIN+1, -1) >= 0"
), "../src/journal/journald-server.c", 1258, __PRETTY_FUNCTION__
); } while (0)
;
1259
1260 r = sd_event_add_signal(s->event, &s->sigusr1_event_source, SIGUSR110, dispatch_sigusr1, s);
1261 if (r < 0)
1262 return r;
1263
1264 r = sd_event_add_signal(s->event, &s->sigusr2_event_source, SIGUSR212, dispatch_sigusr2, s);
1265 if (r < 0)
1266 return r;
1267
1268 r = sd_event_add_signal(s->event, &s->sigterm_event_source, SIGTERM15, dispatch_sigterm, s);
1269 if (r < 0)
1270 return r;
1271
1272 /* Let's process SIGTERM late, so that we flush all queued
1273 * messages to disk before we exit */
1274 r = sd_event_source_set_priority(s->sigterm_event_source, SD_EVENT_PRIORITY_NORMAL+20);
1275 if (r < 0)
1276 return r;
1277
1278 /* When journald is invoked on the terminal (when debugging),
1279 * it's useful if C-c is handled equivalent to SIGTERM. */
1280 r = sd_event_add_signal(s->event, &s->sigint_event_source, SIGINT2, dispatch_sigterm, s);
1281 if (r < 0)
1282 return r;
1283
1284 r = sd_event_source_set_priority(s->sigint_event_source, SD_EVENT_PRIORITY_NORMAL+20);
1285 if (r < 0)
1286 return r;
1287
1288 /* SIGRTMIN+1 causes an immediate sync. We process this very
1289 * late, so that everything else queued at this point is
1290 * really written to disk. Clients can watch
1291 * /run/systemd/journal/synced with inotify until its mtime
1292 * changes to see when a sync happened. */
1293 r = sd_event_add_signal(s->event, &s->sigrtmin1_event_source, SIGRTMIN(__libc_current_sigrtmin ())+1, dispatch_sigrtmin1, s);
1294 if (r < 0)
1295 return r;
1296
1297 r = sd_event_source_set_priority(s->sigrtmin1_event_source, SD_EVENT_PRIORITY_NORMAL+15);
1298 if (r < 0)
1299 return r;
1300
1301 return 0;
1302}
1303
1304static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
1305 Server *s = data;
1306 int r;
1307
1308 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 1308, __PRETTY_FUNCTION__); } while (0)
;
1309
1310 if (proc_cmdline_key_streq(key, "systemd.journald.forward_to_syslog")) {
1311
1312 r = value ? parse_boolean(value) : true1;
1313 if (r < 0)
1314 log_warning("Failed to parse forward to syslog switch \"%s\". Ignoring.", value)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1314, __func__, "Failed to parse forward to syslog switch \"%s\". Ignoring."
, value) : -abs(_e); })
;
1315 else
1316 s->forward_to_syslog = r;
1317
1318 } else if (proc_cmdline_key_streq(key, "systemd.journald.forward_to_kmsg")) {
1319
1320 r = value ? parse_boolean(value) : true1;
1321 if (r < 0)
1322 log_warning("Failed to parse forward to kmsg switch \"%s\". Ignoring.", value)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1322, __func__, "Failed to parse forward to kmsg switch \"%s\". Ignoring."
, value) : -abs(_e); })
;
1323 else
1324 s->forward_to_kmsg = r;
1325
1326 } else if (proc_cmdline_key_streq(key, "systemd.journald.forward_to_console")) {
1327
1328 r = value ? parse_boolean(value) : true1;
1329 if (r < 0)
1330 log_warning("Failed to parse forward to console switch \"%s\". Ignoring.", value)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1330, __func__, "Failed to parse forward to console switch \"%s\". Ignoring."
, value) : -abs(_e); })
;
1331 else
1332 s->forward_to_console = r;
1333
1334 } else if (proc_cmdline_key_streq(key, "systemd.journald.forward_to_wall")) {
1335
1336 r = value ? parse_boolean(value) : true1;
1337 if (r < 0)
1338 log_warning("Failed to parse forward to wall switch \"%s\". Ignoring.", value)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1338, __func__, "Failed to parse forward to wall switch \"%s\". Ignoring."
, value) : -abs(_e); })
;
1339 else
1340 s->forward_to_wall = r;
1341
1342 } else if (proc_cmdline_key_streq(key, "systemd.journald.max_level_console")) {
1343
1344 if (proc_cmdline_value_missing(key, value))
1345 return 0;
1346
1347 r = log_level_from_string(value);
1348 if (r < 0)
1349 log_warning("Failed to parse max level console value \"%s\". Ignoring.", value)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1349, __func__, "Failed to parse max level console value \"%s\". Ignoring."
, value) : -abs(_e); })
;
1350 else
1351 s->max_level_console = r;
1352
1353 } else if (proc_cmdline_key_streq(key, "systemd.journald.max_level_store")) {
1354
1355 if (proc_cmdline_value_missing(key, value))
1356 return 0;
1357
1358 r = log_level_from_string(value);
1359 if (r < 0)
1360 log_warning("Failed to parse max level store value \"%s\". Ignoring.", value)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1360, __func__, "Failed to parse max level store value \"%s\". Ignoring."
, value) : -abs(_e); })
;
1361 else
1362 s->max_level_store = r;
1363
1364 } else if (proc_cmdline_key_streq(key, "systemd.journald.max_level_syslog")) {
1365
1366 if (proc_cmdline_value_missing(key, value))
1367 return 0;
1368
1369 r = log_level_from_string(value);
1370 if (r < 0)
1371 log_warning("Failed to parse max level syslog value \"%s\". Ignoring.", value)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1371, __func__, "Failed to parse max level syslog value \"%s\". Ignoring."
, value) : -abs(_e); })
;
1372 else
1373 s->max_level_syslog = r;
1374
1375 } else if (proc_cmdline_key_streq(key, "systemd.journald.max_level_kmsg")) {
1376
1377 if (proc_cmdline_value_missing(key, value))
1378 return 0;
1379
1380 r = log_level_from_string(value);
1381 if (r < 0)
1382 log_warning("Failed to parse max level kmsg value \"%s\". Ignoring.", value)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1382, __func__, "Failed to parse max level kmsg value \"%s\". Ignoring."
, value) : -abs(_e); })
;
1383 else
1384 s->max_level_kmsg = r;
1385
1386 } else if (proc_cmdline_key_streq(key, "systemd.journald.max_level_wall")) {
1387
1388 if (proc_cmdline_value_missing(key, value))
1389 return 0;
1390
1391 r = log_level_from_string(value);
1392 if (r < 0)
1393 log_warning("Failed to parse max level wall value \"%s\". Ignoring.", value)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1393, __func__, "Failed to parse max level wall value \"%s\". Ignoring."
, value) : -abs(_e); })
;
1394 else
1395 s->max_level_wall = r;
1396
1397 } else if (startswith(key, "systemd.journald"))
1398 log_warning("Unknown journald kernel command line option \"%s\". Ignoring.", key)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1398, __func__, "Unknown journald kernel command line option \"%s\". Ignoring."
, key) : -abs(_e); })
;
1399
1400 /* do not warn about state here, since probably systemd already did */
1401 return 0;
1402}
1403
1404static int server_parse_config_file(Server *s) {
1405 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 1405, __PRETTY_FUNCTION__); } while (0)
;
1406
1407 return config_parse_many_nulstr(PKGSYSCONFDIR"/etc/systemd" "/journald.conf",
1408 CONF_PATHS_NULSTR("systemd/journald.conf.d")"/etc/" "systemd/journald.conf.d" "\0" "/run/" "systemd/journald.conf.d"
"\0" "/usr/local/lib/" "systemd/journald.conf.d" "\0" "/usr/lib/"
"systemd/journald.conf.d" "\0"
,
1409 "Journal\0",
1410 config_item_perf_lookup, journald_gperf_lookup,
1411 CONFIG_PARSE_WARN, s);
1412}
1413
1414static int server_dispatch_sync(sd_event_source *es, usec_t t, void *userdata) {
1415 Server *s = userdata;
1416
1417 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 1417, __PRETTY_FUNCTION__); } while (0)
;
1418
1419 server_sync(s);
1420 return 0;
1421}
1422
1423int server_schedule_sync(Server *s, int priority) {
1424 int r;
1425
1426 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 1426, __PRETTY_FUNCTION__); } while (0)
;
1427
1428 if (priority <= LOG_CRIT2) {
1429 /* Immediately sync to disk when this is of priority CRIT, ALERT, EMERG */
1430 server_sync(s);
1431 return 0;
1432 }
1433
1434 if (s->sync_scheduled)
1435 return 0;
1436
1437 if (s->sync_interval_usec > 0) {
1438 usec_t when;
1439
1440 r = sd_event_now(s->event, CLOCK_MONOTONIC1, &when);
1441 if (r < 0)
1442 return r;
1443
1444 when += s->sync_interval_usec;
1445
1446 if (!s->sync_event_source) {
1447 r = sd_event_add_time(
1448 s->event,
1449 &s->sync_event_source,
1450 CLOCK_MONOTONIC1,
1451 when, 0,
1452 server_dispatch_sync, s);
1453 if (r < 0)
1454 return r;
1455
1456 r = sd_event_source_set_priority(s->sync_event_source, SD_EVENT_PRIORITY_IMPORTANT);
1457 } else {
1458 r = sd_event_source_set_time(s->sync_event_source, when);
1459 if (r < 0)
1460 return r;
1461
1462 r = sd_event_source_set_enabled(s->sync_event_source, SD_EVENT_ONESHOT);
1463 }
1464 if (r < 0)
1465 return r;
1466
1467 s->sync_scheduled = true1;
1468 }
1469
1470 return 0;
1471}
1472
1473static int dispatch_hostname_change(sd_event_source *es, int fd, uint32_t revents, void *userdata) {
1474 Server *s = userdata;
1475
1476 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 1476, __PRETTY_FUNCTION__); } while (0)
;
1477
1478 server_cache_hostname(s);
1479 return 0;
1480}
1481
1482static int server_open_hostname(Server *s) {
1483 int r;
1484
1485 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 1485, __PRETTY_FUNCTION__); } while (0)
;
1486
1487 s->hostname_fd = open("/proc/sys/kernel/hostname",
1488 O_RDONLY00|O_CLOEXEC02000000|O_NONBLOCK04000|O_NOCTTY0400);
1489 if (s->hostname_fd < 0)
1490 return log_error_errno(errno, "Failed to open /proc/sys/kernel/hostname: %m")({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/journal/journald-server.c", 1490
, __func__, "Failed to open /proc/sys/kernel/hostname: %m") :
-abs(_e); })
;
1491
1492 r = sd_event_add_io(s->event, &s->hostname_event_source, s->hostname_fd, 0, dispatch_hostname_change, s);
1493 if (r < 0) {
1494 /* kernels prior to 3.2 don't support polling this file. Ignore
1495 * the failure. */
1496 if (r == -EPERM1) {
1497 log_warning_errno(r, "Failed to register hostname fd in event loop, ignoring: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1497, __func__, "Failed to register hostname fd in event loop, ignoring: %m"
) : -abs(_e); })
;
1498 s->hostname_fd = safe_close(s->hostname_fd);
1499 return 0;
1500 }
1501
1502 return log_error_errno(r, "Failed to register hostname fd in event loop: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1502, __func__, "Failed to register hostname fd in event loop: %m"
) : -abs(_e); })
;
1503 }
1504
1505 r = sd_event_source_set_priority(s->hostname_event_source, SD_EVENT_PRIORITY_IMPORTANT-10);
1506 if (r < 0)
1507 return log_error_errno(r, "Failed to adjust priority of host name event source: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1507, __func__, "Failed to adjust priority of host name event source: %m"
) : -abs(_e); })
;
1508
1509 return 0;
1510}
1511
1512static int dispatch_notify_event(sd_event_source *es, int fd, uint32_t revents, void *userdata) {
1513 Server *s = userdata;
1514 int r;
1515
1516 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 1516, __PRETTY_FUNCTION__); } while (0)
;
1517 assert(s->notify_event_source == es)do { if ((__builtin_expect(!!(!(s->notify_event_source == es
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("s->notify_event_source == es"
), "../src/journal/journald-server.c", 1517, __PRETTY_FUNCTION__
); } while (0)
;
1518 assert(s->notify_fd == fd)do { if ((__builtin_expect(!!(!(s->notify_fd == fd)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s->notify_fd == fd"), "../src/journal/journald-server.c"
, 1518, __PRETTY_FUNCTION__); } while (0)
;
1519
1520 /* The $NOTIFY_SOCKET is writable again, now send exactly one
1521 * message on it. Either it's the watchdog event, the initial
1522 * READY=1 event or an stdout stream event. If there's nothing
1523 * to write anymore, turn our event source off. The next time
1524 * there's something to send it will be turned on again. */
1525
1526 if (!s->sent_notify_ready) {
1527 static const char p[] =
1528 "READY=1\n"
1529 "STATUS=Processing requests...";
1530 ssize_t l;
1531
1532 l = send(s->notify_fd, p, strlen(p), MSG_DONTWAITMSG_DONTWAIT);
1533 if (l < 0) {
1534 if (errno(*__errno_location ()) == EAGAIN11)
1535 return 0;
1536
1537 return log_error_errno(errno, "Failed to send READY=1 notification message: %m")({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/journal/journald-server.c", 1537
, __func__, "Failed to send READY=1 notification message: %m"
) : -abs(_e); })
;
1538 }
1539
1540 s->sent_notify_ready = true1;
1541 log_debug("Sent READY=1 notification.")({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1541, __func__, "Sent READY=1 notification."
) : -abs(_e); })
;
1542
1543 } else if (s->send_watchdog) {
1544
1545 static const char p[] =
1546 "WATCHDOG=1";
1547
1548 ssize_t l;
1549
1550 l = send(s->notify_fd, p, strlen(p), MSG_DONTWAITMSG_DONTWAIT);
1551 if (l < 0) {
1552 if (errno(*__errno_location ()) == EAGAIN11)
1553 return 0;
1554
1555 return log_error_errno(errno, "Failed to send WATCHDOG=1 notification message: %m")({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/journal/journald-server.c", 1555
, __func__, "Failed to send WATCHDOG=1 notification message: %m"
) : -abs(_e); })
;
1556 }
1557
1558 s->send_watchdog = false0;
1559 log_debug("Sent WATCHDOG=1 notification.")({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1559, __func__, "Sent WATCHDOG=1 notification."
) : -abs(_e); })
;
1560
1561 } else if (s->stdout_streams_notify_queue)
1562 /* Dispatch one stream notification event */
1563 stdout_stream_send_notify(s->stdout_streams_notify_queue);
1564
1565 /* Leave us enabled if there's still more to do. */
1566 if (s->send_watchdog || s->stdout_streams_notify_queue)
1567 return 0;
1568
1569 /* There was nothing to do anymore, let's turn ourselves off. */
1570 r = sd_event_source_set_enabled(es, SD_EVENT_OFF);
1571 if (r < 0)
1572 return log_error_errno(r, "Failed to turn off notify event source: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1572, __func__, "Failed to turn off notify event source: %m"
) : -abs(_e); })
;
1573
1574 return 0;
1575}
1576
1577static int dispatch_watchdog(sd_event_source *es, uint64_t usec, void *userdata) {
1578 Server *s = userdata;
1579 int r;
1580
1581 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 1581, __PRETTY_FUNCTION__); } while (0)
;
1582
1583 s->send_watchdog = true1;
1584
1585 r = sd_event_source_set_enabled(s->notify_event_source, SD_EVENT_ON);
1586 if (r < 0)
1587 log_warning_errno(r, "Failed to turn on notify event source: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1587, __func__, "Failed to turn on notify event source: %m"
) : -abs(_e); })
;
1588
1589 r = sd_event_source_set_time(s->watchdog_event_source, usec + s->watchdog_usec / 2);
1590 if (r < 0)
1591 return log_error_errno(r, "Failed to restart watchdog event source: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1591, __func__, "Failed to restart watchdog event source: %m"
) : -abs(_e); })
;
1592
1593 r = sd_event_source_set_enabled(s->watchdog_event_source, SD_EVENT_ON);
1594 if (r < 0)
1595 return log_error_errno(r, "Failed to enable watchdog event source: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1595, __func__, "Failed to enable watchdog event source: %m"
) : -abs(_e); })
;
1596
1597 return 0;
1598}
1599
1600static int server_connect_notify(Server *s) {
1601 union sockaddr_union sa = {
1602 .un.sun_family = AF_UNIX1,
1603 };
1604 const char *e;
1605 int r;
1606
1607 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 1607, __PRETTY_FUNCTION__); } while (0)
;
1608 assert(s->notify_fd < 0)do { if ((__builtin_expect(!!(!(s->notify_fd < 0)),0)))
log_assert_failed_realm(LOG_REALM_SYSTEMD, ("s->notify_fd < 0"
), "../src/journal/journald-server.c", 1608, __PRETTY_FUNCTION__
); } while (0)
;
1609 assert(!s->notify_event_source)do { if ((__builtin_expect(!!(!(!s->notify_event_source)),
0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!s->notify_event_source"
), "../src/journal/journald-server.c", 1609, __PRETTY_FUNCTION__
); } while (0)
;
1610
1611 /*
1612 So here's the problem: we'd like to send notification
1613 messages to PID 1, but we cannot do that via sd_notify(),
1614 since that's synchronous, and we might end up blocking on
1615 it. Specifically: given that PID 1 might block on
1616 dbus-daemon during IPC, and dbus-daemon is logging to us,
1617 and might hence block on us, we might end up in a deadlock
1618 if we block on sending PID 1 notification messages — by
1619 generating a full blocking circle. To avoid this, let's
1620 create a non-blocking socket, and connect it to the
1621 notification socket, and then wait for POLLOUT before we
1622 send anything. This should efficiently avoid any deadlocks,
1623 as we'll never block on PID 1, hence PID 1 can safely block
1624 on dbus-daemon which can safely block on us again.
1625
1626 Don't think that this issue is real? It is, see:
1627 https://github.com/systemd/systemd/issues/1505
1628 */
1629
1630 e = getenv("NOTIFY_SOCKET");
1631 if (!e)
1632 return 0;
1633
1634 if (!IN_SET(e[0], '@', '/')({ _Bool _found = 0; static __attribute__ ((unused)) char _static_assert__macros_need_to_be_extended
[20 - sizeof((int[]){'@', '/'})/sizeof(int)]; switch(e[0]) { case
'@': case '/': _found = 1; break; default: break; } _found; }
)
|| e[1] == 0) {
1635 log_error("NOTIFY_SOCKET set to an invalid value: %s", e)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1635, __func__, "NOTIFY_SOCKET set to an invalid value: %s"
, e) : -abs(_e); })
;
1636 return -EINVAL22;
1637 }
1638
1639 if (strlen(e) > sizeof(sa.un.sun_path)) {
1640 log_error("NOTIFY_SOCKET path too long: %s", e)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1640, __func__, "NOTIFY_SOCKET path too long: %s"
, e) : -abs(_e); })
;
1641 return -EINVAL22;
1642 }
1643
1644 s->notify_fd = socket(AF_UNIX1, SOCK_DGRAMSOCK_DGRAM|SOCK_CLOEXECSOCK_CLOEXEC|SOCK_NONBLOCKSOCK_NONBLOCK, 0);
1645 if (s->notify_fd < 0)
1646 return log_error_errno(errno, "Failed to create notify socket: %m")({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/journal/journald-server.c", 1646
, __func__, "Failed to create notify socket: %m") : -abs(_e);
})
;
1647
1648 (void) fd_inc_sndbuf(s->notify_fd, NOTIFY_SNDBUF_SIZE(8*1024*1024));
1649
1650 strncpy(sa.un.sun_path, e, sizeof(sa.un.sun_path));
1651 if (sa.un.sun_path[0] == '@')
1652 sa.un.sun_path[0] = 0;
1653
1654 r = connect(s->notify_fd, &sa.sa, SOCKADDR_UN_LEN(sa.un)({ const struct sockaddr_un *_sa = &(sa.un); do { if ((__builtin_expect
(!!(!(_sa->sun_family == 1)),0))) log_assert_failed_realm(
LOG_REALM_SYSTEMD, ("_sa->sun_family == AF_UNIX"), "../src/journal/journald-server.c"
, 1654, __PRETTY_FUNCTION__); } while (0); __builtin_offsetof
(struct sockaddr_un, sun_path) + (_sa->sun_path[0] == 0 ? 1
+ strnlen(_sa->sun_path+1, sizeof(_sa->sun_path)-1) : strnlen
(_sa->sun_path, sizeof(_sa->sun_path))); })
);
1655 if (r < 0)
1656 return log_error_errno(errno, "Failed to connect to notify socket: %m")({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/journal/journald-server.c", 1656
, __func__, "Failed to connect to notify socket: %m") : -abs(
_e); })
;
1657
1658 r = sd_event_add_io(s->event, &s->notify_event_source, s->notify_fd, EPOLLOUTEPOLLOUT, dispatch_notify_event, s);
1659 if (r < 0)
1660 return log_error_errno(r, "Failed to watch notification socket: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1660, __func__, "Failed to watch notification socket: %m"
) : -abs(_e); })
;
1661
1662 if (sd_watchdog_enabled(false0, &s->watchdog_usec) > 0) {
1663 s->send_watchdog = true1;
1664
1665 r = sd_event_add_time(s->event, &s->watchdog_event_source, CLOCK_MONOTONIC1, now(CLOCK_MONOTONIC1) + s->watchdog_usec/2, s->watchdog_usec/4, dispatch_watchdog, s);
1666 if (r < 0)
1667 return log_error_errno(r, "Failed to add watchdog time event: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1667, __func__, "Failed to add watchdog time event: %m"
) : -abs(_e); })
;
1668 }
1669
1670 /* This should fire pretty soon, which we'll use to send the
1671 * READY=1 event. */
1672
1673 return 0;
1674}
1675
1676int server_init(Server *s) {
1677 _cleanup_fdset_free___attribute__((cleanup(fdset_freep))) FDSet *fds = NULL((void*)0);
1678 int n, r, fd;
1679 bool_Bool no_sockets;
1680
1681 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 1681, __PRETTY_FUNCTION__); } while (0)
;
1682
1683 zero(*s)(({ size_t _l_ = (sizeof(*s)); void *_x_ = (&(*s)); _l_ ==
0 ? _x_ : memset(_x_, 0, _l_); }))
;
1684 s->syslog_fd = s->native_fd = s->stdout_fd = s->dev_kmsg_fd = s->audit_fd = s->hostname_fd = s->notify_fd = -1;
1685 s->compress.enabled = true1;
1686 s->compress.threshold_bytes = (uint64_t) -1;
1687 s->seal = true1;
1688 s->read_kmsg = true1;
1689
1690 s->watchdog_usec = USEC_INFINITY((usec_t) -1);
1691
1692 s->sync_interval_usec = DEFAULT_SYNC_INTERVAL_USEC(5*((usec_t) (60ULL*((usec_t) 1000000ULL))));
1693 s->sync_scheduled = false0;
1694
1695 s->rate_limit_interval = DEFAULT_RATE_LIMIT_INTERVAL(30*((usec_t) 1000000ULL));
1696 s->rate_limit_burst = DEFAULT_RATE_LIMIT_BURST10000;
1697
1698 s->forward_to_wall = true1;
1699
1700 s->max_file_usec = DEFAULT_MAX_FILE_USEC((usec_t) (2629800ULL*((usec_t) 1000000ULL)));
1701
1702 s->max_level_store = LOG_DEBUG7;
1703 s->max_level_syslog = LOG_DEBUG7;
1704 s->max_level_kmsg = LOG_NOTICE5;
1705 s->max_level_console = LOG_INFO6;
1706 s->max_level_wall = LOG_EMERG0;
1707
1708 s->line_max = DEFAULT_LINE_MAX(48*1024);
1709
1710 journal_reset_metrics(&s->system_storage.metrics);
1711 journal_reset_metrics(&s->runtime_storage.metrics);
1712
1713 server_parse_config_file(s);
1714
1715 r = proc_cmdline_parse(parse_proc_cmdline_item, s, PROC_CMDLINE_STRIP_RD_PREFIX);
1716 if (r < 0)
1717 log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1717, __func__, "Failed to parse kernel command line, ignoring: %m"
) : -abs(_e); })
;
1718
1719 if (!!s->rate_limit_interval ^ !!s->rate_limit_burst) {
1720 log_debug("Setting both rate limit interval and burst from "USEC_FMT",%u to 0,0",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1721, __func__, "Setting both rate limit interval and burst from "
"%" "l" "u"",%u to 0,0", s->rate_limit_interval, s->rate_limit_burst
) : -abs(_e); })
1721 s->rate_limit_interval, s->rate_limit_burst)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1721, __func__, "Setting both rate limit interval and burst from "
"%" "l" "u"",%u to 0,0", s->rate_limit_interval, s->rate_limit_burst
) : -abs(_e); })
;
1722 s->rate_limit_interval = s->rate_limit_burst = 0;
1723 }
1724
1725 (void) mkdir_p("/run/systemd/journal", 0755);
1726
1727 s->user_journals = ordered_hashmap_new(NULL)internal_ordered_hashmap_new(((void*)0) );
1728 if (!s->user_journals)
1729 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/journal/journald-server.c"
, 1729, __func__)
;
1730
1731 s->mmap = mmap_cache_new();
1732 if (!s->mmap)
1733 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/journal/journald-server.c"
, 1733, __func__)
;
1734
1735 s->deferred_closes = set_new(NULL)internal_set_new(((void*)0) );
1736 if (!s->deferred_closes)
1737 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/journal/journald-server.c"
, 1737, __func__)
;
1738
1739 r = sd_event_default(&s->event);
1740 if (r < 0)
1741 return log_error_errno(r, "Failed to create event loop: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1741, __func__, "Failed to create event loop: %m"
) : -abs(_e); })
;
1742
1743 n = sd_listen_fds(true1);
1744 if (n < 0)
1745 return log_error_errno(n, "Failed to read listening file descriptors from environment: %m")({ int _level = ((3)), _e = ((n)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1745, __func__, "Failed to read listening file descriptors from environment: %m"
) : -abs(_e); })
;
1746
1747 for (fd = SD_LISTEN_FDS_START3; fd < SD_LISTEN_FDS_START3 + n; fd++) {
1748
1749 if (sd_is_socket_unix(fd, SOCK_DGRAMSOCK_DGRAM, -1, "/run/systemd/journal/socket", 0) > 0) {
1750
1751 if (s->native_fd >= 0) {
1752 log_error("Too many native sockets passed.")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1752, __func__, "Too many native sockets passed."
) : -abs(_e); })
;
1753 return -EINVAL22;
1754 }
1755
1756 s->native_fd = fd;
1757
1758 } else if (sd_is_socket_unix(fd, SOCK_STREAMSOCK_STREAM, 1, "/run/systemd/journal/stdout", 0) > 0) {
1759
1760 if (s->stdout_fd >= 0) {
1761 log_error("Too many stdout sockets passed.")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1761, __func__, "Too many stdout sockets passed."
) : -abs(_e); })
;
1762 return -EINVAL22;
1763 }
1764
1765 s->stdout_fd = fd;
1766
1767 } else if (sd_is_socket_unix(fd, SOCK_DGRAMSOCK_DGRAM, -1, "/dev/log", 0) > 0 ||
1768 sd_is_socket_unix(fd, SOCK_DGRAMSOCK_DGRAM, -1, "/run/systemd/journal/dev-log", 0) > 0) {
1769
1770 if (s->syslog_fd >= 0) {
1771 log_error("Too many /dev/log sockets passed.")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1771, __func__, "Too many /dev/log sockets passed."
) : -abs(_e); })
;
1772 return -EINVAL22;
1773 }
1774
1775 s->syslog_fd = fd;
1776
1777 } else if (sd_is_socket(fd, AF_NETLINK16, SOCK_RAWSOCK_RAW, -1) > 0) {
1778
1779 if (s->audit_fd >= 0) {
1780 log_error("Too many audit sockets passed.")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1780, __func__, "Too many audit sockets passed."
) : -abs(_e); })
;
1781 return -EINVAL22;
1782 }
1783
1784 s->audit_fd = fd;
1785
1786 } else {
1787
1788 if (!fds) {
1789 fds = fdset_new();
1790 if (!fds)
1791 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/journal/journald-server.c"
, 1791, __func__)
;
1792 }
1793
1794 r = fdset_put(fds, fd);
1795 if (r < 0)
1796 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/journal/journald-server.c"
, 1796, __func__)
;
1797 }
1798 }
1799
1800 /* Try to restore streams, but don't bother if this fails */
1801 (void) server_restore_streams(s, fds);
1802
1803 if (fdset_size(fds) > 0) {
1804 log_warning("%u unknown file descriptors passed, closing.", fdset_size(fds))({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/journal/journald-server.c", 1804, __func__, "%u unknown file descriptors passed, closing."
, fdset_size(fds)) : -abs(_e); })
;
1805 fds = fdset_free(fds);
1806 }
1807
1808 no_sockets = s->native_fd < 0 && s->stdout_fd < 0 && s->syslog_fd < 0 && s->audit_fd < 0;
1809
1810 /* always open stdout, syslog, native, and kmsg sockets */
1811
1812 /* systemd-journald.socket: /run/systemd/journal/stdout */
1813 r = server_open_stdout_socket(s);
1814 if (r < 0)
1815 return r;
1816
1817 /* systemd-journald-dev-log.socket: /run/systemd/journal/dev-log */
1818 r = server_open_syslog_socket(s);
1819 if (r < 0)
1820 return r;
1821
1822 /* systemd-journald.socket: /run/systemd/journal/socket */
1823 r = server_open_native_socket(s);
1824 if (r < 0)
1825 return r;
1826
1827 /* /dev/kmsg */
1828 r = server_open_dev_kmsg(s);
1829 if (r < 0)
1830 return r;
1831
1832 /* Unless we got *some* sockets and not audit, open audit socket */
1833 if (s->audit_fd >= 0 || no_sockets) {
1834 r = server_open_audit(s);
1835 if (r < 0)
1836 return r;
1837 }
1838
1839 r = server_open_kernel_seqnum(s);
1840 if (r < 0)
1841 return r;
1842
1843 r = server_open_hostname(s);
1844 if (r < 0)
1845 return r;
1846
1847 r = setup_signals(s);
1848 if (r < 0)
1849 return r;
1850
1851 s->udev = udev_new();
1852 if (!s->udev)
1853 return -ENOMEM12;
1854
1855 s->rate_limit = journal_rate_limit_new();
1856 if (!s->rate_limit)
1857 return -ENOMEM12;
1858
1859 r = cg_get_root_path(&s->cgroup_root);
1860 if (r < 0)
1861 return r;
1862
1863 server_cache_hostname(s);
1864 server_cache_boot_id(s);
1865 server_cache_machine_id(s);
1866
1867 s->runtime_storage.name = "Runtime journal";
1868 s->system_storage.name = "System journal";
1869
1870 s->runtime_storage.path = strjoin("/run/log/journal/", SERVER_MACHINE_ID(s))strjoin_real(("/run/log/journal/"), ((s)->machine_id_field
+ (sizeof("""_MACHINE_ID=""") - 1)), ((void*)0))
;
1871 s->system_storage.path = strjoin("/var/log/journal/", SERVER_MACHINE_ID(s))strjoin_real(("/var/log/journal/"), ((s)->machine_id_field
+ (sizeof("""_MACHINE_ID=""") - 1)), ((void*)0))
;
1872 if (!s->runtime_storage.path || !s->system_storage.path)
1873 return -ENOMEM12;
1874
1875 (void) server_connect_notify(s);
1876
1877 (void) client_context_acquire_default(s);
1878
1879 return system_journal_open(s, false0);
1880}
1881
1882void server_maybe_append_tags(Server *s) {
1883#if HAVE_GCRYPT1
1884 JournalFile *f;
1885 Iterator i;
1886 usec_t n;
1887
1888 n = now(CLOCK_REALTIME0);
1889
1890 if (s->system_journal)
1891 journal_file_maybe_append_tag(s->system_journal, n);
1892
1893 ORDERED_HASHMAP_FOREACH(f, s->user_journals, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); ordered_hashmap_iterate((s->user_journals
), &(i), (void**)&(f), ((void*)0)); )
1894 journal_file_maybe_append_tag(f, n);
1895#endif
1896}
1897
1898void server_done(Server *s) {
1899 assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("s"), "../src/journal/journald-server.c"
, 1899, __PRETTY_FUNCTION__); } while (0)
;
1900
1901 set_free_with_destructor(s->deferred_closes, journal_file_close)({ ({ void *_item; while ((_item = set_steal_first(s->deferred_closes
))) journal_file_close(_item); }); set_free(s->deferred_closes
); })
;
1902
1903 while (s->stdout_streams)
1904 stdout_stream_free(s->stdout_streams);
1905
1906 client_context_flush_all(s);
1907
1908 (void) journal_file_close(s->system_journal);
1909 (void) journal_file_close(s->runtime_journal);
1910
1911 ordered_hashmap_free_with_destructor(s->user_journals, journal_file_close)({ ({ void *_item; while ((_item = ordered_hashmap_steal_first
(s->user_journals))) journal_file_close(_item); }); ordered_hashmap_free
(s->user_journals); })
;
1912
1913 sd_event_source_unref(s->syslog_event_source);
1914 sd_event_source_unref(s->native_event_source);
1915 sd_event_source_unref(s->stdout_event_source);
1916 sd_event_source_unref(s->dev_kmsg_event_source);
1917 sd_event_source_unref(s->audit_event_source);
1918 sd_event_source_unref(s->sync_event_source);
1919 sd_event_source_unref(s->sigusr1_event_source);
1920 sd_event_source_unref(s->sigusr2_event_source);
1921 sd_event_source_unref(s->sigterm_event_source);
1922 sd_event_source_unref(s->sigint_event_source);
1923 sd_event_source_unref(s->sigrtmin1_event_source);
1924 sd_event_source_unref(s->hostname_event_source);
1925 sd_event_source_unref(s->notify_event_source);
1926 sd_event_source_unref(s->watchdog_event_source);
1927 sd_event_unref(s->event);
1928
1929 safe_close(s->syslog_fd);
1930 safe_close(s->native_fd);
1931 safe_close(s->stdout_fd);
1932 safe_close(s->dev_kmsg_fd);
1933 safe_close(s->audit_fd);
1934 safe_close(s->hostname_fd);
1935 safe_close(s->notify_fd);
1936
1937 if (s->rate_limit)
1938 journal_rate_limit_free(s->rate_limit);
1939
1940 if (s->kernel_seqnum)
1941 munmap(s->kernel_seqnum, sizeof(uint64_t));
1942
1943 free(s->buffer);
1944 free(s->tty_path);
1945 free(s->cgroup_root);
1946 free(s->hostname_field);
1947 free(s->runtime_storage.path);
1948 free(s->system_storage.path);
1949
1950 if (s->mmap)
1951 mmap_cache_unref(s->mmap);
1952
1953 udev_unref(s->udev);
1954}
1955
1956static const char* const storage_table[_STORAGE_MAX] = {
1957 [STORAGE_AUTO] = "auto",
1958 [STORAGE_VOLATILE] = "volatile",
1959 [STORAGE_PERSISTENT] = "persistent",
1960 [STORAGE_NONE] = "none"
1961};
1962
1963DEFINE_STRING_TABLE_LOOKUP(storage, Storage)const char *storage_to_string(Storage i) { if (i < 0 || i >=
(Storage) __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(storage_table), typeof(&*(storage_table))), sizeof
(storage_table)/sizeof((storage_table)[0]), ((void)0)))) return
((void*)0); return storage_table[i]; } Storage storage_from_string
(const char *s) { return (Storage) string_table_lookup(storage_table
, __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(storage_table), typeof(&*(storage_table))), sizeof
(storage_table)/sizeof((storage_table)[0]), ((void)0))), s); }
;
1964DEFINE_CONFIG_PARSE_ENUM(config_parse_storage, storage, Storage, "Failed to parse storage setting")int config_parse_storage(const char *unit, const char *filename
, unsigned line, const char *section, unsigned section_line, const
char *lvalue, int ltype, const char *rvalue, void *data, void
*userdata) { Storage *i = data, x; do { if ((__builtin_expect
(!!(!(filename)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("filename"), "../src/journal/journald-server.c", 1964, __PRETTY_FUNCTION__
); } while (0); do { if ((__builtin_expect(!!(!(lvalue)),0)))
log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lvalue"), "../src/journal/journald-server.c"
, 1964, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect
(!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("rvalue"), "../src/journal/journald-server.c", 1964, __PRETTY_FUNCTION__
); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("data"), "../src/journal/journald-server.c"
, 1964, __PRETTY_FUNCTION__); } while (0); x = storage_from_string
(rvalue); if (x < 0) { ({ int _level = (3), _e = (0); (log_get_max_level_realm
(LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal
(unit, _level, filename, line, _e, "../src/journal/journald-server.c"
, 1964, __func__, "Failed to parse storage setting" ", ignoring: %s"
, rvalue) : -abs(_e); }); return 0; } *i = x; return 0; }
;
1965
1966static const char* const split_mode_table[_SPLIT_MAX] = {
1967 [SPLIT_LOGIN] = "login",
1968 [SPLIT_UID] = "uid",
1969 [SPLIT_NONE] = "none",
1970};
1971
1972DEFINE_STRING_TABLE_LOOKUP(split_mode, SplitMode)const char *split_mode_to_string(SplitMode i) { if (i < 0 ||
i >= (SplitMode) __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(split_mode_table), typeof(&*(split_mode_table))),
sizeof(split_mode_table)/sizeof((split_mode_table)[0]), ((void
)0)))) return ((void*)0); return split_mode_table[i]; } SplitMode
split_mode_from_string(const char *s) { return (SplitMode) string_table_lookup
(split_mode_table, __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(split_mode_table), typeof(&*(split_mode_table))),
sizeof(split_mode_table)/sizeof((split_mode_table)[0]), ((void
)0))), s); }
;
1973DEFINE_CONFIG_PARSE_ENUM(config_parse_split_mode, split_mode, SplitMode, "Failed to parse split mode setting")int config_parse_split_mode(const char *unit, const char *filename
, unsigned line, const char *section, unsigned section_line, const
char *lvalue, int ltype, const char *rvalue, void *data, void
*userdata) { SplitMode *i = data, x; do { if ((__builtin_expect
(!!(!(filename)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("filename"), "../src/journal/journald-server.c", 1973, __PRETTY_FUNCTION__
); } while (0); do { if ((__builtin_expect(!!(!(lvalue)),0)))
log_assert_failed_realm(LOG_REALM_SYSTEMD, ("lvalue"), "../src/journal/journald-server.c"
, 1973, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect
(!!(!(rvalue)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("rvalue"), "../src/journal/journald-server.c", 1973, __PRETTY_FUNCTION__
); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("data"), "../src/journal/journald-server.c"
, 1973, __PRETTY_FUNCTION__); } while (0); x = split_mode_from_string
(rvalue); if (x < 0) { ({ int _level = (3), _e = (0); (log_get_max_level_realm
(LOG_REALM_SYSTEMD) >= ((_level) & 0x07)) ? log_syntax_internal
(unit, _level, filename, line, _e, "../src/journal/journald-server.c"
, 1973, __func__, "Failed to parse split mode setting" ", ignoring: %s"
, rvalue) : -abs(_e); }); return 0; } *i = x; return 0; }
;
1974
1975int config_parse_line_max(
1976 const char* unit,
1977 const char *filename,
1978 unsigned line,
1979 const char *section,
1980 unsigned section_line,
1981 const char *lvalue,
1982 int ltype,
1983 const char *rvalue,
1984 void *data,
1985 void *userdata) {
1986
1987 size_t *sz = data;
1988 int r;
1989
1990 assert(filename)do { if ((__builtin_expect(!!(!(filename)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("filename"), "../src/journal/journald-server.c"
, 1990, __PRETTY_FUNCTION__); } while (0)
;
1991 assert(lvalue)do { if ((__builtin_expect(!!(!(lvalue)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("lvalue"), "../src/journal/journald-server.c"
, 1991, __PRETTY_FUNCTION__); } while (0)
;
1992 assert(rvalue)do { if ((__builtin_expect(!!(!(rvalue)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("rvalue"), "../src/journal/journald-server.c"
, 1992, __PRETTY_FUNCTION__); } while (0)
;
1993 assert(data)do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("data"), "../src/journal/journald-server.c"
, 1993, __PRETTY_FUNCTION__); } while (0)
;
1994
1995 if (isempty(rvalue))
1996 /* Empty assignment means default */
1997 *sz = DEFAULT_LINE_MAX(48*1024);
1998 else {
1999 uint64_t v;
2000
2001 r = parse_size(rvalue, 1024, &v);
2002 if (r < 0) {
2003 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse LineMax= value, ignoring: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD
) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level
, filename, line, _e, "../src/journal/journald-server.c", 2003
, __func__, "Failed to parse LineMax= value, ignoring: %s", rvalue
) : -abs(_e); })
;
2004 return 0;
2005 }
2006
2007 if (v < 79) {
2008 /* Why specify 79 here as minimum line length? Simply, because the most common traditional
2009 * terminal size is 80ch, and it might make sense to break one character before the natural
2010 * line break would occur on that. */
2011 log_syntax(unit, LOG_WARNING, filename, line, 0, "LineMax= too small, clamping to 79: %s", rvalue)({ int _level = (4), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD
) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level
, filename, line, _e, "../src/journal/journald-server.c", 2011
, __func__, "LineMax= too small, clamping to 79: %s", rvalue)
: -abs(_e); })
;
2012 *sz = 79;
2013 } else if (v > (uint64_t) (SSIZE_MAX9223372036854775807L-1)) {
2014 /* So, why specify SSIZE_MAX-1 here? Because that's one below the largest size value read()
2015 * can return, and we need one extra byte for the trailing NUL byte. Of course IRL such large
2016 * memory allocations will fail anyway, hence this limit is mostly theoretical anyway, as we'll
2017 * fail much earlier anyway. */
2018 log_syntax(unit, LOG_WARNING, filename, line, 0, "LineMax= too large, clamping to %" PRIu64 ": %s", (uint64_t) (SSIZE_MAX-1), rvalue)({ int _level = (4), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD
) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level
, filename, line, _e, "../src/journal/journald-server.c", 2018
, __func__, "LineMax= too large, clamping to %" "l" "u" ": %s"
, (uint64_t) (9223372036854775807L -1), rvalue) : -abs(_e); }
)
;
2019 *sz = SSIZE_MAX9223372036854775807L-1;
2020 } else
2021 *sz = (size_t) v;
2022 }
2023
2024 return 0;
2025}
2026
2027int config_parse_compress(const char* unit,
2028 const char *filename,
2029 unsigned line,
2030 const char *section,
2031 unsigned section_line,
2032 const char *lvalue,
2033 int ltype,
2034 const char *rvalue,
2035 void *data,
2036 void *userdata) {
2037 JournalCompressOptions* compress = data;
2038 int r;
2039
2040 if (streq(rvalue, "1")(strcmp((rvalue),("1")) == 0)) {
2041 log_syntax(unit, LOG_WARNING, filename, line, 0,({ int _level = (4), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD
) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level
, filename, line, _e, "../src/journal/journald-server.c", 2042
, __func__, "Compress= ambiguously specified as 1, enabling compression with default threshold"
) : -abs(_e); })
2042 "Compress= ambiguously specified as 1, enabling compression with default threshold")({ int _level = (4), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD
) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level
, filename, line, _e, "../src/journal/journald-server.c", 2042
, __func__, "Compress= ambiguously specified as 1, enabling compression with default threshold"
) : -abs(_e); })
;
2043 compress->enabled = true1;
2044 } else if (streq(rvalue, "0")(strcmp((rvalue),("0")) == 0)) {
2045 log_syntax(unit, LOG_WARNING, filename, line, 0,({ int _level = (4), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD
) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level
, filename, line, _e, "../src/journal/journald-server.c", 2046
, __func__, "Compress= ambiguously specified as 0, disabling compression"
) : -abs(_e); })
2046 "Compress= ambiguously specified as 0, disabling compression")({ int _level = (4), _e = (0); (log_get_max_level_realm(LOG_REALM_SYSTEMD
) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level
, filename, line, _e, "../src/journal/journald-server.c", 2046
, __func__, "Compress= ambiguously specified as 0, disabling compression"
) : -abs(_e); })
;
2047 compress->enabled = false0;
2048 } else if ((r = parse_boolean(rvalue)) >= 0)
2049 compress->enabled = r;
2050 else if (parse_size(rvalue, 1024, &compress->threshold_bytes) == 0)
2051 compress->enabled = true1;
2052 else if (isempty(rvalue)) {
2053 compress->enabled = true1;
2054 compress->threshold_bytes = (uint64_t) -1;
2055 } else
2056 log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse Compress= value, ignoring: %s", rvalue)({ int _level = (3), _e = (r); (log_get_max_level_realm(LOG_REALM_SYSTEMD
) >= ((_level) & 0x07)) ? log_syntax_internal(unit, _level
, filename, line, _e, "../src/journal/journald-server.c", 2056
, __func__, "Failed to parse Compress= value, ignoring: %s", rvalue
) : -abs(_e); })
;
2057
2058 return 0;
2059}