| 1 |
/* |
| 2 |
* Copyright (c) 2002-2005, Network Appliance, Inc. All rights reserved. |
| 3 |
* |
| 4 |
* This Software is licensed under one of the following licenses: |
| 5 |
* |
| 6 |
* 1) under the terms of the "Common Public License 1.0" a copy of which is |
| 7 |
* in the file LICENSE.txt in the root directory. The license is also |
| 8 |
* available from the Open Source Initiative, see |
| 9 |
* http://www.opensource.org/licenses/cpl.php. |
| 10 |
* |
| 11 |
* 2) under the terms of the "The BSD License" a copy of which is in the file |
| 12 |
* LICENSE2.txt in the root directory. The license is also available from |
| 13 |
* the Open Source Initiative, see |
| 14 |
* http://www.opensource.org/licenses/bsd-license.php. |
| 15 |
* |
| 16 |
* 3) under the terms of the "GNU General Public License (GPL) Version 2" a |
| 17 |
* copy of which is in the file LICENSE3.txt in the root directory. The |
| 18 |
* license is also available from the Open Source Initiative, see |
| 19 |
* http://www.opensource.org/licenses/gpl-license.php. |
| 20 |
* |
| 21 |
* Licensee has the right to choose one of the above licenses. |
| 22 |
* |
| 23 |
* Redistributions of source code must retain the above copyright |
| 24 |
* notice and one of the license notices. |
| 25 |
* |
| 26 |
* Redistributions in binary form must reproduce both the above copyright |
| 27 |
* notice, one of the license notices in the documentation |
| 28 |
* and/or other materials provided with the distribution. |
| 29 |
*/ |
| 30 |
|
| 31 |
/********************************************************************** |
| 32 |
* |
| 33 |
* MODULE: dat_osd.c |
| 34 |
* |
| 35 |
* PURPOSE: Operating System Dependent layer |
| 36 |
* Description: |
| 37 |
* Provide OS dependent functions with a canonical DAPL |
| 38 |
* interface. Designed to be portable and hide OS specific quirks |
| 39 |
* of common functions. |
| 40 |
* |
| 41 |
* $Id: dat_osd.c,v 1.14 2005/04/25 17:29:41 jlentini Exp $ |
| 42 |
**********************************************************************/ |
| 43 |
|
| 44 |
#include "dat_osd.h" |
| 45 |
|
| 46 |
|
| 47 |
/********************************************************************* |
| 48 |
* * |
| 49 |
* Constants * |
| 50 |
* * |
| 51 |
*********************************************************************/ |
| 52 |
|
| 53 |
#define DAT_DBG_TYPE_ENV "DAT_DBG_TYPE" |
| 54 |
#define DAT_DBG_DEST_ENV "DAT_DBG_DEST" |
| 55 |
|
| 56 |
|
| 57 |
/********************************************************************* |
| 58 |
* * |
| 59 |
* Enumerations * |
| 60 |
* * |
| 61 |
*********************************************************************/ |
| 62 |
|
| 63 |
typedef int DAT_OS_DBG_DEST; |
| 64 |
|
| 65 |
typedef enum |
| 66 |
{ |
| 67 |
DAT_OS_DBG_DEST_STDOUT = 0x1, |
| 68 |
DAT_OS_DBG_DEST_SYSLOG = 0x2, |
| 69 |
DAT_OS_DBG_DEST_ALL = 0x3 |
| 70 |
} DAT_OS_DBG_DEST_TYPE; |
| 71 |
|
| 72 |
|
| 73 |
/********************************************************************* |
| 74 |
* * |
| 75 |
* Global Variables * |
| 76 |
* * |
| 77 |
*********************************************************************/ |
| 78 |
|
| 79 |
static DAT_OS_DBG_TYPE_VAL g_dbg_type = DAT_OS_DBG_TYPE_ERROR; |
| 80 |
static DAT_OS_DBG_DEST g_dbg_dest = DAT_OS_DBG_DEST_STDOUT; |
| 81 |
|
| 82 |
|
| 83 |
/*********************************************************************** |
| 84 |
* Function: dat_os_dbg_init |
| 85 |
***********************************************************************/ |
| 86 |
|
| 87 |
void |
| 88 |
dat_os_dbg_init ( void ) |
| 89 |
{ |
| 90 |
char *dbg_type; |
| 91 |
char *dbg_dest; |
| 92 |
|
| 93 |
if ( NULL != (dbg_type = dat_os_getenv (DAT_DBG_TYPE_ENV)) ) |
| 94 |
{ |
| 95 |
g_dbg_type = dat_os_strtol (dbg_type, NULL, 0); |
| 96 |
} |
| 97 |
|
| 98 |
if ( NULL != (dbg_dest = dat_os_getenv (DAT_DBG_DEST_ENV)) ) |
| 99 |
{ |
| 100 |
g_dbg_dest = dat_os_strtol (dbg_dest, NULL, 0); |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
/*********************************************************************** |
| 106 |
* Function: dat_os_dbg_print |
| 107 |
***********************************************************************/ |
| 108 |
|
| 109 |
void |
| 110 |
dat_os_dbg_print ( |
| 111 |
DAT_OS_DBG_TYPE_VAL type, |
| 112 |
const char * fmt, |
| 113 |
...) |
| 114 |
{ |
| 115 |
if (type & g_dbg_type) |
| 116 |
{ |
| 117 |
va_list args; |
| 118 |
|
| 119 |
if ( DAT_OS_DBG_DEST_STDOUT & g_dbg_dest ) |
| 120 |
{ |
| 121 |
va_start (args, fmt); |
| 122 |
vfprintf (stdout, fmt, args); |
| 123 |
fflush (stdout); |
| 124 |
va_end (args); |
| 125 |
} |
| 126 |
|
| 127 |
if ( DAT_OS_DBG_DEST_SYSLOG & g_dbg_dest ) |
| 128 |
{ |
| 129 |
va_start (args, fmt); |
| 130 |
vsyslog (LOG_USER | LOG_DEBUG, fmt, args); |
| 131 |
va_end (args); |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
/*********************************************************************** |
| 138 |
* Function: dat_os_library_load |
| 139 |
***********************************************************************/ |
| 140 |
|
| 141 |
DAT_RETURN |
| 142 |
dat_os_library_load ( |
| 143 |
const char *library_path, |
| 144 |
DAT_OS_LIBRARY_HANDLE *library_handle_ptr) |
| 145 |
{ |
| 146 |
DAT_OS_LIBRARY_HANDLE library_handle; |
| 147 |
|
| 148 |
if ( NULL != (library_handle = dlopen (library_path, RTLD_NOW | RTLD_GLOBAL)) ) |
| 149 |
{ |
| 150 |
if ( NULL != library_handle_ptr ) |
| 151 |
{ |
| 152 |
*library_handle_ptr = library_handle; |
| 153 |
} |
| 154 |
|
| 155 |
return DAT_SUCCESS; |
| 156 |
} |
| 157 |
else |
| 158 |
{ |
| 159 |
dat_os_dbg_print (DAT_OS_DBG_TYPE_GENERIC, |
| 160 |
"DAT: library load failure: %s\n", |
| 161 |
dlerror ()); |
| 162 |
return DAT_INTERNAL_ERROR; |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
/*********************************************************************** |
| 168 |
* Function: dat_os_library_unload |
| 169 |
***********************************************************************/ |
| 170 |
|
| 171 |
DAT_RETURN |
| 172 |
dat_os_library_unload ( |
| 173 |
const DAT_OS_LIBRARY_HANDLE library_handle) |
| 174 |
{ |
| 175 |
if ( 0 != dlclose (library_handle) ) |
| 176 |
{ |
| 177 |
return DAT_INTERNAL_ERROR; |
| 178 |
} |
| 179 |
else |
| 180 |
{ |
| 181 |
return DAT_SUCCESS; |
| 182 |
} |
| 183 |
} |