From cfb0ec01b9e28ff5d94c8b73c2b49a7ade4e3597 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Tue, 14 Aug 2018 15:53:04 +0300 Subject: [PATCH] db: introduce the --db-file=/path/to/smatch_db.sqlite option When you build recursively, then it doesn't work to look for the db in the working directory. Signed-off-by: Dan Carpenter --- smatch.c | 8 +++++++- smatch.h | 2 +- smatch_db.c | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/smatch.c b/smatch.c index ae5198c1..4ad13f0f 100644 --- a/smatch.c +++ b/smatch.c @@ -23,6 +23,7 @@ char *option_debug_check = (char *)""; char *option_project_str = (char *)"smatch_generic"; +static char *option_db_file = (char *)"smatch_db.sqlite"; enum project_type option_project = PROJ_NONE; char *bin_dir; char *data_dir; @@ -190,6 +191,11 @@ void parse_args(int *argcp, char ***argvp) (*argvp)[1] = (*argvp)[0]; found = 1; } + if (!found && !strncmp((*argvp)[1], "--db-file=", 10)) { + option_db_file = (*argvp)[1] + 10; + (*argvp)[1] = (*argvp)[0]; + found = 1; + } if (!found && !strncmp((*argvp)[1], "--data=", 7)) { option_datadir_str = (*argvp)[1] + 7; (*argvp)[1] = (*argvp)[0]; @@ -320,7 +326,7 @@ int main(int argc, char **argv) allocate_hook_memory(); create_function_hook_hash(); - open_smatch_db(); + open_smatch_db(option_db_file); for (i = 1; i < ARRAY_SIZE(reg_funcs); i++) { func = reg_funcs[i].func; /* The script IDs start at 1. diff --git a/smatch.h b/smatch.h index 0f9a2bb8..6ddf155c 100644 --- a/smatch.h +++ b/smatch.h @@ -892,7 +892,7 @@ void sql_select_return_states(const char *cols, struct expression *call, void sql_select_call_implies(const char *cols, struct expression *call, int (*callback)(void*, int, char**, char**)); -void open_smatch_db(void); +void open_smatch_db(char *db_file); /* smatch_files.c */ int open_data_file(const char *filename); diff --git a/smatch_db.c b/smatch_db.c index 0896330c..be81f6e6 100644 --- a/smatch_db.c +++ b/smatch_db.c @@ -2197,7 +2197,7 @@ static void dump_cache(struct symbol_list *sym_list) cache_sql(&save_cache_data, (char *)"call_implies", "select * from call_implies;"); } -void open_smatch_db(void) +void open_smatch_db(char *db_file) { int rc; @@ -2210,7 +2210,7 @@ void open_smatch_db(void) init_memdb(); init_cachedb(); - rc = sqlite3_open_v2("smatch_db.sqlite", &smatch_db, SQLITE_OPEN_READONLY, NULL); + rc = sqlite3_open_v2(db_file, &smatch_db, SQLITE_OPEN_READONLY, NULL); if (rc != SQLITE_OK) { option_no_db = 1; return; -- 2.11.4.GIT