From 6166b794a53047ea153be0bdbbc55bb73fbe226c Mon Sep 17 00:00:00 2001 From: Olaf Dietsche Date: Wed, 8 Jul 2015 16:38:45 +0200 Subject: [PATCH] Allow command line options from config file. --- sysbench/sb_options.c | 18 ++++++++++++++++++ sysbench/sb_options.h | 3 ++- sysbench/scripting/script_lua.c | 3 +++ sysbench/sysbench.c | 1 + 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/sysbench/sb_options.c b/sysbench/sb_options.c index ac4ff70..2b2e9ad 100644 --- a/sysbench/sb_options.c +++ b/sysbench/sb_options.c @@ -87,6 +87,18 @@ option_t *sb_find_option(const char *name) return find_option(&options, name); } +static void read_config_file(const char *filename) +{ + /* read config options from file */ + FILE *fp = fopen(filename, "r"); + if (!fp) { + perror(filename); + } else { + read_config(fp, &options); + fclose(fp); + } +} + int set_option(const char *name, const char *value, sb_arg_type_t type) { option_t *opt; @@ -120,6 +132,9 @@ int set_option(const char *name, const char *value, sb_arg_type_t type) add_value(&opt->values, tmp); free(tmp); break; + case SB_ARG_TYPE_FILE: + read_config_file(value); + break; default: printf("Unknown argument type: %d", type); return 1; @@ -163,6 +178,9 @@ void sb_print_options(sb_arg_t *opts) case SB_ARG_TYPE_STRING: fmt = "=STRING"; break; + case SB_ARG_TYPE_FILE: + fmt = "=FILENAME"; + break; default: fmt = ""; } diff --git a/sysbench/sb_options.h b/sysbench/sb_options.h index 28ebdad..cc4664f 100644 --- a/sysbench/sb_options.h +++ b/sysbench/sb_options.h @@ -32,7 +32,8 @@ typedef enum SB_ARG_TYPE_SIZE, SB_ARG_TYPE_FLOAT, SB_ARG_TYPE_STRING, - SB_ARG_TYPE_LIST + SB_ARG_TYPE_LIST, + SB_ARG_TYPE_FILE } sb_arg_type_t; /* Test option definition */ diff --git a/sysbench/scripting/script_lua.c b/sysbench/scripting/script_lua.c index f8387ef..0ddd732 100644 --- a/sysbench/scripting/script_lua.c +++ b/sysbench/scripting/script_lua.c @@ -395,6 +395,9 @@ lua_State *sb_lua_new_state(const char *scriptname, int thread_id) /*FIXME: should be exported as tables */ lua_pushnil(state); break; + case SB_ARG_TYPE_FILE: + /* FIXME: no need to export anything */ + break; default: log_text(LOG_WARNING, "Global option '%s' will not be exported, because" " the type is unknown", opt->name); diff --git a/sysbench/sysbench.c b/sysbench/sysbench.c index 3cab971..3664a4b 100644 --- a/sysbench/sysbench.c +++ b/sysbench/sysbench.c @@ -148,6 +148,7 @@ sb_arg_t general_args[] = {"rand-seed", "seed for random number generator, ignored when 0", SB_ARG_TYPE_INT, "0"}, {"rand-pareto-h", "parameter h for pareto distibution", SB_ARG_TYPE_FLOAT, "0.2"}, + {"config-file", "File containing command line options", SB_ARG_TYPE_FILE, NULL}, {NULL, NULL, SB_ARG_TYPE_NULL, NULL} };