From: Brian Aker Date: Thu, 14 Jan 2010 04:16:17 +0000 (-0800) Subject: Modify where memslap keeps its default config file. X-Git-Tag: 0.40~117 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=7fafbd3dbd318577553476edf6436926aff9014c;p=m6w6%2Flibmemcached Modify where memslap keeps its default config file. --- diff --git a/ChangeLog b/ChangeLog index 53f776c0..308aac83 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 0.38 + * memslap now creates a configuration file at ~/.memslap.cnf + * memcached_purge() now calls any callbacks registered during get execution. diff --git a/clients/memslap.c b/clients/memslap.c index 47be3c37..37e211a0 100644 --- a/clients/memslap.c +++ b/clients/memslap.c @@ -417,7 +417,7 @@ static void ms_options_parse(int argc, char *argv[]) break; case OPT_CONCURRENCY: /* --concurrency or -c */ - ms_setting.nconns= atoi(optarg); + ms_setting.nconns= (int)strtol(optarg, (char **) NULL, 10); if (ms_setting.nconns <= 0) { fprintf(stderr, "Concurrency must be greater than 0.:-)\n"); @@ -426,7 +426,7 @@ static void ms_options_parse(int argc, char *argv[]) break; case OPT_EXECUTE_NUMBER: /* --execute_number or -x */ - ms_setting.exec_num= atoll(optarg); + ms_setting.exec_num= (int)strtol(optarg, (char **) NULL, 10); if (ms_setting.exec_num <= 0) { fprintf(stderr, "Execute number must be greater than 0.:-)\n"); @@ -435,7 +435,7 @@ static void ms_options_parse(int argc, char *argv[]) break; case OPT_THREAD_NUMBER: /* --threads or -T */ - ms_setting.nthreads= atoi(optarg); + ms_setting.nthreads= (int)strtol(optarg, (char **) NULL, 10); if (ms_setting.nthreads <= 0) { fprintf(stderr, "Threads number must be greater than 0.:-)\n"); @@ -444,7 +444,7 @@ static void ms_options_parse(int argc, char *argv[]) break; case OPT_FIXED_LTH: /* --fixed_size or -X */ - ms_setting.fixed_value_size= (size_t)atoi(optarg); + ms_setting.fixed_value_size= (size_t)strtoull(optarg, (char **) NULL, 10); if ((ms_setting.fixed_value_size <= 0) || (ms_setting.fixed_value_size > MAX_VALUE_SIZE)) { @@ -465,7 +465,7 @@ static void ms_options_parse(int argc, char *argv[]) break; case OPT_GETS_DIVISION: /* --division or -d */ - ms_setting.mult_key_num= atoi(optarg); + ms_setting.mult_key_num= (int)strtol(optarg, (char **) NULL, 10); if (ms_setting.mult_key_num <= 0) { fprintf(stderr, "Multi-get key number must be greater than 0.:-)\n"); @@ -551,7 +551,7 @@ static void ms_options_parse(int argc, char *argv[]) break; case OPT_SOCK_PER_CONN: /* --conn_sock or -n */ - ms_setting.sock_per_conn= atoi(optarg); + ms_setting.sock_per_conn= (int)strtol(optarg, (char **) NULL, 10); if (ms_setting.sock_per_conn <= 0) { fprintf(stderr, "Number of socks of each concurrency " @@ -588,7 +588,7 @@ static void ms_options_parse(int argc, char *argv[]) break; case OPT_REP_WRITE_SRV: /* --rep_write or -p */ - ms_setting.rep_write_srv= atoi(optarg); + ms_setting.rep_write_srv= (int)strtol(optarg, (char **) NULL, 10); if (ms_setting.rep_write_srv <= 0) { fprintf(stderr, @@ -781,8 +781,8 @@ static void ms_monitor_slap_mode() second++; if ((ms_setting.stat_freq > 0) && (second % ms_setting.stat_freq == 0) - && ((int32_t)ms_stats.active_conns >= ms_setting.nconns) - && (ms_stats.active_conns <= (uint32_t)INT_MAX)) + && (ms_stats.active_conns >= ms_setting.nconns) + && (ms_stats.active_conns <= INT_MAX)) { ms_print_statistics(second); } diff --git a/clients/ms_memslap.h b/clients/ms_memslap.h index 51023d9d..0b9cc29e 100644 --- a/clients/ms_memslap.h +++ b/clients/ms_memslap.h @@ -69,7 +69,7 @@ typedef struct statistic /* global status statistic structure */ typedef struct stats { - volatile uint32_t active_conns; /* active connections */ + volatile int32_t active_conns; /* active connections */ size_t bytes_read; /* read bytes */ size_t bytes_written; /* written bytes */ size_t obj_bytes; /* object bytes */ diff --git a/clients/ms_setting.c b/clients/ms_setting.c index 2821ec52..d43356c7 100644 --- a/clients/ms_setting.c +++ b/clients/ms_setting.c @@ -13,7 +13,14 @@ #include #include +#include +#include #include +#include +#include +#include + + #include "ms_setting.h" #include "ms_conn.h" @@ -23,6 +30,8 @@ #define RAND_CHAR_SIZE (10 * 1024 * 1024) /* 10M character table */ #define RESERVED_RAND_CHAR_SIZE (2 * 1024 * 1024) /* reserved 2M to avoid pointer sloping over */ +#define DEFAULT_CONFIG_NAME ".memslap.cnf" + #define DEFAULT_THREADS_NUM 1 /* default start one thread */ #define DEFAULT_CONNS_NUM 16 /* default each thread with 16 connections */ #define DEFAULT_EXE_NUM 0 /* default execute number is 0 */ @@ -327,12 +336,30 @@ static int ms_read_is_data(char *line, ssize_t nread) */ static void ms_no_config_file() { - FILE *fd= fopen("config", "w+"); + char userpath[PATH_MAX]; + struct passwd *usr= NULL; + FILE *fd; + + usr= getpwuid(getuid()); + snprintf(userpath, PATH_MAX, "%s/%s", usr->pw_dir, DEFAULT_CONFIG_NAME); + + if (access (userpath, F_OK | R_OK) == 0) + goto exit; + + fd= fopen(userpath, "w+"); + + if (fd == NULL) + { + fprintf(stderr, "Could not create default configure file %s\n", userpath); + perror(strerror(errno)); + exit(1); + } fprintf(fd, "%s", DEFAULT_CONGIF_STR); fclose(fd); - ms_setting.cfg_file= strdup("config"); +exit: + ms_setting.cfg_file= strdup(userpath); } /* ms_no_config_file */ @@ -355,13 +382,11 @@ static void ms_parse_cfg_file(char *cfg_file) int end_of_file= 0; ms_key_distr_t *key_distr= NULL; ms_value_distr_t *val_distr= NULL; - bool no_cfg= false; if (cfg_file == NULL) { ms_no_config_file(); cfg_file= ms_setting.cfg_file; - no_cfg= true; } /*read key value configure file*/ @@ -376,6 +401,7 @@ static void ms_parse_cfg_file(char *cfg_file) if ((((nread= getline(&line, &read_len, f)) == 1) || ! ms_read_is_data(line, nread)) && (nread != EOF)) /* bypass blank line */ continue; + if (nread == EOF) { fprintf(stderr, "Bad configuration file, no configuration find.\n"); @@ -528,13 +554,10 @@ static void ms_parse_cfg_file(char *cfg_file) fclose(f); - if (no_cfg) - { - remove(ms_setting.cfg_file); - } - if (line != NULL) + { free(line); + } } /* ms_parse_cfg_file */ @@ -927,9 +950,9 @@ void ms_setting_init_pre() static void ms_setting_slapmode_init_post() { ms_setting.total_key_rng_cnt= KEY_RANGE_COUNT_INIT; - ms_setting.key_distr= (ms_key_distr_t *)malloc( - (size_t)ms_setting.total_key_rng_cnt - * sizeof(ms_key_distr_t)); + ms_setting.key_distr= + (ms_key_distr_t *)malloc((size_t)ms_setting.total_key_rng_cnt * sizeof(ms_key_distr_t)); + if (ms_setting.key_distr == NULL) { fprintf(stderr, "Can't allocate key distribution structure.\n"); @@ -937,10 +960,10 @@ static void ms_setting_slapmode_init_post() } ms_setting.total_val_rng_cnt= VALUE_RANGE_COUNT_INIT; - ms_setting.value_distr= (ms_value_distr_t *)malloc( - (size_t)ms_setting.total_val_rng_cnt - * sizeof( - ms_value_distr_t)); + + ms_setting.value_distr= + (ms_value_distr_t *)malloc((size_t)ms_setting.total_val_rng_cnt * sizeof( ms_value_distr_t)); + if (ms_setting.value_distr == NULL) { fprintf(stderr, "Can't allocate value distribution structure.\n"); diff --git a/docs/memslap.pod b/docs/memslap.pod index 6332a32b..2ddeed60 100644 --- a/docs/memslap.pod +++ b/docs/memslap.pod @@ -507,8 +507,11 @@ commands together as “mulit-get” to the server. =head1 Configuration file -This section describes the format of the configuration file. Below is a -sample configuration file: +This section describes the format of the configuration file. By default +when no configuration file is specified memslap reads the default +one located at ~/.memslap.cnf. + +Below is a sample configuration file: *************************************************************************** #comments should start with '#' diff --git a/example/memcached_light.c b/example/memcached_light.c index d88e5861..4a53217a 100644 --- a/example/memcached_light.c +++ b/example/memcached_light.c @@ -285,10 +285,12 @@ int main(int argc, char **argv) uint32_t pid; pid_file= fopen(global_options.pid_file, "w+"); - perror(strerror(errno)); if (pid_file == NULL) + { + perror(strerror(errno)); abort(); + } pid= (uint32_t)getpid(); fprintf(pid_file, "%u\n", pid); diff --git a/tests/include.am b/tests/include.am index 259da130..379e9e4a 100644 --- a/tests/include.am +++ b/tests/include.am @@ -119,6 +119,8 @@ clients: cat tests/Xumemc.pid | xargs kill rm tests/Xumemc.pid +MEMSLAP_COMMAND= clients/memslap $(COLLECTION) $(SUITE) + MEM_COMMAND= tests/testapp $(COLLECTION) $(SUITE) HASH_COMMAND= tests/testhashkit $(COLLECTION) $(SUITE) @@ -135,12 +137,17 @@ gdb-mem: gdb-hash: $(DEBUG_COMMAND) $(HASH_COMMAND) +gdb-memslap: + $(DEBUG_COMMAND) $(MEMSLAP_COMMAND) + valgrind-mem: $(VALGRIND_COMMAND) $(MEM_COMMAND) valgrind-hash: $(VALGRIND_COMMAND) $(HASH_COMMAND) +valgrind-memslap: + $(VALGRIND_COMMAND) $(MEMSLAP_COMMAND) PHONY += valgrind valgrind: tests/testapp tests/testhashkit valgrind-mem valgrind-hash