Commit f1716d8c authored by 's avatar
Browse files

the .mapidfunc-shm-* file created by mapid_init for the creation of each...

the .mapidfunc-shm-* file created by mapid_init for the creation of each shared memory key was not being removed, which was cluttering /tmp

git-svn-id: file:///home/svn/mapi/trunk@869 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 898e73c5
......@@ -28,7 +28,7 @@ typedef struct mapidlibflow {
short delete;
flist_t *functionlist;
flist_t *procfunctionlist;
mapid_funct_info_t *funct_info_list;
mapid_funct_info_t *funct_info_list;
mapid_hw_info_t *hwinfo; //Information about hardware using mapidlib
char devtype[MAPI_STR_LENGTH];
void* adapterinfo; //Pointer to adapter specific information
......@@ -63,14 +63,14 @@ static void free_functionlist(struct mapidlibflow *f);
static char* mapid_conf;
int
mapid_init(mapidlib_instance_t *i)
mapid_init(mapidlib_instance_t *i)
//Set hw info
//infor = pointer to info
{
char buf[1024],*str,*s;
char pathname[MAPI_STR_LENGTH];
int fd;
//Copy devtype
/*
i->flowlist=malloc(sizeof(flist_t));
......@@ -127,26 +127,26 @@ mapid_init(mapidlib_instance_t *i)
strncpy(pathname,FUNCTION_SHM_TEMPLATE,MAPI_STR_LENGTH);
if(mktemp(pathname)==NULL)
return MDLIB_SHM_ERR;
umask(017);
if((fd=open(pathname,O_CREAT|O_EXCL,FUNCTION_SHM_PERMS))<0)
return MDLIB_SHM_ERR;
else
else
close(fd);
strncpy(i->shm_spinlock_fname,pathname,MAPI_STR_LENGTH);
if((i->shm_spinlock_key=ftok(pathname,FUNCTION_SHM_PROJECT_ID))<0)
return MDLIB_SHM_ERR;
if((i->shm_spinlock_id=shmget(i->shm_spinlock_key,sizeof(pthread_spinlock_t),FUNCTION_SHM_PERMS | IPC_CREAT)) < 0)
return MDLIB_SHM_ERR;
if((i->shm_spinlock=shmat(i->shm_spinlock_id,0,0))==NULL)
return MDLIB_SHM_ERR;
//Initialize spinlock
pthread_spin_init (i->shm_spinlock, PTHREAD_PROCESS_SHARED);
pthread_spin_init (i->shm_spinlock, PTHREAD_PROCESS_SHARED);
i->shm_spinlock_size=sizeof(pthread_spinlock_t);
return 0;
......@@ -170,7 +170,7 @@ static int mapid_add_funct(mapidlib_instance_t *i, int fd, char *funct, ...)
va_list vl;
mapiFunctArg *pos;
mapiFunctArg args[FUNCTARGS_BUF_SIZE];
pos=args;
va_start(vl,funct);
......@@ -217,7 +217,7 @@ static void fix_funct_ref(global_function_list_t *gflist,mapidflib_function_t *i
functions=((mapid_flow_info_t*)flist_data(flow))->flist;
if(functions==NULL)
continue;
for(fnode=flist_head(functions); fnode!=NULL; fnode=flist_next(fnode)) {
funct=(mapidflib_function_t*)flist_data(fnode);
if(funct->instance==ifunct->instance) {
......@@ -233,9 +233,6 @@ static void fix_funct_ref(global_function_list_t *gflist,mapidflib_function_t *i
}
//Deletes a flow and frees all resources allocated by the flow
static void delete_flow(mapidlib_instance_t *i,struct mapidlibflow *flow) {
struct mapidlibflow *f;
......@@ -245,9 +242,7 @@ static void delete_flow(mapidlib_instance_t *i,struct mapidlibflow *flow) {
mapidflib_function_t *funct;
pthread_spinlock_t *lock;
DEBUG_CMD(printf("Deleting flow %d [%s:%d]\n",flow->fd,__FILE__,__LINE__));
//global optimization
temp = (void*)flist_get(flow->hwinfo->gflist->fflist,flow->fd);
......@@ -255,14 +250,13 @@ static void delete_flow(mapidlib_instance_t *i,struct mapidlibflow *flow) {
fprintf(stderr,"ERROR!! Trying to delete a flow that doesnt exist...");
return;
}
functions= ((mapid_flow_info_t*)temp)->flist;
if(functions!=NULL)
for(funct_node=flist_head(functions);funct_node!=NULL;funct_node=flist_next(funct_node)) {
funct=(mapidflib_function_t*)flist_data(funct_node);
if(funct->ref==0 && funct->instance->refcount>0 )
//Check to see if other functions references this function
fix_funct_ref(flow->hwinfo->gflist,funct);
fix_funct_ref(flow->hwinfo->gflist,funct);
}
#ifdef WITH_MODIFY_PKTS
......@@ -272,28 +266,27 @@ static void delete_flow(mapidlib_instance_t *i,struct mapidlibflow *flow) {
lock=&flow->hwinfo->gflist->lock;
pthread_spin_lock(lock);
#ifdef WITH_PRIORITIES
f=flist_remove(i->flowlist[flow->priority],flow->fd);
#else
f=flist_remove(i->flowlist,flow->fd);
#endif
free_functionlist(f);
free_functionlist(f);
free_sharedmem(f);
free(f);
pthread_spin_unlock(lock);
}
//Frees resources allocated by mapidlib, should be called by the drivers when devices are deleted
void mapid_destroy(mapidlib_instance_t *i)
{
flist_node_t *n;
struct mapidlibflow *f;
if (i!=NULL) {
// pthread_spin_lock(i->shm_spinlock);
// n=flist_head(i->flowlist);
......@@ -305,13 +298,13 @@ void mapid_destroy(mapidlib_instance_t *i)
#else
n=flist_head(i->flowlist);
#endif
while (n!=NULL) {
f=flist_data(n);
n=flist_next(n);
n=flist_next(n);
delete_flow(i,f);
}
// flist_destroy(i->flowlist);
#ifdef WITH_PRIORITIES
flist_destroy(i->flowlist[j]);
......@@ -331,7 +324,13 @@ void mapid_destroy(mapidlib_instance_t *i)
WARNING_CMD(printf("Warning: Could not free shared mem (%s) [%s:%d]\n",strerror(errno),__FILE__,__LINE__));
}
}
// remove the temporary file that was created by mapid_init for the
// creation of the shared memory key
if (unlink(i->shm_spinlock_fname) != 0) {
WARNING_CMD(printf("Warning: Could not remove shm key file %s (%s) [%s:%d]\n",
i->shm_spinlock_fname, strerror(errno),__FILE__,__LINE__));
}
}
else if (libs_loaded>0) {
mapilh_free_libraries();
libs_loaded=0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment