xref: /freebsd/crypto/openssh/platform-listen.c (revision 8e28d84935f2f0ee081d44f9803f3052b960e50b)
1 /*
2  * Copyright (c) 2006 Darren Tucker.  All rights reserved.
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 "includes.h"
18 
19 #include <stdarg.h>
20 #include <stdio.h>
21 #include <string.h>
22 #include <unistd.h>
23 
24 #include "log.h"
25 #include "misc.h"
26 #include "platform.h"
27 
28 #include "openbsd-compat/openbsd-compat.h"
29 
30 void
platform_pre_listen(void)31 platform_pre_listen(void)
32 {
33 #ifdef LINUX_OOM_ADJUST
34 	/* Adjust out-of-memory killer so listening process is not killed */
35 	oom_adjust_setup();
36 #endif
37 #ifdef LINUX_MEMLOCK_ONFAULT
38 	/*
39 	 * Protect ourselves against kcompactd so that we are able to process
40 	 * new connections while it is active and migrating pages.
41 	 */
42 	memlock_onfault_setup();
43 #endif
44 }
45 
46 void
platform_post_listen(void)47 platform_post_listen(void)
48 {
49 #ifdef SYSTEMD_NOTIFY
50 	ssh_systemd_notify_ready();
51 #endif
52 }
53 
54 void
platform_pre_fork(void)55 platform_pre_fork(void)
56 {
57 #ifdef USE_SOLARIS_PROCESS_CONTRACTS
58 	solaris_contract_pre_fork();
59 #endif
60 }
61 
62 void
platform_pre_restart(void)63 platform_pre_restart(void)
64 {
65 #ifdef SYSTEMD_NOTIFY
66 	ssh_systemd_notify_reload();
67 #endif
68 #ifdef LINUX_OOM_ADJUST
69 	oom_adjust_restore();
70 #endif
71 }
72 
73 void
platform_post_fork_parent(pid_t child_pid)74 platform_post_fork_parent(pid_t child_pid)
75 {
76 #ifdef USE_SOLARIS_PROCESS_CONTRACTS
77 	solaris_contract_post_fork_parent(child_pid);
78 #endif
79 }
80 
81 void
platform_post_fork_child(void)82 platform_post_fork_child(void)
83 {
84 #ifdef USE_SOLARIS_PROCESS_CONTRACTS
85 	solaris_contract_post_fork_child();
86 #endif
87 #ifdef LINUX_OOM_ADJUST
88 	oom_adjust_restore();
89 #endif
90 }
91 
platform_pre_session_start(void)92 void platform_pre_session_start(void)
93 {
94 #ifdef LINUX_MEMLOCK_ONFAULT
95 	/*
96 	 * Memlock flags are dropped on fork, lock the memory again so that the
97 	 * child connection is also protected against kcompactd.
98 	 */
99 	memlock_onfault_setup();
100 #endif
101 }
102