1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3 
4 #include <inttypes.h>
5 #include <sys/socket.h>
6 #include <sys/types.h>
7 
8 #include "sd-id128.h"
9 
10 #include "time-util.h"
11 
12 typedef struct ClientContext ClientContext;
13 
14 #include "journald-server.h"
15 
16 struct ClientContext {
17         unsigned n_ref;
18         unsigned lru_index;
19         usec_t timestamp;
20         bool in_lru;
21 
22         pid_t pid;
23         uid_t uid;
24         gid_t gid;
25 
26         char *comm;
27         char *exe;
28         char *cmdline;
29         char *capeff;
30 
31         uint32_t auditid;
32         uid_t loginuid;
33 
34         char *cgroup;
35         char *session;
36         uid_t owner_uid;
37 
38         char *unit;
39         char *user_unit;
40 
41         char *slice;
42         char *user_slice;
43 
44         sd_id128_t invocation_id;
45 
46         char *label;
47         size_t label_size;
48 
49         int log_level_max;
50 
51         struct iovec *extra_fields_iovec;
52         size_t extra_fields_n_iovec;
53         void *extra_fields_data;
54         nsec_t extra_fields_mtime;
55 
56         usec_t log_ratelimit_interval;
57         unsigned log_ratelimit_burst;
58 };
59 
60 int client_context_get(
61                 Server *s,
62                 pid_t pid,
63                 const struct ucred *ucred,
64                 const char *label, size_t label_len,
65                 const char *unit_id,
66                 ClientContext **ret);
67 
68 int client_context_acquire(
69                 Server *s,
70                 pid_t pid,
71                 const struct ucred *ucred,
72                 const char *label, size_t label_len,
73                 const char *unit_id,
74                 ClientContext **ret);
75 
76 ClientContext* client_context_release(Server *s, ClientContext *c);
77 
78 void client_context_maybe_refresh(
79                 Server *s,
80                 ClientContext *c,
81                 const struct ucred *ucred,
82                 const char *label, size_t label_size,
83                 const char *unit_id,
84                 usec_t tstamp);
85 
86 void client_context_acquire_default(Server *s);
87 void client_context_flush_all(Server *s);
88 
client_context_extra_fields_n_iovec(const ClientContext * c)89 static inline size_t client_context_extra_fields_n_iovec(const ClientContext *c) {
90         return c ? c->extra_fields_n_iovec : 0;
91 }
92 
client_context_test_priority(const ClientContext * c,int priority)93 static inline bool client_context_test_priority(const ClientContext *c, int priority) {
94         if (!c)
95                 return true;
96 
97         if (c->log_level_max < 0)
98                 return true;
99 
100         return LOG_PRI(priority) <= c->log_level_max;
101 }
102