Debian Codegraph @

src/kore.c

raw symbols SCIP
1 /*
2 * Copyright (c) 2013-2022 Joris Vink <[email protected]>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 #include <sys/un.h>
20
21 #include <sys/socket.h>
22 #include <sys/resource.h>
23
24 #include <libgen.h>
25 #include <fcntl.h>
26 #include <stdio.h>
27 #include <netdb.h>
28 #include <signal.h>
29
30 #include "kore.h"cxx . . $ `<file>/include/kore/kore.h`/
31 #include "hooks.h"cxx . . $ `<file>/include/kore/hooks.h`/
32
33 #if !defined(KORE_NO_HTTP)
34 #include "http.h"cxx . . $ `<file>/include/kore/http.h`/
35 #endif
36
37 #if defined(KORE_USE_CURL)
38 #include "curl.h"
39 #endif
40
41 #if defined(KORE_USE_PGSQL)
42 #include "pgsql.h"
43 #endif
44
45 #if defined(KORE_USE_PYTHON)
46 #include "python_api.h"
47 #endif
48
49 #if defined(KORE_USE_ACME)
50 #include "acme.h"
51 #endif
52
53 volatile sig_atomic_tcxx . . $ sig_atomic_t# sig_recvcxx . . $ sig_recv.;
54 struct kore_server_listcxx . . $ kore_server_list# kore_serverscxx . . $ kore_servers.;
55 u_int8_tcxx . . $ u_int8_t# nlistenerscxx . . $ nlisteners.;
56 int kore_argccxx . . $ kore_argc. = 0;
57 pid_tcxx . . $ pid_t# kore_pidcxx . . $ kore_pid. = -1;
58 u_int16_tcxx . . $ u_int16_t# cpu_countcxx . . $ cpu_count. = 1;
59 int kore_quietcxx . . $ kore_quiet. = 0;
60 int skip_runascxx . . $ skip_runas. = 0;
61 int skip_chrootcxx . . $ skip_chroot. = 0;
62 u_int8_tcxx . . $ u_int8_t# worker_countcxx . . $ worker_count. = 0;
63 char **kore_argvcxx . . $ kore_argv. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
64 int kore_foregroundcxx . . $ kore_foreground. = 0;
65 char *kore_prognamecxx . . $ kore_progname. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
66 u_int32_tcxx . . $ u_int32_t# kore_socket_backlogcxx . . $ kore_socket_backlog. = 5000;
67 int kore_quitcxx . . $ kore_quit. = KORE_QUIT_NONEcxx . . $ `include/kore/kore.h:83:9`!;
68 char *kore_pidfilecxx . . $ kore_pidfile. = KORE_PIDFILE_DEFAULTcxx . . $ `include/kore/kore.h:103:9`!;
69
70 struct kore_privsepcxx . . $ kore_privsep# worker_privsepcxx . . $ worker_privsep.;
71
72 extern char **environcxx . . $ environ.;
73 extern char *__prognamecxx . . $ __progname.;
74 static size_t proctitle_maxlencxx . . $ proctitle_maxlen. = 0;
75
76 static void usagecxx . . $ usage(49f6e7a06ebc5aa8).(void);
77 static void versioncxx . . $ version(49f6e7a06ebc5aa8).(void);
78
79 static void kore_write_kore_pidcxx . . $ kore_write_kore_pid(49f6e7a06ebc5aa8).(void);
80 static void kore_proctitle_setupcxx . . $ kore_proctitle_setup(49f6e7a06ebc5aa8).(void);
81 static void kore_server_shutdowncxx . . $ kore_server_shutdown(49f6e7a06ebc5aa8).(void);
82 static void kore_server_startcxx . . $ kore_server_start(c759356ac01a31e7).(int, char *[]);
83 static void kore_call_parent_configurecxx . . $ kore_call_parent_configure(c759356ac01a31e7).(int, char **);
84
85 #if !defined(KORE_SINGLE_BINARY) && defined(KORE_USE_PYTHON)
86 static const char *parent_config_hook = KORE_PYTHON_CONFIG_HOOK;
87 static const char *parent_teardown_hook = KORE_PYTHON_TEARDOWN_HOOK;
88 #else
89 static const char *parent_config_hookcxx . . $ parent_config_hook. = KORE_CONFIG_HOOKcxx . . $ `include/kore/hooks.h:20:9`!;
90 static const char *parent_teardown_hookcxx . . $ parent_teardown_hook. = KORE_TEARDOWN_HOOKcxx . . $ `include/kore/hooks.h:21:9`!;
91 #if defined(KORE_SINGLE_BINARY)
92 static const char *parent_daemonized_hook = KORE_DAEMONIZED_HOOK;
93 #endif
94 #endif
95
96 static void
97 usagecxx . . $ usage(49f6e7a06ebc5aa8).(void)
98 {
99 #if defined(KORE_USE_PYTHON)
100 printf("Usage: %s [options] [app | app.py]\n", __progname);
101 #else
102 printfcxx . . $ printf(581fddd72a8db8fc).("Usage: %s [options]\n", __prognamecxx . . $ __progname.);
103 #endif
104
105 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
106 printfcxx . . $ printf(581fddd72a8db8fc).("Available options:\n");
107 #if !defined(KORE_SINGLE_BINARY)
108 printfcxx . . $ printf(581fddd72a8db8fc).("\t-c\tconfiguration to use\n");
109 #endif
110 #if defined(KORE_DEBUG)
111 printf("\t-d\trun with debug on\n");
112 #endif
113 printfcxx . . $ printf(581fddd72a8db8fc).("\t-f\tstart in foreground\n");
114 printfcxx . . $ printf(581fddd72a8db8fc).("\t-h\tthis help text\n");
115 printfcxx . . $ printf(581fddd72a8db8fc).("\t-n\tdo not chroot on any worker\n");
116 printfcxx . . $ printf(581fddd72a8db8fc).("\t-q\tonly log errors\n");
117 printfcxx . . $ printf(581fddd72a8db8fc).("\t-r\tdo not change user on any worker\n");
118 printfcxx . . $ printf(581fddd72a8db8fc).("\t-v\tdisplay %s build information\n", __prognamecxx . . $ __progname.);
119
120 printfcxx . . $ printf(581fddd72a8db8fc).("\nFind more information on https://kore.io\n");
121
122 exitcxx . . $ exit(3ca292c338df9bb3).(1);
123 }
124
125 static void
126 versioncxx . . $ version(49f6e7a06ebc5aa8).(void)
127 {
128 printfcxx . . $ printf(581fddd72a8db8fc).("%s ", kore_versioncxx . . $ kore_version.);
129 #if defined(KORE_NO_HTTP)
130 printf("no-http ");
131 #endif
132 #if defined(KORE_USE_CURL)
133 printf("curl-%s ", LIBCURL_VERSION);
134 #endif
135 #if defined(KORE_USE_PGSQL)
136 printf("pgsql ");
137 #endif
138 #if defined(KORE_USE_TASKS)
139 printf("tasks ");
140 #endif
141 #if defined(KORE_DEBUG)
142 printf("debug ");
143 #endif
144 #if defined(KORE_USE_PYTHON)
145 printf("python-%s ", PY_VERSION);
146 #endif
147 #if defined(KORE_USE_ACME)
148 printf("acme ");
149 #endif
150 if (!kore_tls_supportedcxx . . $ kore_tls_supported(b126dc7c1de90089).())
151 printfcxx . . $ printf(581fddd72a8db8fc).("notls ");
152 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
153 exitcxx . . $ exit(3ca292c338df9bb3).(0);
154 }
155
156 int
157 maincxx . . $ main(afcd3168fc1188a4).(int argc, char *argv[])
158 {
159 struct kore_runtime_callcxx . . $ kore_runtime_call# *rcall;
160 #if !defined(KORE_SINGLE_BINARY) && defined(KORE_USE_PYTHON)
161 struct stat st;
162 #endif
163
164 kore_argccxx . . $ kore_argc. = argc;
165 kore_argvcxx . . $ kore_argv. = argv;
166
167 #if !defined(KORE_SINGLE_BINARY)
168 kore_default_getoptcxx . . $ kore_default_getopt(c759356ac01a31e7).(argc, argv);
169 #endif
170
171 kore_mem_initcxx . . $ kore_mem_init(49f6e7a06ebc5aa8).();
172 kore_msg_initcxx . . $ kore_msg_init(49f6e7a06ebc5aa8).();
173 kore_log_initcxx . . $ kore_log_init(49f6e7a06ebc5aa8).();
174
175 kore_prognamecxx . . $ kore_progname. = kore_strdupcxx . . $ kore_strdup(a8b8e32347182212).(argv[0]);
176 kore_proctitle_setupcxx . . $ kore_proctitle_setup(49f6e7a06ebc5aa8).();
177
178 #if !defined(KORE_SINGLE_BINARY)
179 argc -= optindcxx . . $ optind.;
180 argv += optindcxx . . $ optind.;
181 #endif
182
183 #if !defined(KORE_SINGLE_BINARY) && defined(KORE_USE_PYTHON)
184 if (argc > 0) {
185 kore_pymodule = argv[0];
186 argc--;
187 argv++;
188 } else {
189 kore_pymodule = NULL;
190 }
191
192 if (kore_pymodule) {
193 if (lstat(kore_pymodule, &st) == -1) {
194 fatal("failed to stat '%s': %s",
195 kore_pymodule, errno_s);
196 }
197
198 if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode))
199 fatal("%s: not a directory or file", kore_pymodule);
200 }
201 #endif
202
203 kore_pidcxx . . $ kore_pid. = getpidcxx . . $ getpid(b126dc7c1de90089).();
204 nlistenerscxx . . $ nlisteners. = 0;
205 LIST_INITcxx . . $ `<external>/2546723208511035544/queue.h:101:9`!(&kore_servers);
206
207 kore_platform_initcxx . . $ kore_platform_init(49f6e7a06ebc5aa8).();
208 #if !defined(KORE_NO_HTTP)
209 http_parent_initcxx . . $ http_parent_init(49f6e7a06ebc5aa8).();
210 #if defined(KORE_USE_CURL)
211 kore_curl_sysinit();
212 #endif
213 #if defined(KORE_USE_PGSQL)
214 kore_pgsql_sys_init();
215 #endif
216 kore_auth_initcxx . . $ kore_auth_init(49f6e7a06ebc5aa8).();
217 kore_validator_initcxx . . $ kore_validator_init(49f6e7a06ebc5aa8).();
218 kore_filemap_initcxx . . $ kore_filemap_init(49f6e7a06ebc5aa8).();
219 #endif
220 #if defined(KORE_USE_ACME)
221 kore_acme_init();
222 #endif
223 kore_domain_initcxx . . $ kore_domain_init(49f6e7a06ebc5aa8).();
224 kore_module_initcxx . . $ kore_module_init(49f6e7a06ebc5aa8).();
225 kore_tls_initcxx . . $ kore_tls_init(49f6e7a06ebc5aa8).();
226
227 #if !defined(KORE_SINGLE_BINARY) && !defined(KORE_USE_PYTHON)
228 if (config_filecxx . . $ config_file. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
229 usagecxx . . $ usage(49f6e7a06ebc5aa8).();
230 #endif
231 kore_module_loadcxx . . $ kore_module_load(4ae48391f6be8edd).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, KORE_MODULE_NATIVEcxx . . $ `include/kore/kore.h:414:9`!);
232
233 #if defined(KORE_USE_PYTHON)
234 kore_python_init();
235 #if !defined(KORE_SINGLE_BINARY)
236 if (kore_pymodule) {
237 kore_module_load(kore_pymodule, NULL, KORE_MODULE_PYTHON);
238 if (S_ISDIR(st.st_mode) && chdir(kore_pymodule) == -1)
239 fatal("chdir(%s): %s", kore_pymodule, errno_s);
240 } else {
241 /* swap back to non-python hooks. */
242 parent_config_hook = KORE_CONFIG_HOOK;
243 parent_teardown_hook = KORE_TEARDOWN_HOOK;
244 }
245 #endif
246 #endif
247
248 #if defined(KORE_SINGLE_BINARY)
249 kore_call_parent_configure(argc, argv);
250 #endif
251
252 #if defined(KORE_USE_PYTHON) && !defined(KORE_SINGLE_BINARY)
253 if (kore_pymodule)
254 kore_call_parent_configure(argc, argv);
255 #endif
256
257 kore_parse_configcxx . . $ kore_parse_config(49f6e7a06ebc5aa8).();
258
259 #if !defined(KORE_SINGLE_BINARY)
260 freecxx . . $ free(5d22bdacc48458e8).(config_filecxx . . $ config_file.);
261 #endif
262
263 #if !defined(KORE_NO_HTTP)
264 if (http_body_disk_offloadcxx . . $ http_body_disk_offload. > 0) {
265 if (mkdircxx . . $ mkdir(1df18506ef0a631b).(http_body_disk_pathcxx . . $ http_body_disk_path., 0700) == -1 && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != EEXISTcxx . . $ `<external>/8987895939074593727/errno-base.h:21:9`!) {
266 printfcxx . . $ printf(581fddd72a8db8fc).("can't create http_body_disk_path '%s': %s\n",
267 http_body_disk_pathcxx . . $ http_body_disk_path., errno_scxx . . $ `include/kore/kore.h:100:9`!);
268 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
269 }
270 }
271 #endif
272
273 kore_signal_setupcxx . . $ kore_signal_setup(49f6e7a06ebc5aa8).();
274 kore_server_startcxx . . $ kore_server_start(c759356ac01a31e7).(argc, argv);
275 kore_server_shutdowncxx . . $ kore_server_shutdown(49f6e7a06ebc5aa8).();
276
277 rcall = kore_runtime_getcallcxx . . $ kore_runtime_getcall(b514b5951ac4d62f).(parent_teardown_hookcxx . . $ parent_teardown_hook.);
278 if (rcall != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
279 kore_runtime_executecxx . . $ kore_runtime_execute(5bf3e738821b3e09).(rcall);
280 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(rcall);
281 }
282
283 if (unlinkcxx . . $ unlink(5c4306d8553b3696).(kore_pidfilecxx . . $ kore_pidfile.) == -1 && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!)
284 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_NOTICEcxx . . $ `<external>/6168640806541382331/syslog.h:56:9`!, "failed to remove pidfile (%s)", errno_scxx . . $ `include/kore/kore.h:100:9`!);
285
286 kore_server_cleanupcxx . . $ kore_server_cleanup(49f6e7a06ebc5aa8).();
287
288 if (!kore_quietcxx . . $ kore_quiet.)
289 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_INFOcxx . . $ `<external>/6168640806541382331/syslog.h:57:9`!, "goodbye");
290
291 #if defined(KORE_USE_PYTHON)
292 kore_python_cleanup();
293 #endif
294
295 kore_mem_cleanupcxx . . $ kore_mem_cleanup(49f6e7a06ebc5aa8).();
296
297 return (kore_quitcxx . . $ kore_quit.);
298 }
299
300 void
301 kore_default_getoptcxx . . $ kore_default_getopt(c759356ac01a31e7).(int argc, char **argv)
302 {
303 int ch;
304
305 #if !defined(KORE_SINGLE_BINARY)
306 while ((ch = getoptcxx . . $ getopt(2483c31ff9bab884).(argc, argv, "c:fhnqrv")) != -1) {
307 #else
308 while ((ch = getopt(argc, argv, "fhnqrv")) != -1) {
309 #endif
310 switch (ch) {
311 #if !defined(KORE_SINGLE_BINARY)
312 case 'c':
313 freecxx . . $ free(5d22bdacc48458e8).(config_filecxx . . $ config_file.);
314 if ((config_filecxx . . $ config_file. = strdupcxx . . $ strdup(a8b8e32347182212).(optargcxx . . $ optarg.)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
315 fatalcxx . . $ fatal(f6bc48f0426f26ee).("strdup");
316 break;
317 #endif
318 case 'f':
319 kore_foregroundcxx . . $ kore_foreground. = 1;
320 break;
321 case 'h':
322 usagecxx . . $ usage(49f6e7a06ebc5aa8).();
323 break;
324 case 'n':
325 skip_chrootcxx . . $ skip_chroot. = 1;
326 break;
327 case 'q':
328 kore_quietcxx . . $ kore_quiet. = 1;
329 break;
330 case 'r':
331 skip_runascxx . . $ skip_runas. = 1;
332 break;
333 case 'v':
334 versioncxx . . $ version(49f6e7a06ebc5aa8).();
335 break;
336 default:
337 usagecxx . . $ usage(49f6e7a06ebc5aa8).();
338 }
339 }
340 }
341
342 int
343 kore_server_bindcxx . . $ kore_server_bind(e1ce76104f8352de).(struct kore_servercxx . . $ kore_server# *srv, const char *ip, const char *port,
344 const char *ccb)
345 {
346 int r;
347 struct listenercxx . . $ listener# *l;
348 struct addrinfocxx . . $ addrinfo# hints, *results;
349
350 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&hints, 0, sizeof(hints));
351 hints.ai_familycxx . . $ addrinfo#ai_family. = AF_UNSPECcxx . . $ `<external>/8962547315054503424/socket.h:93:9`!;
352 hints.ai_socktypecxx . . $ addrinfo#ai_socktype. = SOCK_STREAMcxx . . $ `<external>/5956532346368192945/socket_type.h:28:9`!;
353 hints.ai_protocolcxx . . $ addrinfo#ai_protocol. = IPPROTO_TCPcxx . . $ `<external>/9581057695539925927/in.h:51:9`!;
354 hints.ai_flagscxx . . $ addrinfo#ai_flags. = 0;
355
356 r = getaddrinfocxx . . $ getaddrinfo(f68af21b9849b03e).(ip, port, &hints, &results);
357 if (r != 0)
358 fatalcxx . . $ fatal(f6bc48f0426f26ee).("getaddrinfo(%s): %s", ip, gai_strerrorcxx . . $ gai_strerror(f7ae7e56280f18ae).(r));
359
360 l = kore_listener_createcxx . . $ kore_listener_create(78075dd3fe10c870).(srv);
361 l->hostcxx . . $ listener#host. = kore_strdupcxx . . $ kore_strdup(a8b8e32347182212).(ip);
362 l->portcxx . . $ listener#port. = kore_strdupcxx . . $ kore_strdup(a8b8e32347182212).(port);
363
364 if (!kore_listener_initcxx . . $ kore_listener_init(1bef54e34d9f2d1).(l, results->ai_familycxx . . $ addrinfo#ai_family., ccb)) {
365 freeaddrinfocxx . . $ freeaddrinfo(aadc8f19092a28e8).(results);
366 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
367 }
368
369 if (bindcxx . . $ bind(f39c6c650450bfdd).(l->fdcxx . . $ listener#fd., results->ai_addrcxx . . $ addrinfo#ai_addr., results->ai_addrlencxx . . $ addrinfo#ai_addrlen.) == -1) {
370 kore_listener_freecxx . . $ kore_listener_free(e090ef26bfa338f2).(l);
371 freeaddrinfocxx . . $ freeaddrinfo(aadc8f19092a28e8).(results);
372 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_ERRcxx . . $ `<external>/6168640806541382331/syslog.h:54:9`!, "bind(): %s", errno_scxx . . $ `include/kore/kore.h:100:9`!);
373 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
374 }
375
376 freeaddrinfocxx . . $ freeaddrinfo(aadc8f19092a28e8).(results);
377
378 if (listencxx . . $ listen(9b79fb6aee4c0440).(l->fdcxx . . $ listener#fd., kore_socket_backlogcxx . . $ kore_socket_backlog.) == -1) {
379 kore_listener_freecxx . . $ kore_listener_free(e090ef26bfa338f2).(l);
380 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_ERRcxx . . $ `<external>/6168640806541382331/syslog.h:54:9`!, "listen(): %s", errno_scxx . . $ `include/kore/kore.h:100:9`!);
381 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
382 }
383
384 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
385 }
386
387 int
388 kore_server_bind_unixcxx . . $ kore_server_bind_unix(165cfefc442a175c).(struct kore_servercxx . . $ kore_server# *srv, const char *path,
389 const char *ccb)
390 {
391 struct listenercxx . . $ listener# *l;
392 int len;
393 struct sockaddr_uncxx . . $ sockaddr_un# sun;
394 socklen_tcxx . . $ socklen_t# socklen;
395
396 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&sun, 0, sizeof(sun));
397 sun.sun_familycxx . . $ sockaddr_un#sun_family. = AF_UNIXcxx . . $ `<external>/8962547315054503424/socket.h:95:9`!;
398
399 len = snprintfcxx . . $ snprintf(ea502d73e74c754c).(sun.sun_pathcxx . . $ sockaddr_un#sun_path., sizeof(sun.sun_pathcxx . . $ sockaddr_un#sun_path.), "%s", path);
400 if (len == -1 || (size_t)len >= sizeof(sun.sun_pathcxx . . $ sockaddr_un#sun_path.)) {
401 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_ERRcxx . . $ `<external>/6168640806541382331/syslog.h:54:9`!, "unix socket path '%s' too long", path);
402 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
403 }
404
405 #if defined(__linux__cxx . . $ `<built-in>:401:9`!)
406 if (sun.sun_pathcxx . . $ sockaddr_un#sun_path.[0] == '@')
407 sun.sun_pathcxx . . $ sockaddr_un#sun_path.[0] = '\0';
408 socklen = sizeof(sun.sun_familycxx . . $ sockaddr_un#sun_family.) + len;
409 #else
410 socklen = sizeof(sun);
411 #endif
412
413 l = kore_listener_createcxx . . $ kore_listener_create(78075dd3fe10c870).(srv);
414 l->hostcxx . . $ listener#host. = kore_strdupcxx . . $ kore_strdup(a8b8e32347182212).(path);
415
416 if (!kore_listener_initcxx . . $ kore_listener_init(1bef54e34d9f2d1).(l, AF_UNIXcxx . . $ `<external>/8962547315054503424/socket.h:95:9`!, ccb))
417 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
418
419 if (sun.sun_pathcxx . . $ sockaddr_un#sun_path.[0] != '\0') {
420 if (unlinkcxx . . $ unlink(5c4306d8553b3696).(sun.sun_pathcxx . . $ sockaddr_un#sun_path.) == -1 && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!) {
421 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_ERRcxx . . $ `<external>/6168640806541382331/syslog.h:54:9`!, "unlink: %s: %s",
422 sun.sun_pathcxx . . $ sockaddr_un#sun_path., errno_scxx . . $ `include/kore/kore.h:100:9`!);
423 kore_listener_freecxx . . $ kore_listener_free(e090ef26bfa338f2).(l);
424 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
425 }
426 }
427
428 if (bindcxx . . $ bind(f39c6c650450bfdd).(l->fdcxx . . $ listener#fd., (struct sockaddrcxx . . $ sockaddr# *)&sun, socklen) == -1) {
429 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_ERRcxx . . $ `<external>/6168640806541382331/syslog.h:54:9`!, "bind: %s", errno_scxx . . $ `include/kore/kore.h:100:9`!);
430 kore_listener_freecxx . . $ kore_listener_free(e090ef26bfa338f2).(l);
431 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
432 }
433
434 if (listencxx . . $ listen(9b79fb6aee4c0440).(l->fdcxx . . $ listener#fd., kore_socket_backlogcxx . . $ kore_socket_backlog.) == -1) {
435 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_ERRcxx . . $ `<external>/6168640806541382331/syslog.h:54:9`!, "listen(): %s", errno_scxx . . $ `include/kore/kore.h:100:9`!);
436 kore_listener_freecxx . . $ kore_listener_free(e090ef26bfa338f2).(l);
437 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
438 }
439
440 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
441 }
442
443 struct kore_servercxx . . $ kore_server# *
444 kore_server_createcxx . . $ kore_server_create(f2716011ff67f403).(const char *name)
445 {
446 struct kore_servercxx . . $ kore_server# *srv;
447
448 srv = kore_calloccxx . . $ kore_calloc(63a7bf2941bfcd7a).(1, sizeof(struct kore_servercxx . . $ kore_server#));
449 srv->namecxx . . $ kore_server#name. = kore_strdupcxx . . $ kore_strdup(a8b8e32347182212).(name);
450
451 if (kore_tls_supportedcxx . . $ kore_tls_supported(b126dc7c1de90089).())
452 srv->tlscxx . . $ kore_server#tls. = 1;
453 else
454 srv->tlscxx . . $ kore_server#tls. = 0;
455
456 TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&srv->domains);
457 LIST_INITcxx . . $ `<external>/2546723208511035544/queue.h:101:9`!(&srv->listeners);
458
459 LIST_INSERT_HEADcxx . . $ `<external>/2546723208511035544/queue.h:120:9`!(&kore_servers, srv, list);
460
461 return (srv);
462 }
463
464 void
465 kore_server_finalizecxx . . $ kore_server_finalize(ef2fe6a8435a3580).(struct kore_servercxx . . $ kore_server# *srv)
466 {
467 struct listenercxx . . $ listener# *l;
468 const char *proto;
469
470 if (kore_quietcxx . . $ kore_quiet.)
471 return;
472
473 LIST_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:134:9`!(l, &srv->listeners, list) {
474 if (srv->tlscxx . . $ kore_server#tls.)
475 proto = "https";
476 else
477 proto = "http";
478
479 if (l->familycxx . . $ listener#family. == AF_UNIXcxx . . $ `<external>/8962547315054503424/socket.h:95:9`!) {
480 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_INFOcxx . . $ `<external>/6168640806541382331/syslog.h:57:9`!, "%s serving %s on %s",
481 srv->namecxx . . $ kore_server#name., proto, l->hostcxx . . $ listener#host.);
482 } else {
483 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_INFOcxx . . $ `<external>/6168640806541382331/syslog.h:57:9`!, "%s serving %s on %s:%s",
484 srv->namecxx . . $ kore_server#name., proto, l->hostcxx . . $ listener#host., l->portcxx . . $ listener#port.);
485 }
486 }
487 }
488
489 struct listenercxx . . $ listener# *
490 kore_listener_createcxx . . $ kore_listener_create(78075dd3fe10c870).(struct kore_servercxx . . $ kore_server# *server)
491 {
492 struct listenercxx . . $ listener# *l;
493
494 l = kore_calloccxx . . $ kore_calloc(63a7bf2941bfcd7a).(1, sizeof(struct listenercxx . . $ listener#));
495
496 nlistenerscxx . . $ nlisteners.++;
497 LIST_INSERT_HEADcxx . . $ `<external>/2546723208511035544/queue.h:120:9`!(&server->listeners, l, list);
498
499 l->servercxx . . $ listener#server. = server;
500
501 l->fdcxx . . $ listener#fd. = -1;
502 l->evtcxx . . $ listener#evt..typecxx . . $ kore_event#type. = KORE_TYPE_LISTENERcxx . . $ `include/kore/kore.h:169:9`!;
503 l->evtcxx . . $ listener#evt..handlecxx . . $ kore_event#handle. = kore_listener_acceptcxx . . $ kore_listener_accept(d0320739773070f2).;
504
505 return (l);
506 }
507
508 struct kore_servercxx . . $ kore_server# *
509 kore_server_lookupcxx . . $ kore_server_lookup(f2716011ff67f403).(const char *name)
510 {
511 struct kore_servercxx . . $ kore_server# *srv;
512
513 LIST_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:134:9`!(srv, &kore_servers, list) {
514 if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(srv->namecxx . . $ kore_server#name., name))
515 return (srv);
516 }
517
518 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
519 }
520
521 int
522 kore_listener_initcxx . . $ kore_listener_init(1bef54e34d9f2d1).(struct listenercxx . . $ listener# *l, int family, const char *ccb)
523 {
524 switch (family) {
525 case AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!:
526 case AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!:
527 case AF_UNIXcxx . . $ `<external>/8962547315054503424/socket.h:95:9`!:
528 break;
529 default:
530 fatalcxx . . $ fatal(f6bc48f0426f26ee).("unknown address family %d", family);
531 }
532
533 l->familycxx . . $ listener#family. = family;
534
535 if ((l->fdcxx . . $ listener#fd. = socketcxx . . $ socket(2326284602b0bb2d).(family, SOCK_STREAMcxx . . $ `<external>/5956532346368192945/socket_type.h:28:9`!, 0)) == -1) {
536 kore_listener_freecxx . . $ kore_listener_free(e090ef26bfa338f2).(l);
537 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_ERRcxx . . $ `<external>/6168640806541382331/syslog.h:54:9`!, "socket(): %s", errno_scxx . . $ `include/kore/kore.h:100:9`!);
538 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
539 }
540
541 if (fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(l->fdcxx . . $ listener#fd., F_SETFDcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:167:9`!, FD_CLOEXECcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:219:9`!) == -1) {
542 kore_listener_freecxx . . $ kore_listener_free(e090ef26bfa338f2).(l);
543 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_ERRcxx . . $ `<external>/6168640806541382331/syslog.h:54:9`!, "fcntl(): %s", errno_scxx . . $ `include/kore/kore.h:100:9`!);
544 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
545 }
546
547 if (!kore_connection_nonblockcxx . . $ kore_connection_nonblock(9b79fb6aee4c0440).(l->fdcxx . . $ listener#fd., family != AF_UNIXcxx . . $ `<external>/8962547315054503424/socket.h:95:9`!)) {
548 kore_listener_freecxx . . $ kore_listener_free(e090ef26bfa338f2).(l);
549 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_ERRcxx . . $ `<external>/6168640806541382331/syslog.h:54:9`!, "kore_connection_nonblock(): %s", errno_scxx . . $ `include/kore/kore.h:100:9`!);
550 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
551 }
552
553 if (!kore_sockoptcxx . . $ kore_sockopt(2326284602b0bb2d).(l->fdcxx . . $ listener#fd., SOL_SOCKETcxx . . $ `<external>/9030916627833342711/socket.h:9:9`!, SO_REUSEADDRcxx . . $ `<external>/9030916627833342711/socket.h:12:9`!)) {
554 kore_listener_freecxx . . $ kore_listener_free(e090ef26bfa338f2).(l);
555 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
556 }
557
558 if (ccb != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
559 if ((l->connectcxx . . $ listener#connect. = kore_runtime_getcallcxx . . $ kore_runtime_getcall(b514b5951ac4d62f).(ccb)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
560 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_ERRcxx . . $ `<external>/6168640806541382331/syslog.h:54:9`!, "no such callback: '%s'", ccb);
561 kore_listener_freecxx . . $ kore_listener_free(e090ef26bfa338f2).(l);
562 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
563 }
564 } else {
565 l->connectcxx . . $ listener#connect. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
566 }
567
568 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
569 }
570
571 void
572 kore_server_freecxx . . $ kore_server_free(ef2fe6a8435a3580).(struct kore_servercxx . . $ kore_server# *srv)
573 {
574 struct listenercxx . . $ listener# *l;
575 struct kore_domaincxx . . $ kore_domain# *dom;
576
577 LIST_REMOVEcxx . . $ `<external>/2546723208511035544/queue.h:127:9`!(srv, list);
578
579 while ((dom = TAILQ_FIRSTcxx . . $ `<external>/2546723208511035544/queue.h:458:9`!(&srv->domains)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
580 kore_domain_freecxx . . $ kore_domain_free(be08e46f67814b96).(dom);
581
582 while ((l = LIST_FIRSTcxx . . $ `<external>/2546723208511035544/queue.h:143:9`!(&srv->listeners)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
583 kore_listener_freecxx . . $ kore_listener_free(e090ef26bfa338f2).(l);
584
585 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(srv->namecxx . . $ kore_server#name.);
586 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(srv);
587 }
588
589 void
590 kore_listener_freecxx . . $ kore_listener_free(e090ef26bfa338f2).(struct listenercxx . . $ listener# *l)
591 {
592 int rm;
593
594 LIST_REMOVEcxx . . $ `<external>/2546723208511035544/queue.h:127:9`!(l, list);
595
596 if (l->fdcxx . . $ listener#fd. != -1)
597 closecxx . . $ close(7864480464b09eea).(l->fdcxx . . $ listener#fd.);
598
599 rm = 0;
600
601 #if defined(__linux__cxx . . $ `<built-in>:401:9`!)
602 if (workercxx . . $ worker. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && l->familycxx . . $ listener#family. == AF_UNIXcxx . . $ `<external>/8962547315054503424/socket.h:95:9`! && l->hostcxx . . $ listener#host.[0] != '@')
603 rm++;
604 #else
605 if (worker == NULL && l->family == AF_UNIX)
606 rm++;
607 #endif
608 if (rm) {
609 if (unlinkcxx . . $ unlink(5c4306d8553b3696).(l->hostcxx . . $ listener#host.) == -1) {
610 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_NOTICEcxx . . $ `<external>/6168640806541382331/syslog.h:56:9`!,
611 "failed to remove unix socket %s (%s)", l->hostcxx . . $ listener#host.,
612 errno_scxx . . $ `include/kore/kore.h:100:9`!);
613 }
614 }
615
616 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(l->hostcxx . . $ listener#host.);
617 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(l->portcxx . . $ listener#port.);
618
619 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(l);
620 }
621
622 void
623 kore_listener_acceptcxx . . $ kore_listener_accept(d0320739773070f2).(void *arg, int error)
624 {
625 struct connectioncxx . . $ connection# *c;
626 struct listenercxx . . $ listener# *l = arg;
627 u_int32_tcxx . . $ u_int32_t# accepted;
628
629 if (error)
630 fatalcxx . . $ fatal(f6bc48f0426f26ee).("error on listening socket");
631
632 if (!(l->evtcxx . . $ listener#evt..flagscxx . . $ kore_event#flags. & KORE_EVENT_READcxx . . $ `include/kore/kore.h:187:9`!))
633 return;
634
635 accepted = 0;
636
637 while (worker_active_connectionscxx . . $ worker_active_connections. < worker_max_connectionscxx . . $ worker_max_connections.) {
638 if (worker_accept_thresholdcxx . . $ worker_accept_threshold. != 0 &&
639 accepted >= worker_accept_thresholdcxx . . $ worker_accept_threshold.) {
640 kore_worker_make_busycxx . . $ kore_worker_make_busy(49f6e7a06ebc5aa8).();
641 break;
642 }
643
644 if (!kore_connection_acceptcxx . . $ kore_connection_accept(39e429f7003ed54f).(l, &c))
645 break;
646
647 if (c == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
648 break;
649
650 accepted++;
651 kore_platform_event_allcxx . . $ kore_platform_event_all(6ca3d68f5c5f0975).(c->fdcxx . . $ connection#fd., c);
652 }
653 }
654
655 int
656 kore_sockoptcxx . . $ kore_sockopt(2326284602b0bb2d).(int fd, int what, int opt)
657 {
658 int on;
659
660 on = 1;
661 if (setsockoptcxx . . $ setsockopt(506cc1d0fc70fdf1).(fd, what, opt, (const char *)&on, sizeof(on)) == -1) {
662 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_ERRcxx . . $ `<external>/6168640806541382331/syslog.h:54:9`!, "setsockopt(): %s", errno_scxx . . $ `include/kore/kore.h:100:9`!);
663 return (KORE_RESULT_ERRORcxx . . $ `include/kore/kore.h:87:9`!);
664 }
665
666 return (KORE_RESULT_OKcxx . . $ `include/kore/kore.h:88:9`!);
667 }
668
669 void
670 kore_signal_setupcxx . . $ kore_signal_setup(49f6e7a06ebc5aa8).(void)
671 {
672 kore_signal_trapcxx . . $ kore_signal_trap(d4f767463ce0a6b3).(SIGHUPcxx . . $ `<external>/11773118241360591791/signum-generic.h:56:9`!);
673 kore_signal_trapcxx . . $ kore_signal_trap(d4f767463ce0a6b3).(SIGQUITcxx . . $ `<external>/11773118241360591791/signum-generic.h:57:9`!);
674 kore_signal_trapcxx . . $ kore_signal_trap(d4f767463ce0a6b3).(SIGTERMcxx . . $ `<external>/11773118241360591791/signum-generic.h:53:9`!);
675 kore_signal_trapcxx . . $ kore_signal_trap(d4f767463ce0a6b3).(SIGUSR1cxx . . $ `<external>/1457673850468744829/signum-arch.h:49:9`!);
676 kore_signal_trapcxx . . $ kore_signal_trap(d4f767463ce0a6b3).(SIGCHLDcxx . . $ `<external>/1457673850468744829/signum-arch.h:41:9`!);
677
678 if (kore_foregroundcxx . . $ kore_foreground.)
679 kore_signal_trapcxx . . $ kore_signal_trap(d4f767463ce0a6b3).(SIGINTcxx . . $ `<external>/11773118241360591791/signum-generic.h:48:9`!);
680 else
681 (void)signalcxx . . $ signal(c2d516773f91faf8).(SIGINTcxx . . $ `<external>/11773118241360591791/signum-generic.h:48:9`!, SIG_IGNcxx . . $ `<external>/11773118241360591791/signum-generic.h:30:9`!);
682
683 (void)signalcxx . . $ signal(c2d516773f91faf8).(SIGPIPEcxx . . $ `<external>/11773118241360591791/signum-generic.h:60:9`!, SIG_IGNcxx . . $ `<external>/11773118241360591791/signum-generic.h:30:9`!);
684 }
685
686 void
687 kore_signal_trapcxx . . $ kore_signal_trap(d4f767463ce0a6b3).(int sig)
688 {
689 struct sigactioncxx . . $ sigaction# sa;
690
691 sig_recvcxx . . $ sig_recv. = 0;
692 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&sa, 0, sizeof(sa));
693 sa.sa_handlercxx . . $ `<external>/16635209305659446502/sigaction.h:39:10`! = kore_signalcxx . . $ kore_signal(d4f767463ce0a6b3).;
694
695 if (sigfillsetcxx . . $ sigfillset(f9c066a8ff75ee9d).(&sa.sa_maskcxx . . $ sigaction#sa_mask.) == -1)
696 fatalcxx . . $ fatal(f6bc48f0426f26ee).("sigfillset: %s", errno_scxx . . $ `include/kore/kore.h:100:9`!);
697
698 if (sigactioncxx . . $ sigaction(53aba09fe16b06c7).(sig, &sa, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) == -1)
699 fatalcxx . . $ fatal(f6bc48f0426f26ee).("sigaction: %s", errno_scxx . . $ `include/kore/kore.h:100:9`!);
700 }
701
702 void
703 kore_server_closeallcxx . . $ kore_server_closeall(49f6e7a06ebc5aa8).(void)
704 {
705 struct listenercxx . . $ listener# *l;
706 struct kore_servercxx . . $ kore_server# *srv;
707
708 LIST_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:134:9`!(srv, &kore_servers, list) {
709 LIST_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:134:9`!(l, &srv->listeners, list)
710 l->fdcxx . . $ listener#fd. = -1;
711 }
712 }
713
714 void
715 kore_server_cleanupcxx . . $ kore_server_cleanup(49f6e7a06ebc5aa8).(void)
716 {
717 struct kore_servercxx . . $ kore_server# *srv;
718
719 while ((srv = LIST_FIRSTcxx . . $ `<external>/2546723208511035544/queue.h:143:9`!(&kore_servers)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
720 kore_server_freecxx . . $ kore_server_free(ef2fe6a8435a3580).(srv);
721 }
722
723 void
724 kore_signalcxx . . $ kore_signal(d4f767463ce0a6b3).(int sig)
725 {
726 sig_recvcxx . . $ sig_recv. = sig;
727 }
728
729 void
730 kore_shutdowncxx . . $ kore_shutdown(49f6e7a06ebc5aa8).(void)
731 {
732 if (workercxx . . $ worker. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
733 kore_msg_sendcxx . . $ kore_msg_send(6afaa3cccbe95a50).(KORE_MSG_PARENTcxx . . $ `include/kore/kore.h:679:9`!, KORE_MSG_SHUTDOWNcxx . . $ `include/kore/kore.h:663:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0);
734 return;
735 }
736
737 fatalcxx . . $ fatal(f6bc48f0426f26ee).("kore_shutdown: called from parent");
738 }
739
740 void
741 kore_proctitlecxx . . $ kore_proctitle(85c52e162fed56f9).(const char *title)
742 {
743 int len;
744
745 kore_argvcxx . . $ kore_argv.[1] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
746
747 len = snprintfcxx . . $ snprintf(ea502d73e74c754c).(kore_argvcxx . . $ kore_argv.[0], proctitle_maxlencxx . . $ proctitle_maxlen., "%s %s",
748 basenamecxx . . $ `<external>/6296865783241590524/libgen.h:35:9`!(kore_prognamecxx . . $ kore_progname.), title);
749 if (len == -1 || (size_t)len >= proctitle_maxlencxx . . $ proctitle_maxlen.)
750 fatalcxx . . $ fatal(f6bc48f0426f26ee).("proctitle '%s' too large", title);
751
752 memsetcxx . . $ memset(d1de1e4fb215f1c6).(kore_argvcxx . . $ kore_argv.[0] + len, 0, proctitle_maxlencxx . . $ proctitle_maxlen. - len);
753 }
754
755 static void
756 kore_proctitle_setupcxx . . $ kore_proctitle_setup(49f6e7a06ebc5aa8).(void)
757 {
758 int i;
759 char *p;
760
761 proctitle_maxlencxx . . $ proctitle_maxlen. = 0;
762
763 for (i = 0; environcxx . . $ environ.[i] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; i++) {
764 if ((p = strdupcxx . . $ strdup(a8b8e32347182212).(environcxx . . $ environ.[i])) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
765 fatalcxx . . $ fatal(f6bc48f0426f26ee).("strdup");
766 proctitle_maxlencxx . . $ proctitle_maxlen. += strlencxx . . $ strlen(751346f8406fd082).(environcxx . . $ environ.[i]) + 1;
767 environcxx . . $ environ.[i] = p;
768 }
769
770 for (i = 0; kore_argvcxx . . $ kore_argv.[i] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; i++)
771 proctitle_maxlencxx . . $ proctitle_maxlen. += strlencxx . . $ strlen(751346f8406fd082).(kore_argvcxx . . $ kore_argv.[i]) + 1;
772 }
773
774 static void
775 kore_server_startcxx . . $ kore_server_start(c759356ac01a31e7).(int argc, char *argv[])
776 {
777 u_int32_tcxx . . $ u_int32_t# tmp;
778 struct kore_servercxx . . $ kore_server# *srv;
779 u_int64_tcxx . . $ u_int64_t# netwait;
780 int last_sig;
781 #if !defined(KORE_NO_HTTP)
782 int alog;
783 struct kore_domaincxx . . $ kore_domain# *dom;
784 #endif
785 #if defined(KORE_SINGLE_BINARY)
786 struct kore_runtime_call *rcall;
787 #endif
788
789 if (!kore_quietcxx . . $ kore_quiet.) {
790 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_INFOcxx . . $ `<external>/6168640806541382331/syslog.h:57:9`!, "%s %s starting, built=%s",
791 __prognamecxx . . $ __progname., kore_versioncxx . . $ kore_version., kore_build_datecxx . . $ kore_build_date.);
792 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_INFOcxx . . $ `<external>/6168640806541382331/syslog.h:57:9`!, "built-ins: "
793 #if defined(__linux__cxx . . $ `<built-in>:401:9`!)
794 "seccomp "
795 #endif
796 #if defined(KORE_USE_PGSQL)
797 "pgsql "
798 #endif
799 #if defined(KORE_USE_TASKS)
800 "tasks "
801 #endif
802 #if defined(KORE_USE_JSONRPC)
803 "jsonrpc "
804 #endif
805 #if defined(KORE_USE_PYTHON)
806 "python "
807 #endif
808 #if defined(KORE_USE_ACME)
809 "acme "
810 #endif
811 #if defined(KORE_USE_CURL)
812 "curl "
813 #endif
814 );
815 }
816
817 if (kore_foregroundcxx . . $ kore_foreground. == 0) {
818 if (daemoncxx . . $ daemon(9b79fb6aee4c0440).(1, 0) == -1)
819 fatalcxx . . $ fatal(f6bc48f0426f26ee).("cannot daemon(): %s", errno_scxx . . $ `include/kore/kore.h:100:9`!);
820 #if defined(KORE_SINGLE_BINARY)
821 rcall = kore_runtime_getcall(parent_daemonized_hook);
822 if (rcall != NULL) {
823 kore_runtime_execute(rcall);
824 kore_free(rcall);
825 }
826 #endif
827 }
828
829 kore_pidcxx . . $ kore_pid. = getpidcxx . . $ getpid(b126dc7c1de90089).();
830 kore_write_kore_pidcxx . . $ kore_write_kore_pid(49f6e7a06ebc5aa8).();
831
832 #if !defined(KORE_SINGLE_BINARY) && !defined(KORE_USE_PYTHON)
833 kore_call_parent_configurecxx . . $ kore_call_parent_configure(c759356ac01a31e7).(argc, argv);
834 #endif
835
836 #if defined(KORE_USE_PYTHON) && !defined(KORE_SINGLE_BINARY)
837 if (kore_pymodule == NULL)
838 kore_call_parent_configure(argc, argv);
839 #endif
840
841 #if defined(KORE_USE_PYTHON)
842 kore_python_routes_resolve();
843 #endif
844
845 /* Check if keymgr will be active. */
846 if (kore_tls_supportedcxx . . $ kore_tls_supported(b126dc7c1de90089).()) {
847 LIST_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:134:9`!(srv, &kore_servers, list) {
848 if (srv->tlscxx . . $ kore_server#tls.) {
849 kore_keymgr_activecxx . . $ kore_keymgr_active. = 1;
850 break;
851 }
852 }
853 } else {
854 kore_keymgr_activecxx . . $ kore_keymgr_active. = 0;
855 }
856
857 kore_platform_proctitlecxx . . $ kore_platform_proctitle(85c52e162fed56f9).("[parent]");
858
859 if (!kore_worker_initcxx . . $ kore_worker_init(b126dc7c1de90089).()) {
860 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_ERRcxx . . $ `<external>/6168640806541382331/syslog.h:54:9`!, "last worker log lines:");
861 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_ERRcxx . . $ `<external>/6168640806541382331/syslog.h:54:9`!, "=====================================");
862 net_initcxx . . $ net_init(49f6e7a06ebc5aa8).();
863 kore_connection_initcxx . . $ kore_connection_init(49f6e7a06ebc5aa8).();
864 kore_platform_event_initcxx . . $ kore_platform_event_init(49f6e7a06ebc5aa8).();
865 kore_msg_parent_initcxx . . $ kore_msg_parent_init(49f6e7a06ebc5aa8).();
866 kore_platform_event_waitcxx . . $ kore_platform_event_wait(2c44cd906ae4e829).(10);
867 kore_worker_dispatch_signalcxx . . $ kore_worker_dispatch_signal(d4f767463ce0a6b3).(SIGQUITcxx . . $ `<external>/11773118241360591791/signum-generic.h:57:9`!);
868 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_ERRcxx . . $ `<external>/6168640806541382331/syslog.h:54:9`!, "=====================================");
869 return;
870 }
871
872 /* Set worker_max_connections for kore_connection_init(). */
873 tmp = worker_max_connectionscxx . . $ worker_max_connections.;
874 worker_max_connectionscxx . . $ worker_max_connections. = worker_countcxx . . $ worker_count.;
875
876 net_initcxx . . $ net_init(49f6e7a06ebc5aa8).();
877 kore_connection_initcxx . . $ kore_connection_init(49f6e7a06ebc5aa8).();
878 kore_platform_event_initcxx . . $ kore_platform_event_init(49f6e7a06ebc5aa8).();
879 kore_msg_parent_initcxx . . $ kore_msg_parent_init(49f6e7a06ebc5aa8).();
880
881 worker_max_connectionscxx . . $ worker_max_connections. = tmp;
882
883 kore_timer_initcxx . . $ kore_timer_init(49f6e7a06ebc5aa8).();
884
885 #if !defined(KORE_NO_HTTP)
886 alog = 0;
887
888 LIST_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:134:9`!(srv, &kore_servers, list) {
889 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(dom, &srv->domains, list) {
890 if (dom->accesslogcxx . . $ kore_domain#accesslog. != -1)
891 alog = 1;
892 }
893 }
894
895 if (alog) {
896 kore_timer_addcxx . . $ kore_timer_add(6973730e1cd229bb).(kore_accesslog_runcxx . . $ kore_accesslog_run(5500c4293b1bbef0)., 100, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0);
897 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_INFOcxx . . $ `<external>/6168640806541382331/syslog.h:57:9`!, "accesslog vacuum is enabled");
898 }
899 #endif
900
901 #if defined(KORE_USE_PYTHON)
902 kore_msg_unregister(KORE_PYTHON_SEND_OBJ);
903 #endif
904
905 while (kore_quitcxx . . $ kore_quit. == KORE_QUIT_NONEcxx . . $ `include/kore/kore.h:83:9`!) {
906 last_sig = sig_recvcxx . . $ sig_recv.;
907
908 if (last_sig != 0) {
909 switch (last_sig) {
910 case SIGHUPcxx . . $ `<external>/11773118241360591791/signum-generic.h:56:9`!:
911 kore_worker_dispatch_signalcxx . . $ kore_worker_dispatch_signal(d4f767463ce0a6b3).(last_sig);
912 kore_module_reloadcxx . . $ kore_module_reload(d4f767463ce0a6b3).(0);
913 break;
914 case SIGINTcxx . . $ `<external>/11773118241360591791/signum-generic.h:48:9`!:
915 case SIGQUITcxx . . $ `<external>/11773118241360591791/signum-generic.h:57:9`!:
916 case SIGTERMcxx . . $ `<external>/11773118241360591791/signum-generic.h:53:9`!:
917 kore_quitcxx . . $ kore_quit. = KORE_QUIT_NORMALcxx . . $ `include/kore/kore.h:84:9`!;
918 kore_worker_dispatch_signalcxx . . $ kore_worker_dispatch_signal(d4f767463ce0a6b3).(last_sig);
919 continue;
920 case SIGUSR1cxx . . $ `<external>/1457673850468744829/signum-arch.h:49:9`!:
921 kore_worker_dispatch_signalcxx . . $ kore_worker_dispatch_signal(d4f767463ce0a6b3).(last_sig);
922 break;
923 case SIGCHLDcxx . . $ `<external>/1457673850468744829/signum-arch.h:41:9`!:
924 kore_worker_reapcxx . . $ kore_worker_reap(49f6e7a06ebc5aa8).();
925 break;
926 default:
927 break;
928 }
929
930 if (sig_recvcxx . . $ sig_recv. == last_sig)
931 sig_recvcxx . . $ sig_recv. = 0;
932 else
933 continue;
934 }
935
936 netwait = kore_timer_next_runcxx . . $ kore_timer_next_run(ecdaa1632f49f591).(kore_time_mscxx . . $ kore_time_ms(f708dce9a8856c70).());
937 kore_platform_event_waitcxx . . $ kore_platform_event_wait(2c44cd906ae4e829).(netwait);
938 kore_connection_prunecxx . . $ kore_connection_prune(d4f767463ce0a6b3).(KORE_CONNECTION_PRUNE_DISCONNECTcxx . . $ `include/kore/kore.h:214:9`!);
939 kore_timer_runcxx . . $ kore_timer_run(2c44cd906ae4e829).(kore_time_mscxx . . $ kore_time_ms(f708dce9a8856c70).());
940 kore_worker_reapcxx . . $ kore_worker_reap(49f6e7a06ebc5aa8).();
941 }
942
943 kore_worker_dispatch_signalcxx . . $ kore_worker_dispatch_signal(d4f767463ce0a6b3).(SIGQUITcxx . . $ `<external>/11773118241360591791/signum-generic.h:57:9`!);
944 }
945
946 static void
947 kore_server_shutdowncxx . . $ kore_server_shutdown(49f6e7a06ebc5aa8).(void)
948 {
949 if (!kore_quietcxx . . $ kore_quiet.)
950 kore_logcxx . . $ kore_log(afcfcee7634adf7d).(LOG_INFOcxx . . $ `<external>/6168640806541382331/syslog.h:57:9`!, "server shutting down");
951
952 kore_worker_shutdowncxx . . $ kore_worker_shutdown(49f6e7a06ebc5aa8).();
953
954 #if !defined(KORE_NO_HTTP)
955 kore_accesslog_gathercxx . . $ kore_accesslog_gather(936bb941186e2394).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, kore_time_mscxx . . $ kore_time_ms(f708dce9a8856c70).(), 1);
956 #endif
957
958 kore_platform_event_cleanupcxx . . $ kore_platform_event_cleanup(49f6e7a06ebc5aa8).();
959 kore_connection_cleanupcxx . . $ kore_connection_cleanup(49f6e7a06ebc5aa8).();
960 kore_domain_cleanupcxx . . $ kore_domain_cleanup(49f6e7a06ebc5aa8).();
961 kore_tls_cleanupcxx . . $ kore_tls_cleanup(49f6e7a06ebc5aa8).();
962 net_cleanupcxx . . $ net_cleanup(49f6e7a06ebc5aa8).();
963 }
964
965 static void
966 kore_write_kore_pidcxx . . $ kore_write_kore_pid(49f6e7a06ebc5aa8).(void)
967 {
968 FILEcxx . . $ FILE# *fp;
969
970 if ((fp = fopencxx . . $ fopen(82ec0787cd37e0a3).(kore_pidfilecxx . . $ kore_pidfile., "w+")) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
971 printfcxx . . $ printf(581fddd72a8db8fc).("warning: couldn't write pid to %s (%s)\n",
972 kore_pidfilecxx . . $ kore_pidfile., errno_scxx . . $ `include/kore/kore.h:100:9`!);
973 } else {
974 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(fp, "%d\n", kore_pidcxx . . $ kore_pid.);
975 fclosecxx . . $ fclose(89bc1efcdac0ca22).(fp);
976 }
977 }
978
979 static void
980 kore_call_parent_configurecxx . . $ kore_call_parent_configure(c759356ac01a31e7).(int argc, char **argv)
981 {
982 struct kore_runtime_callcxx . . $ kore_runtime_call# *rcall;
983
984 rcall = kore_runtime_getcallcxx . . $ kore_runtime_getcall(b514b5951ac4d62f).(parent_config_hookcxx . . $ parent_config_hook.);
985 if (rcall != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
986 kore_runtime_configurecxx . . $ kore_runtime_configure(eedb5d87327531fa).(rcall, argc, argv);
987 kore_freecxx . . $ kore_free(5d22bdacc48458e8).(rcall);
988 }
989 }