}
cleanup_exit(1);
}
+void nonfatal(char *p, ...)
+{
+ struct termios cf;
+ va_list ap;
+ premsg(&cf);
+ fprintf(stderr, "ERROR: ");
+ va_start(ap, p);
+ vfprintf(stderr, p, ap);
+ va_end(ap);
+ fputc('\n', stderr);
+ postmsg(&cf);
+ if (logctx) {
+ log_free(logctx);
+ logctx = NULL;
+ }
+}
void connection_fatal(void *frontend, char *p, ...)
{
struct termios cf;
int platform_default_i(const char *name, int def)
{
- if (!strcmp(name, "TermWidth") ||
- !strcmp(name, "TermHeight")) {
- struct winsize size;
- if (ioctl(STDIN_FILENO, TIOCGWINSZ, (void *)&size) >= 0)
- return (!strcmp(name, "TermWidth") ? size.ws_col : size.ws_row);
- }
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)
}
bufchain stdout_data, stderr_data;
+enum { EOF_NO, EOF_PENDING, EOF_SENT } outgoingeof;
int try_output(int is_stderr)
{
bufchain *chain = (is_stderr ? &stderr_data : &stdout_data);
int fd = (is_stderr ? STDERR_FILENO : STDOUT_FILENO);
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);
+ int sendlen, ret;
+
+ if (bufchain_size(chain) > 0) {
+ int prev_nonblock = nonblock(fd);
+ 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 (!prev_nonblock)
+ no_nonblock(fd);
+ 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);
}
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);
}
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;
exit(1);
}
+void frontend_net_error_pending(void) {}
+
int main(int argc, char **argv)
{
int sending;
int errors;
int use_subsystem = 0;
int got_host = FALSE;
- long now;
+ unsigned long now;
+ struct winsize size;
fdlist = NULL;
fdcount = fdsize = 0;
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();
} else if (!strcmp(p, "-s")) {
/* Save status to write to conf later. */
use_subsystem = 1;
- } else if (!strcmp(p, "-V")) {
+ } else if (!strcmp(p, "-V") || !strcmp(p, "--version")) {
version();
+ } else if (!strcmp(p, "--help")) {
+ usage();
+ exit(0);
} else if (!strcmp(p, "-pgpfp")) {
pgp_fingerprints();
exit(1);
if (portnumber != -1)
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.
*/
}
putty_signal(SIGWINCH, sigwinch);
+ /*
+ * Now that we've got the SIGWINCH handler installed, try to find
+ * out the initial terminal size.
+ */
+ if (ioctl(STDIN_FILENO, TIOCGWINSZ, &size) >= 0) {
+ conf_set_int(conf, CONF_width, size.ws_col);
+ conf_set_int(conf, CONF_height, size.ws_row);
+ }
+
sk_init();
uxsel_init();
}
do {
- long next, ticks;
+ unsigned long next, then;
+ long ticks;
struct timeval tv, *ptv;
if (run_timers(now, &next)) {
- ticks = next - GETTICKCOUNT();
- if (ticks < 0) ticks = 0; /* just in case */
+ then = now;
+ now = GETTICKCOUNT();
+ if (now - then > next - then)
+ ticks = 0;
+ else
+ ticks = next - now;
tv.tv_sec = ticks / 1000;
tv.tv_usec = ticks % 1000 * 1000;
ptv = &tv;
ret = select(maxfd, &rset, &wset, &xset, ptv);
if (ret == 0)
now = next;
- else {
- long newnow = GETTICKCOUNT();
- /*
- * Check to see whether the system clock has
- * changed massively during the select.
- */
- if (newnow - now < 0 || newnow - now > next - now) {
- /*
- * If so, look at the elapsed time in the
- * select and use it to compute a new
- * tickcount_offset.
- */
- long othernow = now + tv.tv_sec * 1000 + tv.tv_usec / 1000;
- /* So we'd like GETTICKCOUNT to have returned othernow,
- * but instead it return newnow. Hence ... */
- tickcount_offset += othernow - newnow;
- now = othernow;
- } else {
- now = newnow;
- }
- }
+ else
+ now = GETTICKCOUNT();
} while (ret < 0 && errno == EINTR);
if (ret < 0) {
if (read(signalpipe[0], c, 1) <= 0)
/* ignore error */;
/* ignore its value; it'll be `x' */
- if (ioctl(0, TIOCGWINSZ, (void *)&size) >= 0)
+ if (ioctl(STDIN_FILENO, TIOCGWINSZ, (void *)&size) >= 0)
back->size(backhandle, size.ws_col, size.ws_row);
}
back->unthrottle(backhandle, try_output(TRUE));
}
+ net_pending_errors();
+
if ((!connopen || !back->connected(backhandle)) &&
bufchain_size(&stdout_data) == 0 &&
bufchain_size(&stderr_data) == 0)