Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


Hi,

The first patch replace the usage of gethostbyname by the reentrant version.

The second and third patch removes internal gethostbyname_r, backtrace and
backtrace_symbols_fd. I'm not sure about these two patches, those functions
are in the libc on all current OS and symbols are not exported.

Thanks in advance
-- 
Arnaud Versini
From 22d1ac12c959fd1ddeb4ff688a17a4ef13c126b5 Mon Sep 17 00:00:00 2001
From: Arnaud Versini <arnaud.versini@gmail.com>
Date: Fri, 18 Nov 2011 19:52:45 +0100
Subject: [PATCH] Replace gethostbyname by _osl_gethostbyname_r in socket.c .

---
 sal/osl/unx/socket.c |   23 +++++++++--------------
 1 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/sal/osl/unx/socket.c b/sal/osl/unx/socket.c
index ed31a82..d471463 100644
--- a/sal/osl/unx/socket.c
+++ b/sal/osl/unx/socket.c
@@ -1014,22 +1014,17 @@ oslHostAddr SAL_CALL osl_createHostAddrByName(rtl_uString *ustrHostname)
 
 oslHostAddr SAL_CALL osl_psz_createHostAddrByName (const sal_Char *pszHostname)
 {
-    struct hostent *he;
-        oslHostAddr addr;
+    struct      hostent  aHe;
+    struct      hostent *pHe;
+    sal_Char    heBuffer[ MAX_HOSTBUFFER_SIZE ];
+    int         nErrorNo;
 
-    static oslMutex mutex = NULL;
+    pHe = _osl_gethostbyname_r (
+        pszHostname,
+        &aHe, heBuffer,
+        sizeof(heBuffer), &nErrorNo );
 
-    if (mutex == NULL)
-        mutex = osl_createMutex();
-
-    osl_acquireMutex(mutex);
-
-    he = gethostbyname((sal_Char *)pszHostname);
-    addr = _osl_hostentToHostAddr (he);
-
-    osl_releaseMutex(mutex);
-
-    return addr;
+    return _osl_hostentToHostAddr (pHe);
 }
 
 /*****************************************************************************/
-- 
1.7.5.4

From a84a5282258996329c179646f092cd6b9d91aff4 Mon Sep 17 00:00:00 2001
From: Arnaud Versini <arnaud.versini@gmail.com>
Date: Fri, 18 Nov 2011 19:54:28 +0100
Subject: [PATCH] Remove internal gethostbyname_r implementation.

---
 sal/osl/unx/system.c |  122 --------------------------------------------------
 sal/osl/unx/system.h |    4 --
 2 files changed, 0 insertions(+), 126 deletions(-)

diff --git a/sal/osl/unx/system.c b/sal/osl/unx/system.c
index 4bb0e46..e67d388 100644
--- a/sal/osl/unx/system.c
+++ b/sal/osl/unx/system.c
@@ -32,100 +32,6 @@
 
 static pthread_mutex_t getrtl_mutex = PTHREAD_MUTEX_INITIALIZER;
 
-/* struct passwd differs on some platforms */
-#if !defined(FREEBSD) || (__FreeBSD_version < 601103)
-
-extern int h_errno;
-
-struct hostent *gethostbyname_r(const char *name, struct hostent *result,
-                                char *buffer, int buflen, int *h_errnop)
-{
-    /* buffer layout:   name\0
-     *                  array_of_pointer_to_aliases
-     *                  NULL
-     *                  alias1\0...aliasn\0
-     *                  array_of_pointer_to_addresses
-     *                  NULL
-     *                  addr1addr2addr3...addrn
-     */
-      struct hostent* res;
-
-      pthread_mutex_lock(&getrtl_mutex);
-
-      if ( (res = gethostbyname(name)) )
-      {
-        int nname, naliases, naddr_list, naliasesdata, n;
-        char **p, **parray, *data;
-
-        /* Check buffer size before copying, we want to leave the
-         * buffers unmodified in case something goes wrong.
-         *
-         * Is this required?
-         */
-
-        nname= strlen(res->h_name)+1;
-
-        naliases = naddr_list = naliasesdata = 0;
-
-        for ( p = res->h_aliases; *p != NULL; p++) {
-            naliases++;
-            naliasesdata += strlen(*p)+1;
-        }
-
-        for ( p = res->h_addr_list; *p != NULL; p++)
-            naddr_list++;
-
-        if ( nname
-             + (naliases+1)*sizeof(char*) + naliasesdata
-             + (naddr_list+1)*sizeof(char*) + naddr_list*res->h_length
-             <= buflen )
-        {
-            memcpy(result, res, sizeof(struct hostent));
-
-            strcpy(buffer, res->h_name);
-              result->h_name = buffer;
-            buffer += nname;
-
-            parray = (char**)buffer;
-            result->h_aliases = parray;
-            data = buffer + (naliases+1)*sizeof(char*);
-            for ( p = res->h_aliases; *p != NULL; p++) {
-                n = strlen(*p)+1;
-                *parray++ = data;
-                memcpy(data, *p, n);
-                data += n;
-            }
-            *parray = NULL;
-            buffer = data;
-            parray = (char**)buffer;
-            result->h_addr_list = parray;
-            data = buffer + (naddr_list+1)*sizeof(char*);
-            for ( p = res->h_addr_list; *p != NULL; p++) {
-                *parray++ = data;
-                memcpy(data, *p, res->h_length);
-                data += res->h_length;
-            }
-            *parray = NULL;
-
-               res = result;
-        }
-        else
-        {
-            errno = ERANGE;
-            res = NULL;
-        }
-    }
-    else
-    {
-        *h_errnop = h_errno;
-    }
-
-    pthread_mutex_unlock(&getrtl_mutex);
-
-      return res;
-}
-#endif /* !defined(FREEBSD) || (__FreeBSD_version < 601103) */
-
 #if defined(MACOSX)
 /*
  * Add support for resolving Mac native alias files (not the same as unix alias files)
@@ -201,34 +107,6 @@ int macxp_resolveAlias(char *path, int buflen)
 
 #endif /* NO_PTHREAD_RTL */
 
-#if defined(LINUX)
-/* The linux kernel thread implemention, always return the pid of the
-   thread subprocess and not of the main process. So we save the main
-   pid at startup
-*/
-
-// Directly from libc.so.6, obviously missing from some unistd.h:
-extern __pid_t __getpid(void);
-
-static pid_t pid = -1;
-
-static void savePid(void) __attribute__((constructor));
-
-static void savePid(void)
-{
-    if (pid == -1)
-        pid = __getpid();
-}
-
-pid_t getpid(void)
-{
-    if (pid == -1)
-        savePid();
-
-    return (pid);
-}
-#endif /*  defined LINUX */
-
 #ifdef NO_PTHREAD_SEMAPHORES
 int sem_init(sem_t* sem, int pshared, unsigned int value)
 {
diff --git a/sal/osl/unx/system.h b/sal/osl/unx/system.h
index c8f4871..d3293ad 100644
--- a/sal/osl/unx/system.h
+++ b/sal/osl/unx/system.h
@@ -504,10 +504,6 @@ extern struct spwd *getspnam_r(const char *name, struct spwd *result,
 struct tm *localtime_r(const time_t *timep, struct tm *buffer);
 struct tm *gmtime_r(const time_t *timep, struct tm *buffer);
 #endif /* !defined FREEBSD || (__FreeBSD_version < 500112) */
-#if !defined(FREEBSD) || (__FreeBSD_version < 601103)
-struct hostent *gethostbyname_r(const char *name, struct hostent *result,
-                                char *buffer, int buflen, int *h_errnop);
-#endif /* !defined(FREEBSD) || (__FreeBSD_version < 601103) */
 #endif
 
 #endif /* __OSL_SYSTEM_H__ */
-- 
1.7.5.4

From 7ab9fd4f0088c78c6dbb5481ebac0b313f799a50 Mon Sep 17 00:00:00 2001
From: Arnaud Versini <arnaud.versini@gmail.com>
Date: Fri, 18 Nov 2011 19:57:16 +0100
Subject: [PATCH] Remove internal backtrace and backtrace_symbols_fd

---
 sal/osl/unx/backtrace.c |   81 -----------------------------------------------
 sal/osl/unx/backtrace.h |   23 +------------
 2 files changed, 2 insertions(+), 102 deletions(-)

diff --git a/sal/osl/unx/backtrace.c b/sal/osl/unx/backtrace.c
index d5e4e94..01ff18f 100644
--- a/sal/osl/unx/backtrace.c
+++ b/sal/osl/unx/backtrace.c
@@ -211,87 +211,6 @@ void backtrace_symbols_fd( void **buffer, int size, int fd )
 #define _GNU_SOURCE
 #endif
 
-#include <dlfcn.h>
-#include <pthread.h>
-#include <setjmp.h>
-#include <stdio.h>
-#include "backtrace.h"
-
-#if defined(SPARC)
-
-#define FRAME_PTR_OFFSET 1
-#define FRAME_OFFSET 0
-
-#else
-
-#error Unknown Linux target platform.
-
-#endif /* defined SPARC or INTEL */
-
-typedef int ptrdiff_t;
-
-int backtrace( void **buffer, int max_frames )
-{
-    struct frame *fp;
-    jmp_buf ctx;
-    int i;
-
-    /* flush register windows */
-#ifdef SPARC
-    asm("ta 3");
-#endif
-    /* get stack- and framepointer */
-    setjmp(ctx);
-    fp = (struct frame*)(((size_t*)(ctx))[FRAME_PTR_OFFSET]);
-    for ( i=0; (i<FRAME_OFFSET) && (fp!=0); i++)
-        fp = fp->fr_savfp;
-
-    /* iterate through backtrace */
-    for (i=0; fp && fp->fr_savpc && i<max_frames; i++)
-    {
-        /* store frame */
-        *(buffer++) = (void *)fp->fr_savpc;
-        /* next frame */
-        fp=fp->fr_savfp;
-    }
-    return i;
-}
-
-void backtrace_symbols_fd( void **buffer, int size, int fd )
-{
-    FILE    *fp = fdopen( fd, "w" );
-
-    if ( fp )
-    {
-        void **pFramePtr;
-
-        for ( pFramePtr = buffer; size > 0 && pFramePtr && *pFramePtr; pFramePtr++, size-- )
-        {
-            Dl_info     dli;
-
-            if ( 0 != dladdr( *pFramePtr, &dli ) )
-            {
-                ptrdiff_t offset;
-
-                if ( dli.dli_fname && dli.dli_fbase )
-                {
-                    offset = (ptrdiff_t)*pFramePtr - (ptrdiff_t)dli.dli_fbase;
-                    fprintf( fp, "%s+0x%x", dli.dli_fname, offset );
-                }
-                if ( dli.dli_sname && dli.dli_saddr )
-                {
-                    offset = (ptrdiff_t)*pFramePtr - (ptrdiff_t)dli.dli_saddr;
-                    fprintf( fp, "(%s+0x%x)", dli.dli_sname, offset );
-                }
-            }
-            fprintf( fp, "[0x%x]\n", *pFramePtr );
-        }
-
-        fflush( fp );
-        fclose( fp );
-    }
-}
-
 #endif /* defined LINUX */
 
 #if defined( MACOSX )
diff --git a/sal/osl/unx/backtrace.h b/sal/osl/unx/backtrace.h
index 79fb580..61d63ec 100644
--- a/sal/osl/unx/backtrace.h
+++ b/sal/osl/unx/backtrace.h
@@ -58,27 +58,8 @@ struct frame {
 
 #endif /* defined SOLARIS || FREEBSD || NETBSD || OPENBSD */
 
-#if defined (LINUX) && defined (SPARC)
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* backtrace function with same behaviour as defined in GNU libc */
-
-int backtrace( void **buffer, int max_frames );
-
-void backtrace_symbols_fd( void **buffer, int size, int fd );
-
-/* no frame.h on linux sparc */
-struct frame {
-    long    arg0[8];
-    long    arg1[6];
-    struct frame *fr_savfp;
-    long    fr_savpc;
-};
-
-#ifdef __cplusplus
-} /* extern "C" */
+#if defined (LINUX)
+#include <execinfo.h>
 #endif
 
 #endif /* defined LINUX && SPARC */
-- 
1.7.5.4


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.