Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 89577 | Differences between
and this patch

Collapse All | Expand All

(-)socket.c.orig (-6 / +43 lines)
Lines 26-34 Link Here
26
#include <sys/types.h>
26
#include <sys/types.h>
27
#include <sys/wait.h>
27
#include <sys/wait.h>
28
#include <sys/socket.h>
28
#include <sys/socket.h>
29
#include <sys/stat.h>
29
#include <sys/un.h>
30
#include <sys/un.h>
30
#include <netinet/in.h>
31
#include <netinet/in.h>
31
#include <arpa/inet.h>
32
#include <arpa/inet.h>
33
#include <resolv.h>
32
#include <netdb.h>
34
#include <netdb.h>
33
#include <unistd.h>
35
#include <unistd.h>
34
#include <stdio.h>
36
#include <stdio.h>
Lines 159-164 Link Here
159
	return 0;
161
	return 0;
160
}
162
}
161
163
164
void refresh_resolvers(void)
165
{
166
	static time_t resolv_conf_changed = (time_t)NULL;
167
	struct stat s;
168
169
	/* This makes the glibc re-read resolv.conf, if it changed
170
	 * since our startup. Maybe that should be #ifdef'ed, I don't
171
	 * know if it'd work on BSDs.
172
	 * Why doesn't the glibc do it by itself?
173
	 */
174
	if (stat("/etc/resolv.conf", &s) == 0) {
175
		if (s.st_mtime > resolv_conf_changed) {
176
			resolv_conf_changed = s.st_mtime;
177
			res_init();
178
		}
179
	} /* else
180
		we'll have bigger problems. */
181
}
182
162
gint fd_connect_unix(const gchar *path)
183
gint fd_connect_unix(const gchar *path)
163
{
184
{
164
	gint sock;
185
	gint sock;
Lines 387-393 Link Here
387
{
408
{
388
	gint ret;
409
	gint ret;
389
	void (*prev_handler)(gint);
410
	void (*prev_handler)(gint);
390
411
	
391
	alarm(0);
412
	alarm(0);
392
	prev_handler = signal(SIGALRM, timeout_handler);
413
	prev_handler = signal(SIGALRM, timeout_handler);
393
	if (sigsetjmp(jmpenv, 1)) {
414
	if (sigsetjmp(jmpenv, 1)) {
Lines 410-416 Link Here
410
{
431
{
411
	struct hostent *hp;
432
	struct hostent *hp;
412
	void (*prev_handler)(gint);
433
	void (*prev_handler)(gint);
413
434
	
414
	alarm(0);
435
	alarm(0);
415
	prev_handler = signal(SIGALRM, timeout_handler);
436
	prev_handler = signal(SIGALRM, timeout_handler);
416
	if (sigsetjmp(jmpenv, 1)) {
437
	if (sigsetjmp(jmpenv, 1)) {
Lines 467-472 Link Here
467
	ad.sin_family = AF_INET;
488
	ad.sin_family = AF_INET;
468
	ad.sin_port = htons(port);
489
	ad.sin_port = htons(port);
469
490
491
	refresh_resolvers();
492
470
	if (!my_inet_aton(hostname, &ad.sin_addr)) {
493
	if (!my_inet_aton(hostname, &ad.sin_addr)) {
471
		if ((hp = my_gethostbyname(hostname)) == NULL) {
494
		if ((hp = my_gethostbyname(hostname)) == NULL) {
472
			fprintf(stderr, "%s: unknown host.\n", hostname);
495
			fprintf(stderr, "%s: unknown host.\n", hostname);
Lines 494-499 Link Here
494
	struct addrinfo hints, *res, *ai;
517
	struct addrinfo hints, *res, *ai;
495
	gchar port_str[6];
518
	gchar port_str[6];
496
519
520
	refresh_resolvers();
521
497
	memset(&hints, 0, sizeof(hints));
522
	memset(&hints, 0, sizeof(hints));
498
	/* hints.ai_flags = AI_CANONNAME; */
523
	/* hints.ai_flags = AI_CANONNAME; */
499
	hints.ai_family = AF_UNSPEC;
524
	hints.ai_family = AF_UNSPEC;
Lines 851-856 Link Here
851
	SockLookupData *lookup_data = NULL;
876
	SockLookupData *lookup_data = NULL;
852
	gint pipe_fds[2];
877
	gint pipe_fds[2];
853
	pid_t pid;
878
	pid_t pid;
879
	
880
	refresh_resolvers();
854
881
855
	if (pipe(pipe_fds) < 0) {
882
	if (pipe(pipe_fds) < 0) {
856
		perror("pipe");
883
		perror("pipe");
Lines 1020-1026 Link Here
1020
#if USE_OPENSSL
1047
#if USE_OPENSSL
1021
gint ssl_read(SSL *ssl, gchar *buf, gint len)
1048
gint ssl_read(SSL *ssl, gchar *buf, gint len)
1022
{
1049
{
1023
	gint ret;
1050
	gint err, ret;
1024
1051
1025
	if (SSL_pending(ssl) == 0) {
1052
	if (SSL_pending(ssl) == 0) {
1026
		if (fd_check_io(SSL_get_rfd(ssl), G_IO_IN) < 0)
1053
		if (fd_check_io(SSL_get_rfd(ssl), G_IO_IN) < 0)
Lines 1029-1042 Link Here
1029
1056
1030
	ret = SSL_read(ssl, buf, len);
1057
	ret = SSL_read(ssl, buf, len);
1031
1058
1032
	switch (SSL_get_error(ssl, ret)) {
1059
	switch ((err = SSL_get_error(ssl, ret))) {
1033
	case SSL_ERROR_NONE:
1060
	case SSL_ERROR_NONE:
1034
		return ret;
1061
		return ret;
1035
	case SSL_ERROR_WANT_READ:
1062
	case SSL_ERROR_WANT_READ:
1036
	case SSL_ERROR_WANT_WRITE:
1063
	case SSL_ERROR_WANT_WRITE:
1037
		errno = EAGAIN;
1064
		errno = EAGAIN;
1038
		return -1;
1065
		return -1;
1066
	case SSL_ERROR_ZERO_RETURN:
1067
		return 0;
1039
	default:
1068
	default:
1069
		g_warning("SSL_read() returned error %d, ret = %d\n", err, ret);
1070
		if (ret == 0)
1071
			return 0;
1040
		return -1;
1072
		return -1;
1041
	}
1073
	}
1042
}
1074
}
Lines 1315-1321 Link Here
1315
#if USE_OPENSSL
1347
#if USE_OPENSSL
1316
gint ssl_peek(SSL *ssl, gchar *buf, gint len)
1348
gint ssl_peek(SSL *ssl, gchar *buf, gint len)
1317
{
1349
{
1318
	gint ret;
1350
	gint err, ret;
1319
1351
1320
	if (SSL_pending(ssl) == 0) {
1352
	if (SSL_pending(ssl) == 0) {
1321
		if (fd_check_io(SSL_get_rfd(ssl), G_IO_IN) < 0)
1353
		if (fd_check_io(SSL_get_rfd(ssl), G_IO_IN) < 0)
Lines 1324-1337 Link Here
1324
1356
1325
	ret = SSL_peek(ssl, buf, len);
1357
	ret = SSL_peek(ssl, buf, len);
1326
1358
1327
	switch (SSL_get_error(ssl, ret)) {
1359
	switch ((err = SSL_get_error(ssl, ret))) {
1328
	case SSL_ERROR_NONE:
1360
	case SSL_ERROR_NONE:
1329
		return ret;
1361
		return ret;
1330
	case SSL_ERROR_WANT_READ:
1362
	case SSL_ERROR_WANT_READ:
1331
	case SSL_ERROR_WANT_WRITE:
1363
	case SSL_ERROR_WANT_WRITE:
1332
		errno = EAGAIN;
1364
		errno = EAGAIN;
1333
		return -1;
1365
		return -1;
1366
	case SSL_ERROR_ZERO_RETURN:
1367
		return 0;
1334
	default:
1368
	default:
1369
		g_warning("SSL_peek() returned error %d, ret = %d\n", err, ret);
1370
		if (ret == 0)
1371
			return 0;
1335
		return -1;
1372
		return -1;
1336
	}
1373
	}
1337
}
1374
}

Return to bug 89577