From 610c331ead455abffb8c4c4705a0dd86ae16cd92 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 23 Jun 2006 20:41:47 +0000 Subject: [PATCH] *** empty log message *** svn path=/trunk/boinc/; revision=10506 --- checkin_notes | 17 +++++++++++++++++ client/client_state.C | 8 ++++++++ client/hostinfo_network.C | 22 +++++----------------- client/hostinfo_unix.C | 4 +--- client/win/hostinfo_win.cpp | 4 +--- lib/hostinfo.h | 1 + 6 files changed, 33 insertions(+), 23 deletions(-) diff --git a/checkin_notes b/checkin_notes index 2e99fa14c7..4585e05cf9 100755 --- a/checkin_notes +++ b/checkin_notes @@ -6743,3 +6743,20 @@ David 23 June 2006 lib/ prefs.C util.C + +David 23 June 2006 + - core client: + - removed Apple-specific retry logic in get_local_network_info() + - made get_local_network_info() a member of HOST_INFO + - in 1-sec poll loop, if don't have a domain name, + call get_local_network_info() again + (on some systems, gethostbyname() takes a few minutes to work) + + client/ + client_state.C + hostinfo_network.C + hostinfo_unix.C + win/ + hostinfo_win.cpp + lib/ + hostinfo.h diff --git a/client/client_state.C b/client/client_state.C index 3d5d0b618b..d39a2d297e 100644 --- a/client/client_state.C +++ b/client/client_state.C @@ -515,6 +515,14 @@ bool CLIENT_STATE::poll_slow_events() { return true; } else { time_stats.update(!tasks_suspended); + + // on some systems, gethostbyname() only starts working + // a few minutes after system boot. + // If it didn't work before, try it again. + // + if (!strlen(host_info.domain_name)) { + host_info.get_local_network_info(); + } return false; } } diff --git a/client/hostinfo_network.C b/client/hostinfo_network.C index f149e2f47d..203caccc46 100644 --- a/client/hostinfo_network.C +++ b/client/hostinfo_network.C @@ -57,32 +57,20 @@ // get domain name and IP address of this host // -int get_local_network_info( - char* domain_name, int domlen, char* ip_addr, int iplen -) { +int HOST_INFO::get_local_network_info() { char buf[256]; struct in_addr addr; struct hostent* he; - if (gethostname(buf, 256)) return ERR_GETHOSTBYNAME; -#ifdef __APPLE__ - short retryCount = 20; // Used when launching BOINC as a daemon / service at system startup -retry: -#endif + if (gethostname(buf, 256)) return ERR_GETHOSTBYNAME; he = gethostbyname(buf); if (!he || !he->h_addr_list[0]) { -#ifdef __APPLE__ - if ((TickCount() < (120*60)) && (--retryCount > 0)) { // If system has been up for less than 2 minutes - boinc_sleep(0.5); // allow time for gethostbyname to be initialized - goto retry; // Max delay is 20 * 0.5 = 10 seconds - } -#endif - msg_printf(NULL, MSG_ERROR, "gethostbyname failed"); + msg_printf(NULL, MSG_ERROR, "gethostbyname (%s) failed", buf); return ERR_GETHOSTBYNAME; } - strlcpy(domain_name, he->h_name, domlen); + strlcpy(domain_name, he->h_name, sizeof(domain_name)); memcpy(&addr, he->h_addr_list[0], sizeof(addr)); - strlcpy(ip_addr, inet_ntoa(addr), iplen); + strlcpy(ip_addr, inet_ntoa(addr), sizeof(ip_addr)); return 0; } diff --git a/client/hostinfo_unix.C b/client/hostinfo_unix.C index ff9982623d..21bf54299b 100644 --- a/client/hostinfo_unix.C +++ b/client/hostinfo_unix.C @@ -492,9 +492,7 @@ int HOST_INFO::get_host_info() { #endif #endif - get_local_network_info( - domain_name, sizeof(domain_name), ip_addr, sizeof(ip_addr) - ); + get_local_network_info(); timezone = get_timezone(); #ifdef HAVE_SYS_UTSNAME_H diff --git a/client/win/hostinfo_win.cpp b/client/win/hostinfo_win.cpp index eda41adfad..7714dcc756 100755 --- a/client/win/hostinfo_win.cpp +++ b/client/win/hostinfo_win.cpp @@ -618,9 +618,7 @@ int HOST_INFO::get_host_info() { ); // Detect host name/ip info - get_local_network_info( - domain_name, sizeof(domain_name), ip_addr, sizeof(ip_addr) - ); + get_local_network_info(); // Detect which accelerators are installed on the system get_accelerators( diff --git a/lib/hostinfo.h b/lib/hostinfo.h index ca4d2ce713..de430724c6 100644 --- a/lib/hostinfo.h +++ b/lib/hostinfo.h @@ -73,6 +73,7 @@ public: bool host_is_running_on_batteries(); bool users_idle(bool check_all_logins, double idle_time_to_run); int get_host_info(); + int get_local_network_info(); void clear_host_info(); void make_random_string(const char* salt, char* out); void generate_host_cpid();