chg: [pibs] Move memory management fonctions in memutils.c

master
Gerard Wagener 2019-04-10 14:39:16 +02:00
parent 130854cf6e
commit 2226c6c383
2 changed files with 6 additions and 71 deletions

View File

@ -1,5 +1,9 @@
pibs: pibs.o pibs: pibs.o memutils.o
gcc -Wall -o pibs pibs.o -lwiretap `pkg-config --libs glib-2.0` -lpcap -lhiredis -ggdb gcc -Wall -o pibs pibs.o memutils.o -lwiretap `pkg-config --libs glib-2.0` -lpcap -lhiredis -ggdb
memutils.o: memutils.c
gcc -Wall -c memutils.c `pkg-config --cflags glib-2.0` -I /usr/include/wireshark/wiretap -I /usr/include/wireshark/wsutil -I /usr/include/wireshark `pkg-config --libs glib-2.0` -I /usr/local/include/hiredis -ggdb
pibs.o: pibs.c pibs.o: pibs.c
gcc -D HASHDEBUG=0 -Wall -c pibs.c `pkg-config --cflags glib-2.0` -I /usr/include/wireshark/wiretap -I /usr/include/wireshark/wsutil -I /usr/include/wireshark `pkg-config --libs glib-2.0` -I /usr/local/include/hiredis -ggdb gcc -D HASHDEBUG=0 -Wall -c pibs.c `pkg-config --cflags glib-2.0` -I /usr/include/wireshark/wiretap -I /usr/include/wireshark/wsutil -I /usr/include/wireshark `pkg-config --libs glib-2.0` -I /usr/local/include/hiredis -ggdb

View File

@ -19,77 +19,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "pibs.h" #include "pibs.h"
int load_shmid_file(pibs_t* pibs)
{
FILE* fp;
if (pibs->shmid_file[0]) {
fp = fopen(pibs->shmid_file,"r");
if (fp) {
//FIXME check file
fscanf(fp, "%d", &pibs->shmid);
return pibs->shmid;
}
} else {
pibs->errno_pibs = ERR_NO_SHMID_FILE;
}
return -1;
}
//TODO when attaching the next_item must be recovered if results //TODO when attaching the next_item must be recovered if results
//of previous runs need to be increased //of previous runs need to be increased
int pibs_shmat(pibs_t* pibs)
{
/* FIXME init function needs to break up in two functions. One that
* initializes internal pibs structures as cli options etc
* a second one for describing the data itself, size of bin_table
* number of items etc.
*/
if (pibs->data) {
free(pibs->data);
pibs->data = NULL;
}
if (pibs->data) {
pibs->errno_pibs = ERR_ATTACH_NOT_EMPTY;
printf("TEST Data is not null\n");
return -1;
}
if (!pibs->shmid_file[0]) {
pibs->errno_pibs = ERR_NO_SHMID_FILE;
return -1;
}
if (load_shmid_file(pibs) > 0) {
pibs->data = shmat(pibs->shmid, NULL, SHM_RND);
if ( (int) pibs->data == -1) {
pibs->errno_copy = errno;
} else {
return 1;
}
}
// Something did not work
return -1;
}
int pibs_shmget(pibs_t* pibs)
{
FILE* fp;
pibs->shmid = shmget(IPC_PRIVATE, pibs->data_size, IPC_CREAT | 0600);
if (pibs->shmid < 0) {
pibs->errno_copy = errno;
}
if (pibs->shmid_file[0]){
fp = fopen(pibs->shmid_file, "w");
if (fp) {
fprintf(fp,"%d",pibs->shmid);
fclose(fp);
}
//TODO error handling
}
//TODO attach to it and bzero it
//setup the tables
return pibs->shmid;
}
/* /*
* Returns -1 if not found * Returns -1 if not found
* returns last timestamp if found * returns last timestamp if found