[SCM] Debian Qt/KDE packaging tools branch, master, updated. debian/0.13.1-20-g74eac84

Modestas Vainius modax at alioth.debian.org
Wed May 25 19:55:42 UTC 2011


The following commit has been merged in the master branch:
commit 09f8555d7c2b280e8327d83f1344a0492590b62e
Author: Modestas Vainius <modax at debian.org>
Date:   Wed May 25 22:47:27 2011 +0300

    Various improves to dlr_check_file_compatibility().
    
    1) Add posibility to retrieve an open dl handle from
    dlr_check_file_compatibility() or to pass it directly instead of filename.
    
    2) Improve debugging messages.
    
    3) Do not use dlmopen() as it does not appear to be very stable. This means
    less reliability though but in most case DLRestrictions should still catch
    absolute majority of problems.
---
 dlrestrictions/dlrestrictions.c |   44 +++++++++++++++++++++++++++++++--------
 dlrestrictions/dlrestrictions.h |    8 +++++-
 2 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/dlrestrictions/dlrestrictions.c b/dlrestrictions/dlrestrictions.c
index ee1579e..32f5e0b 100644
--- a/dlrestrictions/dlrestrictions.c
+++ b/dlrestrictions/dlrestrictions.c
@@ -512,7 +512,7 @@ static int dlr_are_symbol_objects_compatible(void *h_base, void *h_against)
     return status;
 }
 
-int dlr_check_file_compatibility(const char *file)
+int dlr_check_file_compatibility(const char *file, void **handle)
 {
     void *h_global, *h_file;
     int status;
@@ -521,15 +521,31 @@ int dlr_check_file_compatibility(const char *file)
     errno = 0;
     dlr_set_error(NULL);
 
-    h_file = dlmopen(LM_ID_NEWLM, file, RTLD_LAZY | RTLD_LOCAL);
-    if (h_file == NULL) {
-        return -ENOENT;
+    dlr_debug(2, "Entering dlr_check_file_compatbility(\"%s\") ...", file);
+
+    /* Open a file or use a handle */
+    if (file != NULL) {
+        h_file = dlopen(file, RTLD_LAZY | RTLD_LOCAL);
+        if (handle != NULL) {
+            *handle = h_file;
+        }
+        if (h_file == NULL) {
+            dlr_set_error(dlerror());
+            return -ENOENT;
+        }
+    } else if (handle != NULL) {
+        h_file = *handle;
+    } else {
+        dlr_set_error("dlr_check_file_compatibility(): %s", strerror(EINVAL));
+        return -EINVAL;
     }
 
     h_global = dlopen(0, RTLD_LAZY | RTLD_LOCAL);
     if (h_global == NULL) {
         dlr_set_error("unable to dlopen() global symbol object");
-        dlclose(h_file);
+        if (handle == NULL) {
+            dlclose(h_file);
+        }
         return -ENOTDIR;
     }
 
@@ -539,7 +555,9 @@ int dlr_check_file_compatibility(const char *file)
     }
 
     dlclose(h_global);
-    dlclose(h_file);
+    if (handle == NULL) {
+        dlclose(h_file);
+    }
 
     return status;
 }
@@ -547,8 +565,9 @@ int dlr_check_file_compatibility(const char *file)
 void* dlr_dlopen_extended(const char *file, int mode, int print_error, int fail_on_error)
 {
     int status;
+    void *handle;
 
-    status = dlr_check_file_compatibility(file);
+    status = dlr_check_file_compatibility(file, &handle);
     if (status == -ENOENT) { /* file cannot be loaded (does not exist) */
         return NULL;
     } else if (status < 0) { /* other error while checking compatibility */
@@ -556,17 +575,24 @@ void* dlr_dlopen_extended(const char *file, int mode, int print_error, int fail_
             dlr_print_pretty_error(file);
         }
         if (fail_on_error) {
+            if (handle != NULL) {
+                dlclose(handle);
+            }
             return NULL;
         }
     } else if (status == 0) { /* library is not compatible */
         if (print_error) {
             dlr_print_pretty_error(file);
         }
+        dlclose(handle);
         return NULL;
     }
 
     /* Else either library is compatible or fail_on_error is disabled
-       Just dlopen() the library.
+       Just (re)dlopen() the library if needed.
     */
-    return dlopen(file, mode);
+    if (mode != (RTLD_LAZY | RTLD_LOCAL)) {
+        handle = dlopen(file, mode);
+    }
+    return handle;
 }
diff --git a/dlrestrictions/dlrestrictions.h b/dlrestrictions/dlrestrictions.h
index 7fe4a9b..392d98d 100644
--- a/dlrestrictions/dlrestrictions.h
+++ b/dlrestrictions/dlrestrictions.h
@@ -64,7 +64,11 @@ void dlr_print_pretty_error(const char *context);
    Public function for verification of the given library file against global
    symbol object.
 
-   * file - same as to dlopen();
+   * file - if present, the file to dlopen(); if omitted, the handle parameter
+            will be used.
+   * handle - if not NULL, the handle of the dlopen()'ed file will be stored here
+              (and the object won't be dlclose()'ed). If file is NULL, handle must
+              be non-NULL and point to the already open shared object.
    * Return value:
       < 0 - error occured while checking compatibility:
           * -ENOENT - unable to open file;
@@ -73,7 +77,7 @@ void dlr_print_pretty_error(const char *context);
      == 0 - library and its dependencies are NOT compatible with global object;
       > 0 - library and its dependencies are compatible with global object;
 */
-int dlr_check_file_compatibility(const char *file);
+int dlr_check_file_compatibility(const char *file, void **handle);
 
 /*
    An extended wrapper around dlopen() with integrated file compatibility checking.

-- 
Debian Qt/KDE packaging tools



More information about the pkg-kde-commits mailing list