diff options
author | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2006-12-13 05:53:57 +0000 |
---|---|---|
committer | hiro <hiro@ee746299-78ed-0310-b773-934348b2243d> | 2006-12-13 05:53:57 +0000 |
commit | 3c6ddfce94cf486d7b4ff27035299f6b384f3559 (patch) | |
tree | ea1a7a41cf3d889cbffb86fcb277a7cf6c3556ec /libsylph | |
parent | 0d93d2a44ee23d371f0e9536635d56109f340c83 (diff) |
Unix: reload /etc/resolv.conf if it has been modified.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@1418 ee746299-78ed-0310-b773-934348b2243d
Diffstat (limited to 'libsylph')
-rw-r--r-- | libsylph/socket.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/libsylph/socket.c b/libsylph/socket.c index 3e0982d1..c79e377c 100644 --- a/libsylph/socket.c +++ b/libsylph/socket.c @@ -35,7 +35,9 @@ # include <sys/un.h> # include <netinet/in.h> # include <arpa/inet.h> +# include <resolv.h> # include <netdb.h> +# include <sys/stat.h> #endif /* G_OS_WIN32 */ #include <unistd.h> #include <stdio.h> @@ -621,6 +623,21 @@ static gint sock_connect_with_timeout(gint sock, return ret; } +static void resolver_init(void) +{ +#ifdef G_OS_UNIX + static time_t resolv_conf_mtime = 0; + struct stat s; + + if (g_stat("/etc/resolv.conf", &s) == 0 && + s.st_mtime != resolv_conf_mtime) { + debug_print("Reloading /etc/resolv.conf\n"); + resolv_conf_mtime = s.st_mtime; + res_init(); + } +#endif +} + struct hostent *my_gethostbyname(const gchar *hostname) { struct hostent *hp; @@ -684,6 +701,8 @@ static gint sock_connect_by_hostname(gint sock, const gchar *hostname, struct hostent *hp; struct sockaddr_in ad; + resolver_init(); + memset(&ad, 0, sizeof(ad)); ad.sin_family = AF_INET; ad.sin_port = htons(port); @@ -729,6 +748,8 @@ static SockDesc sock_connect_by_getaddrinfo(const gchar *hostname, gushort port) struct addrinfo hints, *res, *ai; gchar port_str[6]; + resolver_init(); + memset(&hints, 0, sizeof(hints)); /* hints.ai_flags = AI_CANONNAME; */ hints.ai_family = AF_UNSPEC; @@ -1094,6 +1115,8 @@ static SockLookupData *sock_get_address_info_async(const gchar *hostname, gint pipe_fds[2]; pid_t pid; + resolver_init(); + if (pipe(pipe_fds) < 0) { perror("pipe"); func(NULL, data); |