• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 14630481637

23 Apr 2025 07:04PM UTC coverage: 72.178% (-0.002%) from 72.18%
14630481637

push

github

DaanDeMeyer
mkosi: Run clangd within the tools tree instead of the build container

Running within the build sandbox has a number of disadvantages:
- We have a separate clangd cache for each distribution/release combo
- It requires to build the full image before clangd can be used
- It breaks every time the image becomes out of date and requires a
  rebuild
- We can't look at system headers as we don't have the knowledge to map
  them from inside the build sandbox to the corresponding path on the host

Instead, let's have mkosi.clangd run clangd within the tools tree. We
already require building systemd for both the host and the target anyway,
and all the dependencies to build systemd are installed in the tools tree
already for that, as well as clangd since it's installed together with the
other clang tooling we install in the tools tree. Unlike the previous approach,
this approach only requires the mkosi tools tree to be built upfront, which has
a much higher chance of not invalidating its cache. We can also trivially map
system header lookups from within the sandbox to the path within mkosi.tools
on the host so that starts working as well.

297054 of 411557 relevant lines covered (72.18%)

686269.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/src/core/socket.h
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2
#pragma once
3

4
#include "pidref.h"
5
#include "socket-util.h"
6
#include "unit.h"
7

8
typedef struct Socket Socket;
9
typedef struct SocketPeer SocketPeer;
10

11
typedef enum SocketExecCommand {
12
        SOCKET_EXEC_START_PRE,
13
        SOCKET_EXEC_START_CHOWN,
14
        SOCKET_EXEC_START_POST,
15
        SOCKET_EXEC_STOP_PRE,
16
        SOCKET_EXEC_STOP_POST,
17
        _SOCKET_EXEC_COMMAND_MAX,
18
        _SOCKET_EXEC_COMMAND_INVALID = -EINVAL,
19
} SocketExecCommand;
20

21
typedef enum SocketType {
22
        SOCKET_SOCKET,
23
        SOCKET_FIFO,
24
        SOCKET_SPECIAL,
25
        SOCKET_MQUEUE,
26
        SOCKET_USB_FUNCTION,
27
        _SOCKET_TYPE_MAX,
28
        _SOCKET_TYPE_INVALID = -EINVAL,
29
} SocketType;
30

31
typedef enum SocketResult {
32
        SOCKET_SUCCESS,
33
        SOCKET_FAILURE_RESOURCES,
34
        SOCKET_FAILURE_TIMEOUT,
35
        SOCKET_FAILURE_EXIT_CODE,
36
        SOCKET_FAILURE_SIGNAL,
37
        SOCKET_FAILURE_CORE_DUMP,
38
        SOCKET_FAILURE_START_LIMIT_HIT,
39
        SOCKET_FAILURE_TRIGGER_LIMIT_HIT,
40
        SOCKET_FAILURE_SERVICE_START_LIMIT_HIT,
41
        _SOCKET_RESULT_MAX,
42
        _SOCKET_RESULT_INVALID = -EINVAL,
43
} SocketResult;
44

45
typedef struct SocketPort {
46
        Socket *socket;
47

48
        SocketType type;
49
        int fd;
50
        int *auxiliary_fds;
51
        size_t n_auxiliary_fds;
52

53
        SocketAddress address;
54
        char *path;
55
        sd_event_source *event_source;
56

57
        LIST_FIELDS(struct SocketPort, port);
58
} SocketPort;
59

60
typedef enum SocketTimestamping {
61
        SOCKET_TIMESTAMPING_OFF,
62
        SOCKET_TIMESTAMPING_US,  /* SO_TIMESTAMP */
63
        SOCKET_TIMESTAMPING_NS,  /* SO_TIMESTAMPNS */
64
        _SOCKET_TIMESTAMPING_MAX,
65
        _SOCKET_TIMESTAMPING_INVALID = -EINVAL,
66
} SocketTimestamping;
67

68
struct Socket {
69
        Unit meta;
70

71
        LIST_HEAD(SocketPort, ports);
72

73
        Set *peers_by_address;
74

75
        unsigned n_accepted;
76
        unsigned n_connections;
77
        unsigned n_refused;
78
        unsigned max_connections;
79
        unsigned max_connections_per_source;
80

81
        unsigned backlog;
82
        unsigned keep_alive_cnt;
83
        usec_t timeout_usec;
84
        usec_t keep_alive_time;
85
        usec_t keep_alive_interval;
86
        usec_t defer_accept;
87

88
        ExecCommand* exec_command[_SOCKET_EXEC_COMMAND_MAX];
89
        ExecContext exec_context;
90
        KillContext kill_context;
91
        CGroupContext cgroup_context;
92

93
        ExecRuntime *exec_runtime;
94
        CGroupRuntime *cgroup_runtime;
95

96
        /* For Accept=no sockets refers to the one service we'll
97
         * activate. For Accept=yes sockets is either NULL, or filled
98
         * to refer to the next service we spawn. */
99
        UnitRef service;
100

101
        SocketState state, deserialized_state;
102

103
        sd_event_source *timer_event_source;
104

105
        ExecCommand* control_command;
106
        SocketExecCommand control_command_id;
107
        PidRef control_pid;
108

109
        mode_t directory_mode;
110
        mode_t socket_mode;
111

112
        SocketResult result;
113
        SocketResult clean_result;
114

115
        char **symlinks;
116

117
        bool accept;
118
        bool remove_on_stop;
119
        bool writable;
120
        bool flush_pending;
121

122
        int socket_protocol;
123

124
        /* Socket options */
125
        bool keep_alive;
126
        bool no_delay;
127
        bool free_bind;
128
        bool transparent;
129
        bool broadcast;
130
        bool pass_cred;
131
        bool pass_fds_to_exec;
132
        bool pass_sec;
133
        bool pass_pktinfo;
134
        SocketTimestamping timestamping;
135

136
        /* Only for INET6 sockets: issue IPV6_V6ONLY sockopt */
137
        SocketAddressBindIPv6Only bind_ipv6_only;
138

139
        int priority;
140
        int mark;
141
        size_t receive_buffer;
142
        size_t send_buffer;
143
        int ip_tos;
144
        int ip_ttl;
145
        size_t pipe_size;
146
        char *bind_to_device;
147
        char *tcp_congestion;
148
        bool reuse_port;
149
        long mq_maxmsg;
150
        long mq_msgsize;
151

152
        char *smack;
153
        char *smack_ip_in;
154
        char *smack_ip_out;
155

156
        bool selinux_context_from_net;
157

158
        char *user, *group;
159

160
        char *fdname;
161

162
        RateLimit trigger_limit;
163
        RateLimit poll_limit;
164
};
165

166
SocketPeer *socket_peer_ref(SocketPeer *p);
167
SocketPeer *socket_peer_unref(SocketPeer *p);
168
int socket_acquire_peer(Socket *s, int fd, SocketPeer **p);
169

170
DEFINE_TRIVIAL_CLEANUP_FUNC(SocketPeer*, socket_peer_unref);
4✔
171

172
/* Called from the service code when collecting fds */
173
int socket_collect_fds(Socket *s, int **ret);
174

175
/* Called from the service code when a per-connection service ended */
176
void socket_connection_unref(Socket *s);
177

178
SocketPort* socket_port_free(SocketPort *p);
179
DEFINE_TRIVIAL_CLEANUP_FUNC(SocketPort*, socket_port_free);
×
180

181
void socket_free_ports(Socket *s);
182

183
int socket_port_to_address(const SocketPort *s, char **ret);
184

185
int socket_load_service_unit(Socket *s, int cfd, Unit **ret);
186

187
const char* socket_fdname(Socket *s);
188

189
extern const UnitVTable socket_vtable;
190

191
const char* socket_exec_command_to_string(SocketExecCommand i) _const_;
192
SocketExecCommand socket_exec_command_from_string(const char *s) _pure_;
193

194
const char* socket_result_to_string(SocketResult i) _const_;
195
SocketResult socket_result_from_string(const char *s) _pure_;
196

197
const char* socket_port_type_to_string(SocketPort *p) _pure_;
198
SocketType socket_port_type_from_string(const char *p) _pure_;
199

200
const char* socket_timestamping_to_string(SocketTimestamping p) _const_;
201
SocketTimestamping socket_timestamping_from_string(const char *p) _pure_;
202
SocketTimestamping socket_timestamping_from_string_harder(const char *p) _pure_;
203

204
DEFINE_CAST(SOCKET, Socket);
479,427✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc