From 2226c6c383836f0ea31a0b3908a17bbcfb92b5f3 Mon Sep 17 00:00:00 2001 From: Gerard Wagener Date: Wed, 10 Apr 2019 14:39:16 +0200 Subject: [PATCH] chg: [pibs] Move memory management fonctions in memutils.c --- bin/Makefile | 8 ++++-- bin/pibs.c | 69 ---------------------------------------------------- 2 files changed, 6 insertions(+), 71 deletions(-) diff --git a/bin/Makefile b/bin/Makefile index c064bdb..a8e1398 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -1,5 +1,9 @@ -pibs: pibs.o - gcc -Wall -o pibs pibs.o -lwiretap `pkg-config --libs glib-2.0` -lpcap -lhiredis -ggdb +pibs: pibs.o memutils.o + 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 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 diff --git a/bin/pibs.c b/bin/pibs.c index 3183c77..d9caa50 100644 --- a/bin/pibs.c +++ b/bin/pibs.c @@ -19,77 +19,8 @@ * along with this program. If not, see . */ #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 //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 last timestamp if found