From 8611ebf5de2a65a5491943ba355e631b2368537b Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Mon, 22 May 2000 22:53:15 +0000 Subject: [PATCH] (proto): select on the normal socket when waiting for the daemon to connect back to the stderr port, so that we discover when data arrives there before. when that happens, we assume that the daemon did not manage to connect (because of NAT/whatever) and continue as if `-e' was given git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@8286 ec53bebd-3082-4978-b11e-865c3cabbd6b --- appl/rsh/rsh.c | 50 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/appl/rsh/rsh.c b/appl/rsh/rsh.c index b80d098fc..379df9c5e 100644 --- a/appl/rsh/rsh.c +++ b/appl/rsh/rsh.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 1998, 1999 Kungliga Tekniska Högskolan + * Copyright (c) 1997 - 2000 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). * All rights reserved. * @@ -441,14 +441,45 @@ proto (int s, int errsock, return 1; } - errsock2 = accept (errsock, NULL, NULL); - if (errsock2 < 0) { - warn ("accept"); - close (errsock); - return 1; - } - close (errsock); + for (;;) { + fd_set fdset; + + FD_ZERO(&fdset); + FD_SET(errsock, &fdset); + FD_SET(s, &fdset); + + ret = select (max(errsock, s) + 1, &fdset, NULL, NULL, NULL); + if (ret < 0) { + if (errno == EINTR) + continue; + warn ("select"); + close (errsock); + return 1; + } + if (FD_ISSET(errsock, &fdset)) { + errsock2 = accept (errsock, NULL, NULL); + close (errsock); + if (errsock2 < 0) { + warn ("accept"); + return 1; + } + break; + } + + /* + * there should not arrive any data on this fd so if it's + * readable it probably indicates that the other side when + * away. + */ + + if (FD_ISSET(s, &fdset)) { + warnx ("socket closed"); + close (errsock); + errsock2 = -1; + break; + } + } } else { if (net_write (s, "0", 2) != 2) { warn ("write"); @@ -490,8 +521,7 @@ proto (int s, int errsock, /* * Return in `res' a copy of the concatenation of `argc, argv' into - * malloced space. - */ + * malloced space. */ static size_t construct_command (char **res, int argc, char **argv)