Kaydet (Commit) cb22fb0c authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Make osl_getLocalHostname thread-safe

Change-Id: I82b8c49fcbbec161bf968573e28992fa5737b45b
Reviewed-on: https://gerrit.libreoffice.org/67508
Tested-by: Jenkins
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst fd66ee18
...@@ -17,6 +17,10 @@ ...@@ -17,6 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include <sal/config.h>
#include <utility>
#include "system.h" #include "system.h"
#include <osl/socket.h> #include <osl/socket.h>
...@@ -596,10 +600,9 @@ void SAL_CALL osl_destroyHostAddr(oslHostAddr pAddr) ...@@ -596,10 +600,9 @@ void SAL_CALL osl_destroyHostAddr(oslHostAddr pAddr)
oslSocketResult SAL_CALL osl_getLocalHostname (rtl_uString **strLocalHostname) oslSocketResult SAL_CALL osl_getLocalHostname (rtl_uString **strLocalHostname)
{ {
static sal_Unicode LocalHostname[256] = {0}; static auto const init = []() -> std::pair<oslSocketResult, OUString> {
sal_Unicode LocalHostname[256] = {0};
if (rtl_ustr_getLength(LocalHostname) == 0)
{
sal_Char Host[256]= ""; sal_Char Host[256]= "";
if (gethostname(Host, sizeof(Host)) == 0) if (gethostname(Host, sizeof(Host)) == 0)
{ {
...@@ -638,15 +641,18 @@ oslSocketResult SAL_CALL osl_getLocalHostname (rtl_uString **strLocalHostname) ...@@ -638,15 +641,18 @@ oslSocketResult SAL_CALL osl_getLocalHostname (rtl_uString **strLocalHostname)
} }
} }
} }
}
if (rtl_ustr_getLength(LocalHostname) > 0) if (rtl_ustr_getLength(LocalHostname) > 0)
{ {
rtl_uString_newFromStr (strLocalHostname, LocalHostname); return {osl_Socket_Ok, LocalHostname};
return osl_Socket_Ok;
} }
return osl_Socket_Error; return {osl_Socket_Error, OUString()};
}();
rtl_uString_assign (strLocalHostname, init.second.pData);
return init.first;
} }
oslSocketAddr SAL_CALL osl_resolveHostname(rtl_uString* strHostname) oslSocketAddr SAL_CALL osl_resolveHostname(rtl_uString* strHostname)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment