diff options
author | Matt Johnston <matt@ucc.asn.au> | 2006-12-06 13:11:41 +0000 |
---|---|---|
committer | Matt Johnston <matt@ucc.asn.au> | 2006-12-06 13:11:41 +0000 |
commit | d5897b9a5d461c91cd525e5b2212125cf53ad268 (patch) | |
tree | cec78b43140a2610175f8e918ae22bfff0bbdf1f /cli-session.c | |
parent | 7b780efb42e3d9b369b4f00421fba1fc21ec2a22 (diff) | |
parent | 35bcc463e5ffe2f630c71962ca12d69a84952568 (diff) |
merge of '182c2d8dbd5321ef4d1df8758936f4dc7127015f'
and '31dcd7a22983ef19d6c63248e415e71d292dd0ec'
--HG--
extra : convert_revision : e84f66826c7ee6ebe99ef92cc0f6c22ecf638d01
Diffstat (limited to 'cli-session.c')
-rw-r--r-- | cli-session.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/cli-session.c b/cli-session.c index 35510fa..be36bec 100644 --- a/cli-session.c +++ b/cli-session.c @@ -212,19 +212,38 @@ static void cli_sessionloop() { */ case USERAUTH_SUCCESS_RCVD: + + if (cli_opts.backgrounded) { + int devnull; + // keeping stdin open steals input from the terminal and + // is confusing, though stdout/stderr could be useful. + devnull = open(_PATH_DEVNULL, O_RDONLY); + if (devnull < 0) { + dropbear_exit("opening /dev/null: %d %s", + errno, strerror(errno)); + } + dup2(devnull, STDIN_FILENO); + if (daemon(0, 1) < 0) { + dropbear_exit("Backgrounding failed: %d %s", + errno, strerror(errno)); + } + } + #ifdef ENABLE_CLI_LOCALTCPFWD setup_localtcp(); #endif #ifdef ENABLE_CLI_REMOTETCPFWD setup_remotetcp(); #endif - cli_send_chansess_request(); - TRACE(("leave cli_sessionloop: cli_send_chansess_request")) + if (!cli_opts.no_cmd) { + cli_send_chansess_request(); + } + TRACE(("leave cli_sessionloop: running")) cli_ses.state = SESSION_RUNNING; return; case SESSION_RUNNING: - if (ses.chancount < 1) { + if (ses.chancount < 1 && !cli_opts.no_cmd) { cli_finished(); } |