@@ -328,7 +328,7 @@ static enum protocol get_protocol(const char *name)
328
328
*/
329
329
static int git_tcp_connect_sock (char * host )
330
330
{
331
- int sockfd = -1 ;
331
+ int sockfd = -1 , saved_errno = 0 ;
332
332
char * colon , * end ;
333
333
const char * port = STR (DEFAULT_GIT_PORT );
334
334
struct addrinfo hints , * ai0 , * ai ;
@@ -362,9 +362,12 @@ static int git_tcp_connect_sock(char *host)
362
362
for (ai0 = ai ; ai ; ai = ai -> ai_next ) {
363
363
sockfd = socket (ai -> ai_family ,
364
364
ai -> ai_socktype , ai -> ai_protocol );
365
- if (sockfd < 0 )
365
+ if (sockfd < 0 ) {
366
+ saved_errno = errno ;
366
367
continue ;
368
+ }
367
369
if (connect (sockfd , ai -> ai_addr , ai -> ai_addrlen ) < 0 ) {
370
+ saved_errno = errno ;
368
371
close (sockfd );
369
372
sockfd = -1 ;
370
373
continue ;
@@ -375,7 +378,7 @@ static int git_tcp_connect_sock(char *host)
375
378
freeaddrinfo (ai0 );
376
379
377
380
if (sockfd < 0 )
378
- die ("unable to connect a socket (%s)" , strerror (errno ));
381
+ die ("unable to connect a socket (%s)" , strerror (saved_errno ));
379
382
380
383
return sockfd ;
381
384
}
@@ -387,7 +390,7 @@ static int git_tcp_connect_sock(char *host)
387
390
*/
388
391
static int git_tcp_connect_sock (char * host )
389
392
{
390
- int sockfd = -1 ;
393
+ int sockfd = -1 , saved_errno = 0 ;
391
394
char * colon , * end ;
392
395
char * port = STR (DEFAULT_GIT_PORT ), * ep ;
393
396
struct hostent * he ;
@@ -426,15 +429,18 @@ static int git_tcp_connect_sock(char *host)
426
429
427
430
for (ap = he -> h_addr_list ; * ap ; ap ++ ) {
428
431
sockfd = socket (he -> h_addrtype , SOCK_STREAM , 0 );
429
- if (sockfd < 0 )
432
+ if (sockfd < 0 ) {
433
+ saved_errno = errno ;
430
434
continue ;
435
+ }
431
436
432
437
memset (& sa , 0 , sizeof sa );
433
438
sa .sin_family = he -> h_addrtype ;
434
439
sa .sin_port = htons (nport );
435
440
memcpy (& sa .sin_addr , * ap , he -> h_length );
436
441
437
442
if (connect (sockfd , (struct sockaddr * )& sa , sizeof sa ) < 0 ) {
443
+ saved_errno = errno ;
438
444
close (sockfd );
439
445
sockfd = -1 ;
440
446
continue ;
@@ -443,7 +449,7 @@ static int git_tcp_connect_sock(char *host)
443
449
}
444
450
445
451
if (sockfd < 0 )
446
- die ("unable to connect a socket (%s)" , strerror (errno ));
452
+ die ("unable to connect a socket (%s)" , strerror (saved_errno ));
447
453
448
454
return sockfd ;
449
455
}
0 commit comments