forked from big-data-lab-team/Sea
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from ValHayot/tristan
merging all recent changes to master
- Loading branch information
Showing
27 changed files
with
2,970 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
*.o | ||
*.so | ||
*.gcda | ||
*.gcno | ||
sea.ini | ||
sea.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,20 @@ | ||
all: passthrough.so | ||
gcc_opts=-Wall -fPIC -c -std=c++0x | ||
debug_opts=-g -ggdb | ||
all: passthrough.so test | ||
config.o: config.cpp | ||
gcc ${gcc_opts} ${debug_opts} config.cpp | ||
passthrough.o: passthrough.cpp passthrough.h | ||
gcc -Wall -fPIC -g -c -ggdb passthrough.cpp | ||
gcc ${gcc_opts} ${debug_opts} passthrough.cpp | ||
sea.o: sea.cpp sea.h | ||
gcc ${gcc_opts} ${debug_opts} sea.cpp | ||
functions.o: functions.cpp functions.h | ||
gcc -Wall -fPIC -g -c -ggdb functions.cpp | ||
gcc ${gcc_opts} ${debug_opts} functions.cpp | ||
logger.o: logger.cpp logger.h | ||
gcc -Wall -fPIC -g -c -ggdb logger.cpp | ||
passthrough.so: passthrough.o functions.o logger.o | ||
gcc -shared passthrough.o functions.o logger.o -g -o passthrough.so -ldl -lpthread -ggdb -lstdc++ | ||
gcc ${gcc_opts} ${debug_opts} logger.cpp | ||
passthrough.so: passthrough.o functions.o logger.o config.o sea.o | ||
gcc -shared passthrough.o functions.o logger.o config.o sea.o ${debug_opts} -o passthrough.so -ldl -lpthread -lstdc++ -liniparser | ||
test_custom.o: tests/test_custom.cpp passthrough.o sea.o config.o logger.o | ||
gcc ${debug_opts} -std=c++11 -Wall -fPIC tests/test_custom.cpp passthrough.o sea.o config.o logger.o -o tests/test_custom -lstdc++ -liniparser -ldl -lgtest -lpthread | ||
test: test_custom.o | ||
clean: | ||
\rm -f logger.o functions.o passthrough.o passthrough.so | ||
\rm -f logger.o functions.o passthrough.o config.o sea.o passthrough.so *.gcda *.gcov *.gcno tests/test_custom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
extern "C"{ | ||
#include <iniparser.h> | ||
} | ||
#include <linux/limits.h> | ||
#include <sys/stat.h> | ||
#include "config.h" | ||
#include "logger.h" | ||
#include "passthrough.h" | ||
|
||
struct config sea_config; | ||
|
||
char * get_sea_home() | ||
{ | ||
char* sea_home; | ||
sea_home = getenv("SEA_HOME"); | ||
if(sea_home == NULL) | ||
{ | ||
printf("SEA_HOME is not defined\n"); | ||
exit(1); | ||
} | ||
return sea_home; | ||
} | ||
|
||
char * get_config_file() | ||
{ | ||
char * sea_home = get_sea_home(); | ||
static char config_file[PATH_MAX]; | ||
strcpy(config_file, sea_home); | ||
strcat(config_file,"/sea.ini"); | ||
return config_file; | ||
} | ||
|
||
void create_config_file(char * config_file) | ||
{ | ||
char * sea_home = get_sea_home(); | ||
FILE * ini ; | ||
if ((ini=fopen(config_file, "w"))==NULL) { | ||
printf("ERROR: cannot create %s\n", config_file); | ||
exit(1); | ||
} | ||
|
||
fprintf(ini, | ||
"#\n" | ||
"# Sea configuration\n" | ||
"#\n" | ||
"[Sea]\n" | ||
"mount_dir = %s/mount_dir ; # use absolute paths\n" | ||
"log_file = %s/sea.log ;\n" | ||
"log_level = 1 ; # DEBUG=4, INFO=3, WARNING=2, ERROR=1, NONE=0 (use <= 3 tests)\n" | ||
"n_sources = 1 ;\n" | ||
"source_0 = %s/source ; # use absolute paths\n" | ||
"\n", sea_home, sea_home, sea_home); | ||
fclose(ini); | ||
} | ||
|
||
void parse_config() | ||
{ | ||
char * config_file = get_config_file(); | ||
bool exists = (((funcptr_access) libc_access)(config_file, F_OK ) != -1); | ||
if(!exists) | ||
{ | ||
create_config_file(config_file); | ||
printf("WARNING: Couldn't find config file %s so I created it" | ||
" for you (you should really check it).\n", config_file); | ||
} | ||
dictionary * config_dict = iniparser_load(config_file); | ||
if(config_dict == 0) | ||
{ | ||
printf("Cannot load config file %s\n", config_file); | ||
exit(1); | ||
} | ||
if((sea_config.n_sources = iniparser_getint(config_dict, "sea:n_sources", 0))==0) | ||
{ | ||
printf("Missing n_sources in config file %s\n", config_file); | ||
exit(1); | ||
} | ||
sea_config.source_mounts = new char* [sea_config.n_sources]; | ||
for(int i = 0 ; i < sea_config.n_sources ; i++) | ||
{ | ||
char source_name[15]; | ||
sprintf(source_name, "sea:source_%d", i); | ||
//sea_config.source_mounts[i] = new char[PATH_MAX]; | ||
if((sea_config.source_mounts[i] = (char *) iniparser_getstring(config_dict, source_name, NULL))==0) | ||
{ | ||
printf("Missing %s in config file %s\n", source_name, config_file); | ||
exit(1); | ||
} | ||
// add '/' to the end of source mount path if missing | ||
//if (sea_config.source_mounts[i][strlen(sea_config.source_mounts[i])-1] != '/') | ||
// strcat(sea_config.source_mounts[i], "/"); | ||
} | ||
if((sea_config.mount_dir = (char *) iniparser_getstring(config_dict, "sea:mount_dir", NULL))==0) | ||
{ | ||
printf("Missing mount_dir in config file %s\n", config_file); | ||
exit(1); | ||
} | ||
if((sea_config.log_file = (char *) iniparser_getstring(config_dict, "sea:log_file", NULL))==0) | ||
{ | ||
printf("Missing log_file in config file %s\n", config_file); | ||
exit(1); | ||
} | ||
|
||
// add '/' to the end of mount path | ||
//if (sea_config.mount_dir[strlen(sea_config.mount_dir)-1] != '/') | ||
// strcat(sea_config.mount_dir, "/"); | ||
sea_config.log_level = iniparser_getint(config_dict, "sea:log_level", 1); | ||
sea_config.parsed = true; | ||
} | ||
|
||
config get_sea_config() | ||
{ | ||
if(!sea_config.parsed) | ||
{ | ||
parse_config(); | ||
} | ||
|
||
return sea_config; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef CONFIG_H | ||
#define CONFIG_H | ||
|
||
typedef struct config | ||
{ | ||
bool parsed; | ||
int n_sources; | ||
char ** source_mounts; | ||
char * mount_dir; | ||
char * log_file; | ||
int log_level; | ||
} config; | ||
|
||
char * get_config_file(); | ||
struct config get_sea_config(); | ||
|
||
#endif |
Oops, something went wrong.