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 "reporter/reporter.h"
#include "resources/feResource.h"
#include "omalloc/omalloc.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_VAR BOOLEAN warn_handle = FALSE
 
STATIC_VAR BOOLEAN warn_proc = FALSE
 
STATIC_VAR void * kernel_handle = NULL
 

Macro Definition Documentation

◆ DL_IMPLEMENTED

#define DL_IMPLEMENTED

Definition at line 135 of file mod_raw.cc.

◆ DL_TAIL

#define DL_TAIL   ".so"

Definition at line 44 of file mod_raw.cc.

Function Documentation

◆ dynl_check_opened()

int dynl_check_opened ( char *  filename)

Definition at line 138 of file mod_raw.cc.

141 {
142  return dlopen(filename,RTLD_NOW|RTLD_NOLOAD) != NULL;
143 }
#define NULL
Definition: omList.c:12

◆ dynl_close()

int dynl_close ( void *  handle)

Definition at line 173 of file mod_raw.cc.

174 {
175  return(dlclose (handle));
176 }

◆ dynl_error()

const char* dynl_error ( )

Definition at line 178 of file mod_raw.cc.

179 {
180  return(dlerror());
181 }

◆ dynl_open()

void* dynl_open ( char *  filename)

Definition at line 145 of file mod_raw.cc.

148 {
149  return dlopen(filename, RTLD_NOW|RTLD_GLOBAL);
150 #if 0
151 // glibc 2.2:
152  if ((filename==NULL) || (dlopen(filename,RTLD_NOW|RTLD_NOLOAD)==NULL))
153  return(dlopen(filename, RTLD_NOW|RTLD_GLOBAL));
154  else
155  Werror("module %s already loaded",filename);
156  return NULL;
157 // alternative
158 // return(dlopen(filename, RTLD_NOW|RTLD_GLOBAL));
159 #endif
160 }
#define NULL
Definition: omList.c:12
void Werror(const char *fmt,...)
Definition: reporter.cc:189

◆ dynl_open_binary_warn()

void* dynl_open_binary_warn ( const char *  binary_name,
const char *  msg 
)

Definition at line 48 of file mod_raw.cc.

49 {
50  void* handle = NULL;
51  char* binary_name_so=NULL;
53 
54  // try P_PROCS_DIR (%P)
55  char* proc_path = feGetResource('P');
56  if (proc_path != NULL)
57  {
58  char *p;
59  char *q;
60  p=proc_path;
61  int binary_name_so_length = 3 + strlen(DL_TAIL) + strlen(binary_name) + strlen(DIR_SEPP) + strlen(proc_path);
62  binary_name_so = (char *)omAlloc0( binary_name_so_length * sizeof(char) );
63  while((p!=NULL)&&(*p!='\0'))
64  {
65  q=strchr(p,fePathSep);
66  if (q!=NULL) *q='\0';
67  strcpy(binary_name_so,p);
68  if (q!=NULL) *q=fePathSep;
69  strcat(binary_name_so,DIR_SEPP);
70  strcat(binary_name_so,binary_name);
71  strcat(binary_name_so,DL_TAIL);
72  if(!access(binary_name_so, R_OK)) { found=TRUE; break; }
73  if (q!=NULL) p=q+1; else p=NULL;
74  }
75  if (found) handle = dynl_open(binary_name_so);
76  }
77 
78  if (handle == NULL && ! warn_handle)
79  {
80  Warn("Could not find dynamic library: %s%s (path %s)",
81  binary_name, DL_TAIL,proc_path);
82  if (found) Warn("Error message from system: %s", dynl_error());
83  if (msg != NULL) Warn("%s", msg);
84  WarnS("See the INSTALL section in the Singular manual for details.");
85  warn_handle = TRUE;
86  }
87  omfree((ADDRESS)binary_name_so );
88 
89  return handle;
90 }
#define DL_TAIL
Definition: mod_raw.cc:44
#define FALSE
Definition: auxiliary.h:96
#define TRUE
Definition: auxiliary.h:100
void * ADDRESS
Definition: auxiliary.h:135
const char fePathSep
Definition: feResource.h:58
#define WarnS
Definition: emacs.cc:78
STATIC_VAR BOOLEAN warn_handle
Definition: mod_raw.cc:41
void * dynl_open(char *filename)
Definition: mod_raw.cc:145
bool found
Definition: facFactorize.cc:56
char * feGetResource(const char id, int warn)
Definition: feResource.cc:155
#define omfree(addr)
Definition: omAllocDecl.h:237
#define DIR_SEPP
Definition: feResource.h:7
#define NULL
Definition: omList.c:12
int p
Definition: cfModGcd.cc:4019
int BOOLEAN
Definition: auxiliary.h:87
#define omAlloc0(size)
Definition: omAllocDecl.h:211
const char * dynl_error()
Definition: mod_raw.cc:178
#define Warn
Definition: emacs.cc:77

◆ dynl_sym()

void* dynl_sym ( void *  handle,
const char *  symbol 
)

Definition at line 162 of file mod_raw.cc.

163 {
164  if (handle == DYNL_KERNEL_HANDLE)
165  {
166  if (kernel_handle == NULL)
168  handle = kernel_handle;
169  }
170  return(dlsym(handle, symbol));
171 }
void * dynl_open(char *filename)
Definition: mod_raw.cc:145
STATIC_VAR void * kernel_handle
Definition: mod_raw.cc:137
#define NULL
Definition: omList.c:12
#define DYNL_KERNEL_HANDLE
Definition: mod_raw.h:32

◆ dynl_sym_warn()

void* dynl_sym_warn ( void *  handle,
const char *  proc,
const char *  msg 
)

Definition at line 92 of file mod_raw.cc.

93 {
94  void *proc_ptr = NULL;
95  if (handle != NULL)
96  {
97  proc_ptr = dynl_sym(handle, proc);
98  if (proc_ptr == NULL && ! warn_proc)
99  {
100  WarnS("Could load a procedure from a dynamic library");
101  Warn("Error message from system: %s", dynl_error());
102  if (msg != NULL) Warn("%s", msg);
103  WarnS("See the INSTALL section in the Singular manual for details.");
104  warn_proc = TRUE;
105  }
106  }
107  return proc_ptr;
108 }
unsigned char * proc[NUM_PROC]
Definition: checklibs.c:16
#define TRUE
Definition: auxiliary.h:100
void * dynl_sym(void *handle, const char *symbol)
Definition: mod_raw.cc:162
#define WarnS
Definition: emacs.cc:78
#define NULL
Definition: omList.c:12
STATIC_VAR BOOLEAN warn_proc
Definition: mod_raw.cc:42
const char * dynl_error()
Definition: mod_raw.cc:178
#define Warn
Definition: emacs.cc:77

Variable Documentation

◆ kernel_handle

STATIC_VAR void* kernel_handle = NULL

Definition at line 137 of file mod_raw.cc.

◆ warn_handle

STATIC_VAR BOOLEAN warn_handle = FALSE

Definition at line 41 of file mod_raw.cc.

◆ warn_proc

STATIC_VAR BOOLEAN warn_proc = FALSE

Definition at line 42 of file mod_raw.cc.