Macros | Functions | Variables
mod_raw.cc File Reference
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <sys/stat.h>
#include <errno.h>
#include <unistd.h>
#include <misc/auxiliary.h>
#include <omalloc/omalloc.h>
#include <reporter/reporter.h>
#include <resources/feResource.h>
#include "mod_raw.h"
#include <dlfcn.h>

Go to the source code of this file.

Macros

#define DL_TAIL   ".so"
 
#define DL_IMPLEMENTED
 

Functions

void * dynl_open_binary_warn (const char *binary_name, const char *msg)
 
void * dynl_sym_warn (void *handle, const char *proc, const char *msg)
 
int dynl_check_opened (char *filename)
 
void * dynl_open (char *filename)
 
void * dynl_sym (void *handle, const char *symbol)
 
int dynl_close (void *handle)
 
const char * dynl_error ()
 

Variables

static BOOLEAN warn_handle = FALSE
 
static BOOLEAN warn_proc = FALSE
 
static void * kernel_handle = NULL
 

Macro Definition Documentation

#define DL_IMPLEMENTED

Definition at line 147 of file mod_raw.cc.

#define DL_TAIL   ".so"

Definition at line 55 of file mod_raw.cc.

Function Documentation

int dynl_check_opened ( char *  filename)

Definition at line 150 of file mod_raw.cc.

153 {
154  return dlopen(filename,RTLD_NOW|RTLD_NOLOAD) != NULL;
155 }
#define NULL
Definition: omList.c:10
int dynl_close ( void *  handle)

Definition at line 182 of file mod_raw.cc.

183 {
184  return(dlclose (handle));
185 }
const char* dynl_error ( )

Definition at line 187 of file mod_raw.cc.

188 {
189  return(dlerror());
190 }
void* dynl_open ( char *  filename)

Definition at line 157 of file mod_raw.cc.

160 {
161 // glibc 2.2:
162  if ((filename==NULL) || (dlopen(filename,RTLD_NOW|RTLD_NOLOAD)==NULL))
163  return(dlopen(filename, RTLD_NOW|RTLD_GLOBAL));
164  else
165  Werror("module %s already loaded",filename);
166  return NULL;
167 // alternative
168 // return(dlopen(filename, RTLD_NOW|RTLD_GLOBAL));
169 }
#define NULL
Definition: omList.c:10
void Werror(const char *fmt,...)
Definition: reporter.cc:199
void* dynl_open_binary_warn ( const char *  binary_name,
const char *  msg 
)

Definition at line 60 of file mod_raw.cc.

61 {
62  void* handle = NULL;
63  char* binary_name_so=NULL;
65 
66  // try P_PROCS_DIR (%P)
67  char* proc_path = feGetResource('P');
68  if (proc_path != NULL)
69  {
70  char *p;
71  char *q;
72  p=proc_path;
73  int binary_name_so_length = 3 + strlen(DL_TAIL) + strlen(binary_name) + strlen(DIR_SEPP) + strlen(proc_path);
74  binary_name_so = (char *)omAlloc0( binary_name_so_length * sizeof(char) );
75  while((p!=NULL)&&(*p!='\0'))
76  {
77  q=strchr(p,fePathSep);
78  if (q!=NULL) *q='\0';
79  strcpy(binary_name_so,p);
80  if (q!=NULL) *q=fePathSep;
81  strcat(binary_name_so,DIR_SEPP);
82  strcat(binary_name_so,binary_name);
83  strcat(binary_name_so,DL_TAIL);
84  if(!access(binary_name_so, R_OK)) { found=TRUE; break; }
85  if (q!=NULL) p=q+1; else p=NULL;
86  }
87  if (found) handle = dynl_open(binary_name_so);
88  }
89 
90  if (handle == NULL && ! warn_handle)
91  {
92  Warn("Could not find dynamic library: %s%s (path %s)",
93  binary_name, DL_TAIL,proc_path);
94  if (found) Warn("Error message from system: %s", dynl_error());
95  if (msg != NULL) Warn("%s", msg);
96  Warn("See the INSTALL section in the Singular manual for details.");
97  warn_handle = TRUE;
98  }
99  omfree((ADDRESS)binary_name_so );
100 
101  return handle;
102 }
#define DL_TAIL
Definition: mod_raw.cc:55
#define FALSE
Definition: auxiliary.h:140
return P p
Definition: myNF.cc:203
#define TRUE
Definition: auxiliary.h:144
void * ADDRESS
Definition: auxiliary.h:161
const char fePathSep
Definition: feResource.h:57
void * dynl_open(char *filename)
Definition: mod_raw.cc:157
bool found
Definition: facFactorize.cc:56
static BOOLEAN warn_handle
Definition: mod_raw.cc:49
char * feGetResource(const char id, int warn)
Definition: feResource.cc:149
#define omfree(addr)
Definition: omAllocDecl.h:237
#define DIR_SEPP
Definition: feResource.h:7
#define NULL
Definition: omList.c:10
int BOOLEAN
Definition: auxiliary.h:131
#define omAlloc0(size)
Definition: omAllocDecl.h:211
const char * dynl_error()
Definition: mod_raw.cc:187
#define Warn
Definition: emacs.cc:80
void* dynl_sym ( void *  handle,
const char *  symbol 
)

Definition at line 171 of file mod_raw.cc.

172 {
173  if (handle == DYNL_KERNEL_HANDLE)
174  {
175  if (kernel_handle == NULL)
177  handle = kernel_handle;
178  }
179  return(dlsym(handle, symbol));
180 }
static void * kernel_handle
Definition: mod_raw.cc:149
void * dynl_open(char *filename)
Definition: mod_raw.cc:157
#define NULL
Definition: omList.c:10
#define DYNL_KERNEL_HANDLE
Definition: mod_raw.h:32
void* dynl_sym_warn ( void *  handle,
const char *  proc,
const char *  msg 
)

Definition at line 104 of file mod_raw.cc.

105 {
106  void *proc_ptr = NULL;
107  if (handle != NULL)
108  {
109  proc_ptr = dynl_sym(handle, proc);
110  if (proc_ptr == NULL && ! warn_proc)
111  {
112  Warn("Could load a procedure from a dynamic library");
113  Warn("Error message from system: %s", dynl_error());
114  if (msg != NULL) Warn("%s", msg);
115  Warn("See the INSTALL section in the Singular manual for details.");
116  warn_proc = TRUE;
117  }
118  }
119  return proc_ptr;
120 }
#define TRUE
Definition: auxiliary.h:144
void * dynl_sym(void *handle, const char *symbol)
Definition: mod_raw.cc:171
static BOOLEAN warn_proc
Definition: mod_raw.cc:50
#define NULL
Definition: omList.c:10
const char * dynl_error()
Definition: mod_raw.cc:187
#define Warn
Definition: emacs.cc:80

Variable Documentation

void* kernel_handle = NULL
static

Definition at line 149 of file mod_raw.cc.

BOOLEAN warn_handle = FALSE
static

Definition at line 49 of file mod_raw.cc.

BOOLEAN warn_proc = FALSE
static

Definition at line 50 of file mod_raw.cc.