Skip to content

Commit

Permalink
Merge pull request #3 from ValHayot/tristan
Browse files Browse the repository at this point in the history
merging all recent changes to master
  • Loading branch information
ValHayot authored Jun 26, 2020
2 parents d06e8e7 + 4798916 commit f610194
Show file tree
Hide file tree
Showing 27 changed files with 2,970 additions and 197 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
*.o
*.so
*.gcda
*.gcno
sea.ini
sea.log
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ before_install:

install:
- docker run --rm -v $PWD:$PWD -w $PWD imagetest:${TAGNAME} make clean
- docker run --rm -v $PWD:$PWD -w $PWD imagetest:${TAGNAME} make
- docker run --rm -v $PWD:$PWD -w $PWD imagetest:${TAGNAME} make debug_opts="-g -ggdb --coverage -fprofile-arcs -ftest-coverage"

script:
- docker run --rm -v $PWD:$PWD -w $PWD imagetest:${TAGNAME} bats tests/tests.bats
- docker run --rm -v $PWD:$PWD -w $PWD -e SEA_HOME=$PWD imagetest:${TAGNAME} tests/test_custom

after_success:
- bash <(curl -s https://codecov.io/bash)
23 changes: 16 additions & 7 deletions Makefile
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
118 changes: 118 additions & 0 deletions config.cpp
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;
}
17 changes: 17 additions & 0 deletions config.h
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
Loading

0 comments on commit f610194

Please sign in to comment.