Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for the newline-fd readiness protocol #484

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "openbsd-compat/openbsd-compat.h"

extern int use_privsep;
extern int notify_fd;
extern ServerOptions options;

void
Expand All @@ -47,6 +48,12 @@ platform_pre_listen(void)
void
platform_post_listen(void)
{
if (notify_fd) {
/* newline notification */
write(STDOUT_FILENO, "\n", 1);
/* close stdout */
dup2(STDERR_FILENO, STDOUT_FILENO);
}
#ifdef SYSTEMD_NOTIFY
ssh_systemd_notify_ready();
#endif
Expand Down
20 changes: 16 additions & 4 deletions sshd.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ char *config_file_name = _PATH_SERVER_CONFIG_FILE;
*/
int debug_flag = 0;

/*
* Write a newline to stdout after listening.
*/
int notify_fd = 0;

/*
* Indicating that the daemon should only test the configuration and keys.
* If test_flag > 1 ("-T" flag), then sshd will also dump the effective
Expand Down Expand Up @@ -896,7 +901,7 @@ usage(void)
{
fprintf(stderr, "%s, %s\n", SSH_RELEASE, SSH_OPENSSL_VERSION);
fprintf(stderr,
"usage: sshd [-46DdeGiqTtV] [-C connection_spec] [-c host_cert_file]\n"
"usage: sshd [-46DdeGiqTtV3] [-C connection_spec] [-c host_cert_file]\n"
" [-E log_file] [-f config_file] [-g login_grace_time]\n"
" [-h host_key_file] [-o option] [-p port] [-u len]\n"
);
Expand Down Expand Up @@ -1591,7 +1596,7 @@ main(int ac, char **av)

/* Parse command-line arguments. */
while ((opt = getopt(ac, av,
"C:E:b:c:f:g:h:k:o:p:u:46DGQRTdeiqrtV")) != -1) {
"C:E:b:c:f:g:h:k:o:p:u:46DGQRTdeiqrtV3")) != -1) {
switch (opt) {
case '4':
options.address_family = AF_INET;
Expand Down Expand Up @@ -1699,6 +1704,11 @@ main(int ac, char **av)
fprintf(stderr, "%s, %s\n",
SSH_RELEASE, SSH_OPENSSL_VERSION);
exit(0);
case '3':
/* implies process will be supervised */
no_daemon_flag = 1;
notify_fd = 1;
break;
default:
usage();
break;
Expand All @@ -1708,10 +1718,12 @@ main(int ac, char **av)
rexec_flag = 0;
if (!test_flag && !do_dump_cfg && rexec_flag && !path_absolute(av[0]))
fatal("sshd re-exec requires execution with an absolute path");
if (rexeced_flag)
if (rexeced_flag) {
notify_fd = 0;
closefrom(REEXEC_MIN_FREE_FD);
else
} else {
closefrom(REEXEC_DEVCRYPTO_RESERVED_FD);
}

seed_rng();

Expand Down