version 1.536, 2020/09/21 07:29:09 |
version 1.537, 2020/10/03 09:22:26 |
|
|
control_persist_detach(void) |
control_persist_detach(void) |
{ |
{ |
pid_t pid; |
pid_t pid; |
int devnull, keep_stderr; |
|
|
|
debug("%s: backgrounding master process", __func__); |
debug("%s: backgrounding master process", __func__); |
|
|
|
|
/* muxclient() doesn't return on success. */ |
/* muxclient() doesn't return on success. */ |
fatal("Failed to connect to new control master"); |
fatal("Failed to connect to new control master"); |
} |
} |
if ((devnull = open(_PATH_DEVNULL, O_RDWR)) == -1) { |
if (stdfd_devnull(1, 1, !(log_is_on_stderr() && debug_flag)) == -1) |
error("%s: open(\"/dev/null\"): %s", __func__, |
error("%s: stdfd_devnull failed", __func__); |
strerror(errno)); |
|
} else { |
|
keep_stderr = log_is_on_stderr() && debug_flag; |
|
if (dup2(devnull, STDIN_FILENO) == -1 || |
|
dup2(devnull, STDOUT_FILENO) == -1 || |
|
(!keep_stderr && dup2(devnull, STDERR_FILENO) == -1)) |
|
error("%s: dup2: %s", __func__, strerror(errno)); |
|
if (devnull > STDERR_FILENO) |
|
close(devnull); |
|
} |
|
daemon(1, 1); |
daemon(1, 1); |
setproctitle("%s [mux]", options.control_path); |
setproctitle("%s [mux]", options.control_path); |
} |
} |
|
|
static void |
static void |
fork_postauth(void) |
fork_postauth(void) |
{ |
{ |
int devnull, keep_stderr; |
|
|
|
if (need_controlpersist_detach) |
if (need_controlpersist_detach) |
control_persist_detach(); |
control_persist_detach(); |
debug("forking to background"); |
debug("forking to background"); |
fork_after_authentication_flag = 0; |
fork_after_authentication_flag = 0; |
if (daemon(1, 1) == -1) |
if (daemon(1, 1) == -1) |
fatal("daemon() failed: %.200s", strerror(errno)); |
fatal("daemon() failed: %.200s", strerror(errno)); |
if ((devnull = open(_PATH_DEVNULL, O_WRONLY)) == -1) |
if (stdfd_devnull(1, 1, !(log_is_on_stderr() && debug_flag)) == -1) |
error("%s: open %s: %s", __func__, |
error("%s: stdfd_devnull failed", __func__); |
_PATH_DEVNULL, strerror(errno)); |
|
else { |
|
keep_stderr = log_is_on_stderr() && debug_flag; |
|
if (dup2(devnull, STDIN_FILENO) == -1 || |
|
dup2(devnull, STDOUT_FILENO) == -1 || |
|
(!keep_stderr && dup2(devnull, STDOUT_FILENO) == -1)) |
|
fatal("%s: dup2() stdio failed", __func__); |
|
if (devnull > STDERR_FILENO) |
|
close(devnull); |
|
} |
|
} |
} |
|
|
static void |
static void |
|
|
static int |
static int |
ssh_session2(struct ssh *ssh, struct passwd *pw) |
ssh_session2(struct ssh *ssh, struct passwd *pw) |
{ |
{ |
int r, devnull, id = -1; |
int r, id = -1; |
char *cp, *tun_fwd_ifname = NULL; |
char *cp, *tun_fwd_ifname = NULL; |
|
|
/* XXX should be pre-session */ |
/* XXX should be pre-session */ |
|
|
* NB. this can only happen after LocalCommand has completed, |
* NB. this can only happen after LocalCommand has completed, |
* as it may want to write to stdout. |
* as it may want to write to stdout. |
*/ |
*/ |
if (!need_controlpersist_detach) { |
if (!need_controlpersist_detach && stdfd_devnull(0, 1, 0) == -1) |
if ((devnull = open(_PATH_DEVNULL, O_WRONLY)) == -1) { |
error("%s: stdfd_devnull failed", __func__); |
error("%s: open %s: %s", __func__, |
|
_PATH_DEVNULL, strerror(errno)); |
|
} else { |
|
if (dup2(devnull, STDOUT_FILENO) == -1) |
|
fatal("%s: dup2() stdout failed", __func__); |
|
if (devnull > STDERR_FILENO) |
|
close(devnull); |
|
} |
|
} |
|
|
|
/* |
/* |
* If requested and we are not interested in replies to remote |
* If requested and we are not interested in replies to remote |