int
p4_dlslot_open (const char* nameptr, int namelen)
{
int slot;
void* dll = 0;
char systemonly = 0;
# ifdef VxWorks
static volatile SEM_ID mutex;
static int timeout;
register SEM_ID my_mutex = 0;
if (! timeout) timeout = 2000 * CLOCKS_PER_SEC;
if (! mutex) mutex = my_mutex = semMCreate (0);
if (! mutex) {
P4_fatal ("PANIC: no sem-id from semMCreate!!" );
return -ECONNREFUSED;
}
if (my_mutex && my_mutex != mutex) {
P4_fatal ("PANIC: race detected, doubled smMCreate!!" );
return -EISCONN;
}
if (semTake (mutex, timeout)) {
P4_fatal ("PANIC: semTake failed (timeout? invalid?)" );
return -ETIMEDOUT;
}
# define mutexGive() semGive(mutex)
# else
# define mutexGive()
# endif
if (*nameptr == '\t' ) {
P4_debug (13,"system only..." );
systemonly=1;
nameptr++; namelen--;
}
if ((slot= p4_dlslot_find (nameptr, namelen)))
{
p4_dlslot_table[slot].use++;
P4_info2 ("module already loaded: [%i] '%s'" ,
slot, p4_dlslot_table[slot].name);
mutexGive ();
return slot;
}
slot= p4_dlslot_create (nameptr, namelen);
P4_enter1 ("loading '%s'" , p4_dlslot_table[slot].name);
if (! strchr (p4_dlslot_table[slot].name, '/' )
&& ! strchr (p4_dlslot_table[slot].name, ':' ))
{
char named[255]; int len;
strcpy (named, PFE_MODULE_DIR); len = strlen(named);
if (named[len-1] != '/' && named[len-1] != '\\' && named[len-1] != ':' )
strncat (named, PFE_DIR_DELIMSTR, 255);
strncat (named, p4_dlslot_table[slot].name, 255);
if (memchr (named, '\0' , 255))
{
dll = p4_dlopenext (named);
# ifdef _CHECKDLL
if (! dll)
P4_warn1 ("%s" , p4_dlerror ());
# endif
if (systemonly)
goto skipdirectpath;
}
}
if (! dll)
dll = p4_dlopenext (p4_dlslot_table[slot].name);
skipdirectpath:
if (! dll)
{
# ifdef _CHECKDLL
P4_warn1 ("%s" , p4_dlerror ());
# else
p4_dlerror ();
# endif
p4_dlslot_remove (slot);
mutexGive ();
return -ENOENT;
}
p4_dlslot_table[slot].dlptr = dll;
p4_dlslot_table[slot].llist = p4_dlsym (dll, "p4_LTX_p4_MODULE" );
if (p4_dlslot_isnt_unique_llist (slot))
p4_dlslot_table[slot].llist = NULL;
if (!p4_dlslot_table[slot].llist)
{
P4_fail1 ("'%s': cannot find modules loadlist" ,
p4_dlslot_table[slot].name);
p4_dlclose (dll);
p4_dlslot_remove (slot);
mutexGive ();
return -ESRCH;
}
P4_leave1 (" dlslot = %i" , slot);
mutexGive ();
return slot;
# undef mutexGive
} |