LCOV - code coverage report
Current view: top level - misc/kabi/lvm2.git/lib/misc - sharedlib.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 0 18 0.0 %
Date: 2010-04-13 Functions: 0 2 0.0 %
Branches: 0 16 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved.
       3                 :            :  * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
       4                 :            :  *
       5                 :            :  * This file is part of LVM2.
       6                 :            :  *
       7                 :            :  * This copyrighted material is made available to anyone wishing to use,
       8                 :            :  * modify, copy, or redistribute it subject to the terms and conditions
       9                 :            :  * of the GNU Lesser General Public License v.2.1.
      10                 :            :  *
      11                 :            :  * You should have received a copy of the GNU Lesser General Public License
      12                 :            :  * along with this program; if not, write to the Free Software Foundation,
      13                 :            :  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      14                 :            :  */
      15                 :            : 
      16                 :            : #include "lib.h"
      17                 :            : #include "config.h"
      18                 :            : #include "lvm-string.h"
      19                 :            : #include "sharedlib.h"
      20                 :            : #include "toolcontext.h"
      21                 :            : 
      22                 :            : #include <limits.h>
      23                 :            : #include <sys/stat.h>
      24                 :            : #include <dlfcn.h>
      25                 :            : 
      26                 :          0 : void get_shared_library_path(struct cmd_context *cmd, const char *libname,
      27                 :            :                              char *path, size_t path_len)
      28                 :            : {
      29                 :            :         struct stat info;
      30                 :            :         const char *lib_dir;
      31                 :            : 
      32                 :            :         /* If libname doesn't begin with '/' then use lib_dir/libname,
      33                 :            :          * if present */
      34 [ #  #  #  #  # :          0 :         if (libname[0] == '/' ||
                #  #  # ]
      35                 :          0 :             !(lib_dir = find_config_tree_str(cmd, "global/library_dir", 0)) ||
      36                 :          0 :             (dm_snprintf(path, path_len, "%s/%s", lib_dir,
      37                 :          0 :                           libname) == -1) || stat(path, &info) == -1)
      38                 :          0 :                 strncpy(path, libname, path_len);
      39                 :          0 : }
      40                 :            : 
      41                 :          0 : void *load_shared_library(struct cmd_context *cmd, const char *libname,
      42                 :            :                           const char *desc, int silent)
      43                 :            : {
      44                 :            :         char path[PATH_MAX];
      45                 :            :         void *library;
      46                 :            : 
      47         [ #  # ]:          0 :         if (is_static()) {
      48                 :          0 :                 log_error("Not loading shared %s library %s in static mode.",
      49                 :            :                           desc, libname);
      50                 :          0 :                 return NULL;
      51                 :            :         }
      52                 :            : 
      53                 :          0 :         get_shared_library_path(cmd, libname, path, sizeof(path));
      54                 :            : 
      55                 :          0 :         log_very_verbose("Opening shared %s library %s", desc, path);
      56                 :            : 
      57         [ #  # ]:          0 :         if (!(library = dlopen(path, RTLD_LAZY | RTLD_GLOBAL))) {
      58 [ #  # ][ #  # ]:          0 :                 if (silent && ignorelockingfailure())
      59                 :          0 :                         log_verbose("Unable to open external %s library %s: %s",
      60                 :            :                                     desc, path, dlerror());
      61                 :            :                 else
      62                 :          0 :                         log_error("Unable to open external %s library %s: %s",
      63                 :            :                                   desc, path, dlerror());
      64                 :            :         }
      65                 :            : 
      66                 :          0 :         return library;
      67                 :            : }

Generated by: LCOV version 1.8