| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "common-signal.h" |
| 5 |
#include "journal-file.h" |
| 6 |
#include "journald-config.h" |
| 7 |
#include "journald-forward.h" |
| 8 |
#include "list.h" |
| 9 |
#include "ratelimit.h" |
| 10 |
|
| 11 |
typedef struct JournalStorageSpace { |
| 12 |
usec_t timestamp; |
| 13 |
|
| 14 |
uint64_t available; |
| 15 |
uint64_t limit; |
| 16 |
|
| 17 |
uint64_t vfs_used; /* space used by journal files */ |
| 18 |
uint64_t vfs_available; |
| 19 |
} JournalStorageSpace; |
| 20 |
|
| 21 |
typedef struct JournalStorage { |
| 22 |
const char *name; |
| 23 |
char *path; |
| 24 |
|
| 25 |
JournalMetrics metrics; |
| 26 |
JournalStorageSpace space; |
| 27 |
} JournalStorage; |
| 28 |
|
| 29 |
/* This structure will be kept in $RUNTIME_DIRECTORY/seqnum and is mapped by journald, and is used to |
| 30 |
* maintain the sequence number counter with its seqnum ID */ |
| 31 |
typedef struct SeqnumData { |
| 32 |
sd_id128_t id; |
| 33 |
uint64_t seqnum; |
| 34 |
} SeqnumData; |
| 35 |
|
| 36 |
typedef struct Manager { |
| 37 |
char *namespace; |
| 38 |
|
| 39 |
int syslog_fd; |
| 40 |
int native_fd; |
| 41 |
int stdout_fd; |
| 42 |
int dev_kmsg_fd; |
| 43 |
int audit_fd; |
| 44 |
int hostname_fd; |
| 45 |
int notify_fd; |
| 46 |
int forward_socket_fd; |
| 47 |
|
| 48 |
sd_event *event; |
| 49 |
|
| 50 |
sd_event_source *syslog_event_source; |
| 51 |
sd_event_source *native_event_source; |
| 52 |
sd_event_source *stdout_event_source; |
| 53 |
sd_event_source *dev_kmsg_event_source; |
| 54 |
sd_event_source *audit_event_source; |
| 55 |
sd_event_source *sync_event_source; |
| 56 |
sd_event_source *sigusr1_event_source; |
| 57 |
sd_event_source *sigusr2_event_source; |
| 58 |
sd_event_source *sigterm_event_source; |
| 59 |
sd_event_source *sigint_event_source; |
| 60 |
sd_event_source *sigrtmin1_event_source; |
| 61 |
sd_event_source *hostname_event_source; |
| 62 |
sd_event_source *notify_event_source; |
| 63 |
sd_event_source *watchdog_event_source; |
| 64 |
sd_event_source *idle_event_source; |
| 65 |
struct sigrtmin18_info sigrtmin18_info; |
| 66 |
|
| 67 |
JournalFile *runtime_journal; |
| 68 |
JournalFile *system_journal; |
| 69 |
OrderedHashmap *user_journals; |
| 70 |
|
| 71 |
SeqnumData *seqnum; |
| 72 |
|
| 73 |
char *buffer; |
| 74 |
|
| 75 |
OrderedHashmap *ratelimit_groups_by_id; |
| 76 |
|
| 77 |
JournalStorage runtime_storage; |
| 78 |
JournalStorage system_storage; |
| 79 |
|
| 80 |
bool send_watchdog; |
| 81 |
bool sent_notify_ready; |
| 82 |
bool sync_scheduled; |
| 83 |
|
| 84 |
unsigned n_forward_syslog_missed; |
| 85 |
usec_t last_warn_forward_syslog_missed; |
| 86 |
|
| 87 |
usec_t oldest_file_usec; |
| 88 |
|
| 89 |
LIST_HEAD(StdoutStream, stdout_streams); |
| 90 |
LIST_HEAD(StdoutStream, stdout_streams_notify_queue); |
| 91 |
unsigned n_stdout_streams; |
| 92 |
|
| 93 |
MMapCache *mmap; |
| 94 |
|
| 95 |
Set *deferred_closes; |
| 96 |
|
| 97 |
uint64_t *kernel_seqnum; |
| 98 |
RateLimit kmsg_own_ratelimit; |
| 99 |
|
| 100 |
char machine_id_field[STRLEN("_MACHINE_ID=") + SD_ID128_STRING_MAX]; |
| 101 |
char boot_id_field[STRLEN("_BOOT_ID=") + SD_ID128_STRING_MAX]; |
| 102 |
char *hostname_field; |
| 103 |
char *namespace_field; |
| 104 |
char *runtime_directory; |
| 105 |
|
| 106 |
/* Cached cgroup root, so that we don't have to query that all the time */ |
| 107 |
char *cgroup_root; |
| 108 |
|
| 109 |
usec_t watchdog_usec; |
| 110 |
|
| 111 |
usec_t last_realtime_clock; |
| 112 |
|
| 113 |
/* Caching of client metadata */ |
| 114 |
Hashmap *client_contexts; |
| 115 |
Prioq *client_contexts_lru; |
| 116 |
|
| 117 |
usec_t last_cache_pid_flush; |
| 118 |
|
| 119 |
ClientContext *my_context; /* the context of journald itself */ |
| 120 |
ClientContext *pid1_context; /* the context of PID 1 */ |
| 121 |
|
| 122 |
sd_varlink_server *varlink_server; |
| 123 |
|
| 124 |
/* timestamp of most recently processed log messages from each source (CLOCK_REALTIME for the first |
| 125 |
* two, CLOCK_BOOTTIME for the other) */ |
| 126 |
usec_t native_timestamp, syslog_timestamp, dev_kmsg_timestamp; |
| 127 |
|
| 128 |
/* Pending synchronization requests, ordered by their timestamp */ |
| 129 |
Prioq *sync_req_realtime_prioq; |
| 130 |
Prioq *sync_req_boottime_prioq; |
| 131 |
|
| 132 |
/* Pending synchronization requests with non-zero rqlen counter */ |
| 133 |
LIST_HEAD(SyncReq, sync_req_pending_rqlen); |
| 134 |
|
| 135 |
/* These structs are used to preserve configurations set by credentials and command line. |
| 136 |
* - config - main configuration used by journald manager, |
| 137 |
* - config_by_cred - configuration set by credentials, |
| 138 |
* - config_by_conf - configuration set by configuration file, |
| 139 |
* - config_by_cmdline - configuration set by command line. |
| 140 |
* The priority order of the sub-configurations is: |
| 141 |
* config_by_cmdline > config_by_conf > config_by_cred |
| 142 |
* where A > B means that if the two have the same setting, A's value overrides B's value for that |
| 143 |
* setting. */ |
| 144 |
JournalConfig config; |
| 145 |
JournalConfig config_by_cred; |
| 146 |
JournalConfig config_by_conf; |
| 147 |
JournalConfig config_by_cmdline; |
| 148 |
} Manager; |
| 149 |
|
| 150 |
#define MANAGER_MACHINE_ID(s) ((s)->machine_id_field + STRLEN("_MACHINE_ID=")) |
| 151 |
|
| 152 |
/* Extra fields for any log messages */ |
| 153 |
#define N_IOVEC_META_FIELDS 24 |
| 154 |
|
| 155 |
/* Extra fields for log messages that contain OBJECT_PID= (i.e. log about another process) */ |
| 156 |
#define N_IOVEC_OBJECT_FIELDS 18 |
| 157 |
|
| 158 |
/* Maximum number of fields we'll add in for driver (i.e. internal) messages */ |
| 159 |
#define N_IOVEC_PAYLOAD_FIELDS 16 |
| 160 |
|
| 161 |
/* kmsg: Maximum number of extra fields we'll import from the kernel's /dev/kmsg */ |
| 162 |
#define N_IOVEC_KERNEL_FIELDS 64 |
| 163 |
|
| 164 |
/* kmsg: Maximum number of extra fields we'll import from udev's devices */ |
| 165 |
#define N_IOVEC_UDEV_FIELDS 32 |
| 166 |
|
| 167 |
/* audit: Maximum number of extra fields we'll import from audit messages */ |
| 168 |
#define N_IOVEC_AUDIT_FIELDS 64 |
| 169 |
|
| 170 |
void manager_dispatch_message(Manager *m, struct iovec *iovec, size_t n, size_t mm, ClientContext *c, const struct timeval *tv, int priority, pid_t object_pid); |
| 171 |
void manager_driver_message_internal(Manager *m, pid_t object_pid, const char *format, ...) _sentinel_; |
| 172 |
#define manager_driver_message(...) manager_driver_message_internal(__VA_ARGS__, NULL) |
| 173 |
|
| 174 |
int manager_new(Manager **ret); |
| 175 |
int manager_set_namespace(Manager *m, const char *namespace); |
| 176 |
int manager_init(Manager *m); |
| 177 |
Manager* manager_free(Manager *m); |
| 178 |
DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free); |
| 179 |
void manager_full_sync(Manager *m, bool wait); |
| 180 |
void manager_vacuum(Manager *m, bool verbose); |
| 181 |
void manager_rotate(Manager *m); |
| 182 |
void manager_full_rotate(Manager *m); |
| 183 |
int manager_flush_to_var(Manager *m, bool require_flag_file); |
| 184 |
void manager_full_flush(Manager *m); |
| 185 |
int manager_relinquish_var(Manager *m); |
| 186 |
void manager_maybe_append_tags(Manager *m); |
| 187 |
int manager_process_datagram(sd_event_source *es, int fd, uint32_t revents, void *userdata); |
| 188 |
void manager_space_usage_message(Manager *m, JournalStorage *storage); |
| 189 |
|
| 190 |
int manager_start_or_stop_idle_timer(Manager *m); |
| 191 |
void manager_reopen_journals(Manager *m, const JournalConfig *old); |
| 192 |
|
| 193 |
int manager_map_seqnum_file(Manager *m, const char *fname, size_t size, void **ret); |
| 194 |
void manager_unmap_seqnum_file(void *p, size_t size); |
| 195 |
int manager_unlink_seqnum_file(Manager *m, const char *fname); |