X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/4a693cfc5c3ee0e639bbee0215345e921715ab04..bfcd86603c6bc91605bf5cf98c21170d8bd93726:/unix/uxplink.c diff --git a/unix/uxplink.c b/unix/uxplink.c index 4d36e50a..85f5352a 100644 --- a/unix/uxplink.c +++ b/unix/uxplink.c @@ -125,21 +125,17 @@ int platform_default_i(const char *name, int def) return def; } -FontSpec platform_default_fontspec(const char *name) +FontSpec *platform_default_fontspec(const char *name) { - FontSpec ret; - *ret.name = '\0'; - return ret; + return fontspec_new(""); } -Filename platform_default_filename(const char *name) +Filename *platform_default_filename(const char *name) { - Filename ret; if (!strcmp(name, "LogFileName")) - strcpy(ret.path, "putty.log"); + return filename_from_str("putty.log"); else - *ret.path = '\0'; - return ret; + return filename_from_str(""); } char *x_get_default(const char *key) @@ -383,6 +379,7 @@ void cleanup_termios(void) } bufchain stdout_data, stderr_data; +enum { EOF_NO, EOF_PENDING, EOF_SENT } outgoingeof; int try_output(int is_stderr) { @@ -391,23 +388,26 @@ int try_output(int is_stderr) void *senddata; int sendlen, ret, fl; - if (bufchain_size(chain) == 0) - return bufchain_size(&stdout_data) + bufchain_size(&stderr_data); - - fl = fcntl(fd, F_GETFL); - if (fl != -1 && !(fl & O_NONBLOCK)) - fcntl(fd, F_SETFL, fl | O_NONBLOCK); - do { - bufchain_prefix(chain, &senddata, &sendlen); - ret = write(fd, senddata, sendlen); - if (ret > 0) - bufchain_consume(chain, ret); - } while (ret == sendlen && bufchain_size(chain) != 0); - if (fl != -1 && !(fl & O_NONBLOCK)) - fcntl(fd, F_SETFL, fl); - if (ret < 0 && errno != EAGAIN) { - perror(is_stderr ? "stderr: write" : "stdout: write"); - exit(1); + if (bufchain_size(chain) > 0) { + fl = fcntl(fd, F_GETFL); + if (fl != -1 && !(fl & O_NONBLOCK)) + fcntl(fd, F_SETFL, fl | O_NONBLOCK); + do { + bufchain_prefix(chain, &senddata, &sendlen); + ret = write(fd, senddata, sendlen); + if (ret > 0) + bufchain_consume(chain, ret); + } while (ret == sendlen && bufchain_size(chain) != 0); + if (fl != -1 && !(fl & O_NONBLOCK)) + fcntl(fd, F_SETFL, fl); + if (ret < 0 && errno != EAGAIN) { + perror(is_stderr ? "stderr: write" : "stdout: write"); + exit(1); + } + } + if (outgoingeof == EOF_PENDING && bufchain_size(&stdout_data) == 0) { + close(STDOUT_FILENO); + outgoingeof = EOF_SENT; } return bufchain_size(&stdout_data) + bufchain_size(&stderr_data); } @@ -419,6 +419,7 @@ int from_backend(void *frontend_handle, int is_stderr, bufchain_add(&stderr_data, data, len); return try_output(TRUE); } else { + assert(outgoingeof == EOF_NO); bufchain_add(&stdout_data, data, len); return try_output(FALSE); } @@ -434,6 +435,14 @@ int from_backend_untrusted(void *frontend_handle, const char *data, int len) return 0; /* not reached */ } +int from_backend_eof(void *frontend_handle) +{ + assert(outgoingeof == EOF_NO); + outgoingeof = EOF_PENDING; + try_output(FALSE); + return FALSE; /* do not respond to incoming EOF with outgoing */ +} + int get_userpass_input(prompts_t *p, unsigned char *in, int inlen) { int ret; @@ -576,6 +585,8 @@ static void version(void) exit(1); } +void frontend_net_error_pending(void) {} + int main(int argc, char **argv) { int sending; @@ -599,6 +610,10 @@ int main(int argc, char **argv) default_protocol = PROT_SSH; default_port = 22; + bufchain_init(&stdout_data); + bufchain_init(&stderr_data); + outgoingeof = EOF_NO; + flags = FLAG_STDERR | FLAG_STDERR_TTY; stderr_tty_init(); @@ -873,6 +888,12 @@ int main(int argc, char **argv) conf_set_int(conf, CONF_port, portnumber); /* + * Block SIGPIPE, so that we'll get EPIPE individually on + * particular network connections that go wrong. + */ + putty_signal(SIGPIPE, SIG_IGN); + + /* * Set up the pipe we'll use to tell us about SIGWINCH. */ if (pipe(signalpipe) < 0) { @@ -1088,6 +1109,8 @@ int main(int argc, char **argv) back->unthrottle(backhandle, try_output(TRUE)); } + net_pending_errors(); + if ((!connopen || !back->connected(backhandle)) && bufchain_size(&stdout_data) == 0 && bufchain_size(&stderr_data) == 0)