diff options
author | Jiri Olsa <Jiri Olsa jolsa@redhat.com> | 2010-02-13 21:20:26 +0100 |
---|---|---|
committer | Jiri Olsa <Jiri Olsa jolsa@redhat.com> | 2010-02-13 21:20:26 +0100 |
commit | 7cfcb7e6a024d27e2bc9756d8a8595d7ecb50811 (patch) | |
tree | 35cb5109e2d32086cd3fb24bb4c493fda9129fc1 /src | |
parent | 253e346421f9dd201d86e4fdf518c4985ea2f343 (diff) | |
download | latrace-7cfcb7e6a024d27e2bc9756d8a8595d7ecb50811.tar.gz latrace-7cfcb7e6a024d27e2bc9756d8a8595d7ecb50811.tar.xz latrace-7cfcb7e6a024d27e2bc9756d8a8595d7ecb50811.zip |
refactoring shared config
Diffstat (limited to 'src')
-rw-r--r-- | src/args.c | 76 | ||||
-rw-r--r-- | src/audit-init.c | 62 | ||||
-rw-r--r-- | src/audit.c | 52 | ||||
-rw-r--r-- | src/config.c | 65 | ||||
-rw-r--r-- | src/config.h | 25 | ||||
-rw-r--r-- | src/fifo.c | 10 | ||||
-rw-r--r-- | src/latrace.c | 6 | ||||
-rw-r--r-- | src/objsearch.c | 10 | ||||
-rw-r--r-- | src/run.c | 22 | ||||
-rw-r--r-- | src/stats.c | 22 |
10 files changed, 184 insertions, 166 deletions
@@ -238,10 +238,10 @@ static struct lt_enum* getenum(struct lt_config_shared *cfg, char *name) struct lt_enum *en; ENTRY e, *ep; - PRINT_VERBOSE(cfg->verbose, 1, "request for <%s>\n", name); + PRINT_VERBOSE(cfg, 1, "request for <%s>\n", name); if (!enum_init) { - PRINT_VERBOSE(cfg->verbose, 1, "no enum added so far\n", name); + PRINT_VERBOSE(cfg, 1, "no enum added so far\n", name); return NULL; } @@ -249,13 +249,13 @@ static struct lt_enum* getenum(struct lt_config_shared *cfg, char *name) hsearch_r(e, FIND, &ep, &args_enum_tab); if (!ep) { - PRINT_VERBOSE(cfg->verbose, 1, "failed to find enum <%s>\n", name); + PRINT_VERBOSE(cfg, 1, "failed to find enum <%s>\n", name); return NULL; } en = (struct lt_enum*) ep->data; - PRINT_VERBOSE(cfg->verbose, 1, "found %p <%s>\n", en, en->name); + PRINT_VERBOSE(cfg, 1, "found %p <%s>\n", en, en->name); return en; } @@ -273,7 +273,7 @@ static struct lt_enum_elem* get_enumelem(struct lt_config_shared *cfg, struct lt_enum_elem key; key.val = val; - PRINT_VERBOSE(cfg->verbose, 1, "looking for %p <%s> value %ld\n", + PRINT_VERBOSE(cfg, 1, "looking for %p <%s> value %ld\n", en, en->name, val); return bsearch(&key, en->elems, en->cnt, @@ -311,7 +311,7 @@ int lt_args_add_enum(struct lt_config_shared *cfg, char *name, free(en); /* we dont want to exit just because we ran out of our symbol limit */ - PRINT_VERBOSE(cfg->verbose, 3, + PRINT_VERBOSE(cfg, 3, "reach the enum number limit %u\n", LT_ARGS_DEF_ENUM_NUM); } @@ -325,7 +325,7 @@ int lt_args_add_enum(struct lt_config_shared *cfg, char *name, if (NULL == (en->elems = malloc(sizeof(struct lt_enum_elem) * en->cnt))) return -1; - PRINT_VERBOSE(cfg->verbose, 3, "enum %s (%d elems)\n", + PRINT_VERBOSE(cfg, 3, "enum %s (%d elems)\n", en->name, en->cnt); lt_list_for_each_entry(elem, h, list) { @@ -338,7 +338,7 @@ int lt_args_add_enum(struct lt_config_shared *cfg, char *name, elem->undef = 0; } - PRINT_VERBOSE(cfg->verbose, 3, "\t %s = %d\n", + PRINT_VERBOSE(cfg, 3, "\t %s = %d\n", elem->name, elem->val); en->elems[i++] = *elem; @@ -372,7 +372,7 @@ struct lt_enum_elem* lt_args_get_enum(struct lt_config_shared *cfg, elem->name = strdup(name); - PRINT_VERBOSE(cfg->verbose, 3, "enum elem %s = %d, undef = %d\n", + PRINT_VERBOSE(cfg, 3, "enum elem %s = %d, undef = %d\n", elem->name, elem->val, elem->undef); return elem; } @@ -396,12 +396,12 @@ int lt_args_add_struct(struct lt_config_shared *cfg, char *type_name, sarg.type_name = type_name; sarg.args_head = h; - PRINT_VERBOSE(cfg->verbose, 3, "struct [%s] type %d\n", - sarg.type_name, sarg.type_id); + PRINT_VERBOSE(cfg, 3, "struct [%s] type %d\n", + sarg.type_name, sarg.type_id); lt_list_for_each_entry(arg, sarg.args_head, args_list) { - PRINT_VERBOSE(cfg->verbose, 3, "\t %s %s %u\n", + PRINT_VERBOSE(cfg, 3, "\t %s %s %u\n", arg->type_name, arg->name, arg->type_len); /* This is not what sizeof would return on the structure. @@ -412,7 +412,7 @@ int lt_args_add_struct(struct lt_config_shared *cfg, char *type_name, args_def_struct[args_def_struct_cnt++] = sarg; - PRINT_VERBOSE(cfg->verbose, 3, "%d.struct - final len = %u\n", + PRINT_VERBOSE(cfg, 3, "%d.struct - final len = %u\n", args_def_struct_cnt, sarg.type_len); return 0; } @@ -425,7 +425,7 @@ int lt_args_add_sym(struct lt_config_shared *cfg, struct lt_arg *ret, struct lt_arg *arg; int i = 0; - PRINT_VERBOSE(cfg->verbose, 3, "got symbol '%s %s'\n", + PRINT_VERBOSE(cfg, 3, "got symbol '%s %s'\n", ret->type_name, ret->name); if (NULL == (sym = (struct lt_args_sym*) malloc(sizeof(*sym)))) @@ -444,12 +444,12 @@ int lt_args_add_sym(struct lt_config_shared *cfg, struct lt_arg *ret, to exit the program anyway */ return -1; - PRINT_VERBOSE(cfg->verbose, 3, "got return %s, ptr %d\n", + PRINT_VERBOSE(cfg, 3, "got return %s, ptr %d\n", ret->type_name, ret->pointer); sym->args[i++] = ret; lt_list_for_each_entry(arg, h, args_list) { - PRINT_VERBOSE(cfg->verbose, 3, "\t '%s %s'\n", + PRINT_VERBOSE(cfg, 3, "\t '%s %s'\n", arg->type_name, arg->name); sym->args[i++] = arg; } @@ -462,10 +462,10 @@ int lt_args_add_sym(struct lt_config_shared *cfg, struct lt_arg *ret, free(sym); /* we dont want to exit just because we ran out of our symbol limit */ - PRINT_VERBOSE(cfg->verbose, 3, "reach the symbol number limit %u\n", + PRINT_VERBOSE(cfg, 3, "reach the symbol number limit %u\n", LT_ARGS_TAB); } else - PRINT_VERBOSE(cfg->verbose, 3, "got symbol %s (%d args)\n", + PRINT_VERBOSE(cfg, 3, "got symbol %s (%d args)\n", sym->name, sym->argcnt); return 0; @@ -476,7 +476,7 @@ static struct lt_arg* argdup(struct lt_config_shared *cfg, struct lt_arg *asrc) struct lt_arg *arg, *a; struct lt_list_head *h; - PRINT_VERBOSE(cfg->verbose, 2, "got arg '%s %s', dtype %d\n", + PRINT_VERBOSE(cfg, 2, "got arg '%s %s', dtype %d\n", asrc->type_name, asrc->name, asrc->dtype); if (NULL == (arg = malloc(sizeof(*arg)))) { @@ -522,7 +522,7 @@ static struct lt_arg* find_arg(struct lt_config_shared *cfg, char *type, struct lt_arg *arg; struct lt_arg adef = argsdef[i]; - PRINT_VERBOSE(cfg->verbose, 3, "%d. looking for [%s] - [%s]\n", + PRINT_VERBOSE(cfg, 3, "%d. looking for [%s] - [%s]\n", i, type, adef.type_name); if (strcmp(type, adef.type_name)) @@ -533,7 +533,7 @@ static struct lt_arg* find_arg(struct lt_config_shared *cfg, char *type, arg = argdup(cfg, &adef); - PRINT_VERBOSE(cfg->verbose, 3, "found %d\n", arg->type_id); + PRINT_VERBOSE(cfg, 3, "found %d\n", arg->type_id); return arg; } @@ -604,12 +604,12 @@ int lt_args_add_typedef(struct lt_config_shared *cfg, char *base, args_def_typedef, args_def_typedef_cnt, 0))) break; - PRINT_VERBOSE(cfg->verbose, 3, "%s not found\n", base); + PRINT_VERBOSE(cfg, 3, "%s not found\n", base); return -1; } while(0); - PRINT_VERBOSE(cfg->verbose, 3, "got [%s]\n", new); + PRINT_VERBOSE(cfg, 3, "got [%s]\n", new); args_def_typedef[i = args_def_typedef_cnt++] = *arg; @@ -619,7 +619,7 @@ int lt_args_add_typedef(struct lt_config_shared *cfg, char *base, lt_init_list_head(&arg->args_list); - PRINT_VERBOSE(cfg->verbose, 3, "%d.typedef - got [%s] [%s]\n", + PRINT_VERBOSE(cfg, 3, "%d.typedef - got [%s] [%s]\n", args_def_typedef_cnt, base, arg->type_name); return 0; } @@ -639,7 +639,7 @@ int lt_args_init(struct lt_config_shared *cfg) if (*cfg->args_def) file = cfg->args_def; - PRINT_VERBOSE(cfg->verbose, 1, "arguments definition file %s\n", file); + PRINT_VERBOSE(cfg, 1, "arguments definition file %s\n", file); if (lt_args_buf_open(cfg, file)) return -1; @@ -662,7 +662,7 @@ static struct lt_args_sym* getsym(struct lt_config_shared *cfg, char *sym) struct lt_args_sym *a; ENTRY e, *ep; - PRINT_VERBOSE(cfg->verbose, 1, "request for <%s>\n", sym); + PRINT_VERBOSE(cfg, 1, "request for <%s>\n", sym); e.key = sym; hsearch_r(e, FIND, &ep, &cfg->args_tab); @@ -672,7 +672,7 @@ static struct lt_args_sym* getsym(struct lt_config_shared *cfg, char *sym) a = (struct lt_args_sym*) ep->data; - PRINT_VERBOSE(cfg->verbose, 1, "found %p <%s>\n", a, a->name); + PRINT_VERBOSE(cfg, 1, "found %p <%s>\n", a, a->name); return a; } @@ -700,7 +700,7 @@ static int getstr_pod(struct lt_config_shared *cfg, int dspname, struct lt_arg * int len = 0, alen = *arglen; int namelen = strlen(arg->name); - PRINT_VERBOSE(cfg->verbose, 1, "\t arg '%s %s', pval %p, len %d, pointer %d, dtype %d, type_id %d\n", + PRINT_VERBOSE(cfg, 1, "\t arg '%s %s', pval %p, len %d, pointer %d, dtype %d, type_id %d\n", arg->type_name, arg->name, pval, alen, arg->pointer, arg->dtype, arg->type_id); if (alen < 5) @@ -804,7 +804,7 @@ do { \ out: *arglen += strlen(argbuf); - PRINT_VERBOSE(cfg->verbose, 1, "\t arg out len %d - [%s]\n", + PRINT_VERBOSE(cfg, 1, "\t arg out len %d - [%s]\n", *arglen, argbuf); return 0; } @@ -814,7 +814,7 @@ int lt_args_cb_arg(struct lt_config_shared *cfg, struct lt_arg *arg, void *pval, { int len = data->arglen; - PRINT_VERBOSE(cfg->verbose, 1, "arg '%s %s', pval %p, last %d\n", + PRINT_VERBOSE(cfg, 1, "arg '%s %s', pval %p, last %d\n", arg->type_name, arg->name, pval, last); getstr_pod(cfg, dspname, arg, pval, @@ -832,7 +832,7 @@ int lt_args_cb_arg(struct lt_config_shared *cfg, struct lt_arg *arg, void *pval, int lt_args_cb_struct(struct lt_config_shared *cfg, int type, struct lt_arg *arg, void *pval, struct lt_args_data *data, int last) { - PRINT_VERBOSE(cfg->verbose, 1, + PRINT_VERBOSE(cfg, 1, "type %d, arg '%s %s', pval %p, last %d, pointer %d\n", type, arg->type_name, arg->name, pval, last, arg->pointer); @@ -910,11 +910,11 @@ static FILE* open_include(struct lt_config_shared *cfg, char *file) /* we got an absolute path */ if ((NULL != (f = fopen(file, "r")))) { - PRINT_VERBOSE(cfg->verbose, 1, "open ok [%s]\n", file); + PRINT_VERBOSE(cfg, 1, "open ok [%s]\n", file); return f; } - PRINT_VERBOSE(cfg->verbose, 1, "open failed [%s]: %s\n", + PRINT_VERBOSE(cfg, 1, "open failed [%s]: %s\n", file, strerror(errno)); /* give up if there was already the absolute name */ @@ -934,13 +934,13 @@ static FILE* open_include(struct lt_config_shared *cfg, char *file) sprintf(fn, "%s/%s", LT_ARGS_DEF_DIR, file); if ((NULL == (f = fopen(fn, "r")))) { - PRINT_VERBOSE(cfg->verbose, 1, "open failed [%s]: %s\n", + PRINT_VERBOSE(cfg, 1, "open failed [%s]: %s\n", fn, strerror(errno)); printf("open failed [%s]: %s\n", file, strerror(errno)); return NULL; } - PRINT_VERBOSE(cfg->verbose, 1, "open ok [%s]\n", fn); + PRINT_VERBOSE(cfg, 1, "open ok [%s]\n", fn); return f; } @@ -948,7 +948,7 @@ int lt_args_buf_open(struct lt_config_shared *cfg, char *file) { struct lt_args_include *inc; - PRINT_VERBOSE(cfg->verbose, 1, "opening buffer for [%s] depth %d\n", + PRINT_VERBOSE(cfg, 1, "opening buffer for [%s] depth %d\n", file, include_stack_ptr); if ((include_stack_ptr + 1) == MAX_INCLUDE_DEPTH) { @@ -969,7 +969,7 @@ int lt_args_buf_open(struct lt_config_shared *cfg, char *file) yy_switch_to_buffer(inc->yybuf); - PRINT_VERBOSE(cfg->verbose, 1, "opened buffer for [%s] depth %d\n", + PRINT_VERBOSE(cfg, 1, "opened buffer for [%s] depth %d\n", file, include_stack_ptr); return 0; } @@ -978,7 +978,7 @@ int lt_args_buf_close(struct lt_config_shared *cfg) { struct lt_args_include *inc = &include_stack[--include_stack_ptr]; - PRINT_VERBOSE(cfg->verbose, 1, "buffer closed [%s], depth [%d]\n", + PRINT_VERBOSE(cfg, 1, "buffer closed [%s], depth [%d]\n", inc->file, include_stack_ptr); free(inc->file); diff --git a/src/audit-init.c b/src/audit-init.c index 5ab978c..76e6d21 100644 --- a/src/audit-init.c +++ b/src/audit-init.c @@ -47,7 +47,7 @@ static int read_config(char *dir) return -1; } - if (-1 == read(fd, &cfg.sh, sizeof(cfg.sh))) { + if (-1 == read(fd, &cfg.sh_storage, sizeof(cfg.sh_storage))) { perror("read failed"); return -1; } @@ -57,16 +57,17 @@ static int read_config(char *dir) return -1; } - if (len != sizeof(cfg.sh)) { + if (len != sizeof(cfg.sh_storage)) { printf("config file size differs\n"); return -1; } - if (LT_MAGIC != cfg.sh.magic) { + if (LT_MAGIC != cfg.sh_storage.magic) { printf("config file magic check failed\n"); return -1; } + cfg.sh = cfg.sh_storage.sh = &cfg.sh_storage; return 0; } @@ -75,26 +76,26 @@ static int get_names(struct lt_config_audit *cfg, char *names, char **ptr) char* s; int cnt = 0; - PRINT_VERBOSE(cfg->sh.verbose, 1, "names: [%s] max: %d\n", + PRINT_VERBOSE(cfg, 1, "names: [%s] max: %d\n", names, LT_NAMES_MAX); s = strchr(names, LT_NAMES_SEP); while(NULL != (s = strchr(names, LT_NAMES_SEP)) && (cnt < LT_NAMES_MAX)) { *s = 0x0; - PRINT_VERBOSE(cfg->sh.verbose, 1, "got: %s", names); + PRINT_VERBOSE(cfg, 1, "got: %s", names); ptr[cnt++] = names; names = ++s; } if (cnt) { ptr[cnt++] = names; - PRINT_VERBOSE(cfg->sh.verbose, 1, "got: %s\n", names); + PRINT_VERBOSE(cfg, 1, "got: %s\n", names); } if (!cnt && *names) { ptr[0] = names; cnt = 1; - PRINT_VERBOSE(cfg->sh.verbose, 1, "got: %s\n", names); + PRINT_VERBOSE(cfg, 1, "got: %s\n", names); } ptr[cnt] = NULL; @@ -102,7 +103,7 @@ static int get_names(struct lt_config_audit *cfg, char *names, char **ptr) if (!cnt) return -1; - PRINT_VERBOSE(cfg->sh.verbose, 1, "got %d entries\n", cnt); + PRINT_VERBOSE(cfg, 1, "got %d entries\n", cnt); return cnt; } @@ -112,51 +113,51 @@ int audit_init(int argc, char **argv, char **env) return -1; /* -Aa */ - if (cfg.sh.args_enabled && lt_args_init(&cfg.sh)) + if (lt_sh(&cfg, args_enabled) && lt_args_init(cfg.sh)) return -1; /* -t */ - if ((*cfg.sh.libs_to) && - (-1 == (cfg.libs_to_cnt = get_names(&cfg, cfg.sh.libs_to, cfg.libs_to)))) { + if ((*lt_sh(&cfg, libs_to)) && + (-1 == (cfg.libs_to_cnt = get_names(&cfg, lt_sh(&cfg, libs_to), cfg.libs_to)))) { printf("latrace failed to parse libs to\n"); return -1; } /* -f */ - if ((*cfg.sh.libs_from) && - (-1 == (cfg.libs_from_cnt = get_names(&cfg, cfg.sh.libs_from, cfg.libs_from)))) { + if ((*lt_sh(&cfg, libs_from)) && + (-1 == (cfg.libs_from_cnt = get_names(&cfg, lt_sh(&cfg, libs_from), cfg.libs_from)))) { printf("latrace failed to parse libs from\n"); return -1; } /* -l */ - if ((*cfg.sh.libs_both) && - (-1 == (cfg.libs_both_cnt = get_names(&cfg, cfg.sh.libs_both, cfg.libs_both)))) { + if ((*lt_sh(&cfg, libs_both)) && + (-1 == (cfg.libs_both_cnt = get_names(&cfg, lt_sh(&cfg, libs_both), cfg.libs_both)))) { printf("latrace failed to parse libs from\n"); return -1; } /* -s */ - if ((*cfg.sh.symbols) && - (-1 == (cfg.symbols_cnt = get_names(&cfg, cfg.sh.symbols, cfg.symbols)))) { + if ((*lt_sh(&cfg, symbols)) && + (-1 == (cfg.symbols_cnt = get_names(&cfg, lt_sh(&cfg, symbols), cfg.symbols)))) { printf("latrace failed to parse symbols\n"); return -1; } /* -b */ - if ((*cfg.sh.flow_below) && - (-1 == (cfg.flow_below_cnt = get_names(&cfg, cfg.sh.flow_below, cfg.flow_below)))) { + if ((*lt_sh(&cfg, flow_below)) && + (-1 == (cfg.flow_below_cnt = get_names(&cfg, lt_sh(&cfg, flow_below), cfg.flow_below)))) { printf("latrace failed to parse symbols in flow-below option\n"); return -1; } /* -L */ - if (*cfg.sh.libs_subst) { + if (*lt_sh(&cfg, libs_subst)) { char *ptr[LT_NAMES_MAX]; int cnt; - if (-1 == (cnt = get_names(&cfg, cfg.sh.libs_subst, ptr))) { + if (-1 == (cnt = get_names(&cfg, lt_sh(&cfg, libs_subst), ptr))) { printf("latrace failed to parse input for subst option\n"); return -1; } @@ -167,20 +168,21 @@ int audit_init(int argc, char **argv, char **env) } } - /* -o */ - cfg.sh.fout = stdout; - if ((*cfg.sh.output) && (NULL == (cfg.sh.fout = fopen(cfg.sh.output, "w")))) { - printf("latrace failed to open output file %s\n", cfg.sh.output); + /* -o FIXME put fout out of the shared structure */ + lt_sh(&cfg, fout) = stdout; + if ((*lt_sh(&cfg, output)) && + (NULL == (lt_sh(&cfg, fout) = fopen(lt_sh(&cfg, output), "w")))) { + printf("latrace failed to open output file %s\n", lt_sh(&cfg, output)); return -1; } /* -E */ - if (cfg.sh.not_follow_exec) + if (lt_sh(&cfg, not_follow_exec)) unsetenv("LD_AUDIT"); /* -F */ - if (cfg.sh.not_follow_fork) - cfg.sh.pid = getpid(); + if (lt_sh(&cfg, not_follow_fork)) + lt_sh(&cfg, pid) = getpid(); cfg.init_ok = 1; return 0; @@ -191,6 +193,6 @@ void finalize(void) __attribute__((destructor)); void finalize(void) { - if ((!cfg.sh.pipe) && (*cfg.sh.output)) - fclose(cfg.sh.fout); + if ((!lt_sh(&cfg, pipe)) && (*lt_sh(&cfg, output))) + fclose(lt_sh(&cfg, fout)); } diff --git a/src/audit.c b/src/audit.c index 850daac..3eaff1d 100644 --- a/src/audit.c +++ b/src/audit.c @@ -47,13 +47,13 @@ static int check_names(char *name, char **ptr) for(n = *ptr; n; n = *(++ptr)) { if (strstr(name, n)) { - PRINT_VERBOSE(cfg.sh.verbose, 2, + PRINT_VERBOSE(&cfg, 2, "return %d for name %s\n", 1, name); return 1; } } - PRINT_VERBOSE(cfg.sh.verbose, 2, "return %d for name %s\n", + PRINT_VERBOSE(&cfg, 2, "return %d for name %s\n", 0, name); return 0; } @@ -75,18 +75,18 @@ static int sym_entry(const char *symname, char *lib_from, char *lib_to, char *argbuf = "", *argdbuf = ""; struct timeval tv; - PRINT_VERBOSE(cfg.sh.verbose, 2, "%s@%s\n", symname, lib_to); + PRINT_VERBOSE(&cfg, 2, "%s@%s\n", symname, lib_to); if (cfg.flow_below_cnt && !check_flow_below(symname, 1)) return 0; - if (cfg.sh.timestamp || cfg.sh.counts) + if (lt_sh(&cfg, timestamp) || lt_sh(&cfg, counts)) gettimeofday(&tv, NULL); - argret = cfg.sh.args_enabled ? - lt_args_sym_entry(&cfg.sh, (char*) symname, regs, &argbuf, &argdbuf) : -1; + argret = lt_sh(&cfg, args_enabled) ? + lt_args_sym_entry(cfg.sh, (char*) symname, regs, &argbuf, &argdbuf) : -1; - if (cfg.sh.pipe) { + if (lt_sh(&cfg, pipe)) { char buf[FIFO_MSG_MAXLEN]; int len; @@ -99,14 +99,14 @@ static int sym_entry(const char *symname, char *lib_from, char *lib_to, return lt_fifo_send(&cfg, pipe_fd, buf, len); } - cfg.sh.indent_depth++; + lt_sh(&cfg, indent_depth)++; - lt_out_entry(&cfg.sh, &tv, symname, lib_to, + lt_out_entry(cfg.sh, &tv, symname, lib_to, argbuf, argdbuf); if (!argret) { free(argbuf); - if (cfg.sh.args_detailed && (*argdbuf)) + if (lt_sh(&cfg, args_detailed) && (*argdbuf)) free(argdbuf); } @@ -120,19 +120,19 @@ static int sym_exit(const char *symname, char *lib_from, char *lib_to, char *argbuf = "", *argdbuf = ""; struct timeval tv; - PRINT_VERBOSE(cfg.sh.verbose, 2, "%s@%s\n", symname, lib_to); + PRINT_VERBOSE(&cfg, 2, "%s@%s\n", symname, lib_to); if (cfg.flow_below_cnt && !check_flow_below(symname, 0)) return 0; - if (cfg.sh.timestamp || cfg.sh.counts) + if (lt_sh(&cfg, timestamp) || lt_sh(&cfg, counts)) gettimeofday(&tv, NULL); - argret = cfg.sh.args_enabled ? - lt_args_sym_exit(&cfg.sh, (char*) symname, + argret = lt_sh(&cfg, args_enabled) ? + lt_args_sym_exit(cfg.sh, (char*) symname, (La_regs*) inregs, outregs, &argbuf, &argdbuf) : -1; - if (cfg.sh.pipe) { + if (lt_sh(&cfg, pipe)) { char buf[FIFO_MSG_MAXLEN]; int len; @@ -142,15 +142,15 @@ static int sym_exit(const char *symname, char *lib_from, char *lib_to, return lt_fifo_send(&cfg, pipe_fd, buf, len); } - lt_out_exit(&cfg.sh, &tv, symname, lib_from, + lt_out_exit(cfg.sh, &tv, symname, lib_from, argbuf, argdbuf); - cfg.sh.indent_depth--; + lt_sh(&cfg, indent_depth)--; if (!argret) { free(argbuf); - if (cfg.sh.args_detailed && (*argdbuf)) + if (lt_sh(&cfg, args_detailed) && (*argdbuf)) free(argdbuf); } @@ -161,10 +161,10 @@ static int check_pid() { pid_t pid = getpid(); - PRINT_VERBOSE(cfg.sh.verbose, 1, "tid = %d, cfg tid = %d\n", - pid, cfg.sh.pid); + PRINT_VERBOSE(&cfg, 1, "tid = %d, cfg tid = %d\n", + pid, lt_sh(&cfg, pid)); - if (pid != cfg.sh.pid) + if (pid != lt_sh(&cfg, pid)) return -1; return 0; @@ -172,7 +172,7 @@ static int check_pid() #define CHECK_PID(ret) \ do { \ - if (cfg.sh.not_follow_fork && \ + if (cfg.sh->not_follow_fork && \ check_pid()) \ return ret; \ } while(0) @@ -230,7 +230,7 @@ static unsigned int la_symbind(const char *symname) void la_activity(uintptr_t *cookie, unsigned int act) { - PRINT_VERBOSE(cfg.sh.verbose, 2, "entry\n"); + PRINT_VERBOSE(&cfg, 2, "entry\n"); } char* la_objsearch(const char *name, uintptr_t *cookie, unsigned int flag) @@ -243,12 +243,12 @@ char* la_objsearch(const char *name, uintptr_t *cookie, unsigned int flag) void la_preinit(uintptr_t *__cookie) { - PRINT_VERBOSE(cfg.sh.verbose, 2, "entry\n"); + PRINT_VERBOSE(&cfg, 2, "entry\n"); } unsigned int la_objclose(uintptr_t *__cookie) { - PRINT_VERBOSE(cfg.sh.verbose, 2, "entry\n"); + PRINT_VERBOSE(&cfg, 2, "entry\n"); return 0; } @@ -277,7 +277,7 @@ pltenter(ElfW(Sym) *sym, unsigned int ndx, uintptr_t *refcook, CHECK_PID(sym->st_value); sym_entry(symname, lr ? lr->l_name : NULL, ld ? ld->l_name : NULL, regs); - *framesizep = cfg.sh.framesize; + *framesizep = lt_sh(&cfg, framesize); return sym->st_value; } diff --git a/src/config.c b/src/config.c index 6b02ceb..c704183 100644 --- a/src/config.c +++ b/src/config.c @@ -101,15 +101,16 @@ static int get_type(struct lt_config_app *cfg, struct lt_config_tv *tv, int lt_config(struct lt_config_app *cfg, int argc, char **argv) { memset(cfg, 0, sizeof(*cfg)); + cfg->sh = &cfg->sh_storage; /* default values settings */ - cfg->sh.magic = LT_MAGIC; - cfg->sh.framesize = 1000; - cfg->sh.fout = stdout; - cfg->sh.indent_sym = 1; - cfg->sh.indent_size = 2; - cfg->sh.args_maxlen = LR_ARGS_MAXLEN; - cfg->sh.args_detail_maxlen = LR_ARGS_DETAIL_MAXLEN; + lt_sh(cfg, magic) = LT_MAGIC; + lt_sh(cfg, framesize) = 1000; + lt_sh(cfg, fout) = stdout; + lt_sh(cfg, indent_sym) = 1; + lt_sh(cfg, indent_size) = 2; + lt_sh(cfg, args_maxlen) = LR_ARGS_MAXLEN; + lt_sh(cfg, args_detail_maxlen) = LR_ARGS_DETAIL_MAXLEN; cfg->csort = LT_CSORT_CALL; while (1) { @@ -155,82 +156,82 @@ int lt_config(struct lt_config_app *cfg, int argc, char **argv) if (strlen(optarg) > LT_LIBS_MAXSIZE) return -1; - strncpy(cfg->sh.libs_both, optarg, strlen(optarg)); + strncpy(lt_sh(cfg, libs_both), optarg, strlen(optarg)); break; case 't': if (strlen(optarg) > LT_LIBS_MAXSIZE) return -1; - strncpy(cfg->sh.libs_to, optarg, strlen(optarg)); + strncpy(lt_sh(cfg, libs_to), optarg, strlen(optarg)); break; case 'f': if (strlen(optarg) > LT_LIBS_MAXSIZE) return -1; - strncpy(cfg->sh.libs_from, optarg, strlen(optarg)); + strncpy(lt_sh(cfg, libs_from), optarg, strlen(optarg)); break; case 's': if (strlen(optarg) > LT_SYMBOLS_MAXSIZE) return -1; - strncpy(cfg->sh.symbols, optarg, strlen(optarg)); + strncpy(lt_sh(cfg, symbols), optarg, strlen(optarg)); break; case 'b': if (strlen(optarg) > LT_SYMBOLS_MAXSIZE) return -1; - strncpy(cfg->sh.flow_below, optarg, strlen(optarg)); + strncpy(lt_sh(cfg, flow_below), optarg, strlen(optarg)); break; case 'v': - cfg->sh.verbose++; + lt_sh(cfg, verbose)++; break; case 'S': - cfg->sh.timestamp = 1; + lt_sh(cfg, timestamp) = 1; break; case 'T': - cfg->sh.hide_tid = 1; + lt_sh(cfg, hide_tid) = 1; break; case 'F': - cfg->sh.not_follow_fork = 1; + lt_sh(cfg, not_follow_fork) = 1; break; case 'E': - cfg->sh.not_follow_exec = 1; + lt_sh(cfg, not_follow_exec) = 1; break; case 'i': - cfg->sh.indent_size = atoi(optarg); + lt_sh(cfg, indent_size) = atoi(optarg); break; case 'B': - cfg->sh.braces = 1; + lt_sh(cfg, braces) = 1; break; case 'd': - cfg->sh.demangle = 1; + lt_sh(cfg, demangle) = 1; break; case 'I': - cfg->sh.indent_sym = 0; + lt_sh(cfg, indent_sym) = 0; break; case 'y': - cfg->sh.framesize = atoi(optarg); + lt_sh(cfg, framesize) = atoi(optarg); break; case 'L': if (strlen(optarg) > LT_SYMBOLS_MAXSIZE) return -1; - strncpy(cfg->sh.libs_subst, optarg, strlen(optarg)); + strncpy(lt_sh(cfg, libs_subst), optarg, strlen(optarg)); break; case 'C': @@ -239,25 +240,25 @@ int lt_config(struct lt_config_app *cfg, int argc, char **argv) usage(); /* falling through */ case 'c': - cfg->sh.counts = 1; + lt_sh(cfg, counts) = 1; /* falling through */ case 'p': - cfg->sh.pipe = 1; + lt_sh(cfg, pipe) = 1; break; case 'a': - strcpy(cfg->sh.args_def, optarg); + strcpy(lt_sh(cfg, args_def), optarg); /* falling through */ case 'A': - cfg->sh.args_enabled = 1; + lt_sh(cfg, args_enabled) = 1; break; case 'D': - cfg->sh.args_detailed = 1; + lt_sh(cfg, args_detailed) = 1; break; case 'o': - strcpy(cfg->sh.output, optarg); + strcpy(lt_sh(cfg, output), optarg); break; case 'V': @@ -289,9 +290,9 @@ int lt_config(struct lt_config_app *cfg, int argc, char **argv) usage(); } - if ((cfg->sh.pipe) && (*cfg->sh.output) && - (NULL == (cfg->sh.fout = fopen(cfg->sh.output, "w")))) { - printf("failed to fopen output file %s\n", cfg->sh.output); + if ((lt_sh(cfg, pipe)) && (*lt_sh(cfg, output)) && + (NULL == (lt_sh(cfg, fout) = fopen(lt_sh(cfg, output), "w")))) { + printf("failed to fopen output file %s\n", lt_sh(cfg, output)); usage(); } diff --git a/src/config.h b/src/config.h index afd8a7a..59ddc9b 100644 --- a/src/config.h +++ b/src/config.h @@ -120,10 +120,18 @@ struct lt_config_shared { /* used by both app and lib */ unsigned int indent_depth; + + /* XXX feel like an idiot.. find another way!!! */ + struct lt_config_shared *sh; }; struct lt_config_app { - struct lt_config_shared sh; + /* + * This is to copy the lt_config_audit, so we can use + * one PRINT_VERBOSE only. + */ + struct lt_config_shared *sh; + struct lt_config_shared sh_storage; char *prog; #define LT_NUM_ARG 500 @@ -149,7 +157,14 @@ struct lt_objsearch { }; struct lt_config_audit { - struct lt_config_shared sh; + + /* + * Normally sh points to the sh_storage. When using + * ctl-config feature, the shared config is stored + * in mmaped area. + */ + struct lt_config_shared *sh; + struct lt_config_shared sh_storage; char *libs_to[LT_NAMES_MAX]; int libs_to_cnt; @@ -173,6 +188,8 @@ struct lt_config_audit { int init_ok; }; +#define lt_sh(cfg, field) ((cfg)->sh->field) + #define FIFO_MSG_MAXLEN 2000 /* common message data */ @@ -410,9 +427,9 @@ do { \ printf(lpbuf, ## args); \ } while(0) -#define PRINT_VERBOSE(verbose, cond, fmt, args...) \ +#define PRINT_VERBOSE(cfg, cond, fmt, args...) \ do { \ - if (cond > verbose) \ + if (cond > (cfg)->sh->verbose) \ break; \ PRINT(fmt, ## args); \ } while(0) @@ -59,7 +59,7 @@ int lt_fifo_open(struct lt_config_app *cfg, char *name) if (-1 == (fd = open(name, O_RDONLY))) perror("open fifo failed"); - PRINT_VERBOSE(cfg->sh.verbose, 1, "pipe openned fd: %d\n", fd); + PRINT_VERBOSE(cfg, 1, "pipe openned fd: %d\n", fd); return fd; } @@ -73,7 +73,7 @@ int lt_fifo_send(struct lt_config_audit *cfg, int fd, char *buf, int len) } written += len; - PRINT_VERBOSE(cfg->sh.verbose, 1, "sending %d, total %u\n", + PRINT_VERBOSE(cfg, 1, "sending %d, total %u\n", len, written); return 0; } @@ -95,7 +95,7 @@ int lt_fifo_recv(struct lt_config_app *cfg, struct lt_thread *t, void *buf, red += size; - PRINT_VERBOSE(cfg->sh.verbose, 1, "received %d\n", h->len); + PRINT_VERBOSE(cfg, 1, "received %d\n", h->len); if ((size + h->len) > bufsize) { printf("thread %d - buffer max size reached\n", t->tid); @@ -109,7 +109,7 @@ int lt_fifo_recv(struct lt_config_app *cfg, struct lt_thread *t, void *buf, red += size; - PRINT_VERBOSE(cfg->sh.verbose, 1, "received %d, total %u\n", + PRINT_VERBOSE(cfg, 1, "received %d, total %u\n", size + sizeof(*h), red); return 0; } @@ -141,7 +141,7 @@ int lt_fifo_msym_get(struct lt_config_audit *cfg, char *buf, int type, len += len_data; m->h.len = len_data + (sizeof(*m) - sizeof(struct lt_fifo_mbase)); - PRINT_VERBOSE(cfg->sh.verbose, 1, "sending data %d <%s> <%s> <%s> <%s>\n", + PRINT_VERBOSE(cfg, 1, "sending data %d <%s> <%s> <%s> <%s>\n", m->h.len, m->data + m->sym, m->data + m->lib, diff --git a/src/latrace.c b/src/latrace.c index 9527fcf..68c36e9 100644 --- a/src/latrace.c +++ b/src/latrace.c @@ -35,10 +35,10 @@ int main(int argc, char **argv) if (-1 == lt_run(&cfg)) return -1; - if ((cfg.sh.pipe) && (*cfg.sh.output)) - fclose(cfg.sh.fout); + if ((lt_sh(&cfg, pipe)) && (*lt_sh(&cfg, output))) + fclose(lt_sh(&cfg, fout)); - if (cfg.sh.counts) + if (lt_sh(&cfg, counts)) lt_stats_show(&cfg); return 0; diff --git a/src/objsearch.c b/src/objsearch.c index ae0823f..ebc2074 100644 --- a/src/objsearch.c +++ b/src/objsearch.c @@ -56,7 +56,7 @@ static int add_subst(struct lt_config_audit *cfg, char *subst) *dst++ = 0x0; - PRINT_VERBOSE(cfg->sh.verbose, 2, "adding subst type %d, src [%s], dst [%s]\n", + PRINT_VERBOSE(cfg, 2, "adding subst type %d, src [%s], dst [%s]\n", type, src, dst); s = &cfg->subst[cfg->subst_cnt++]; @@ -80,7 +80,7 @@ static int add_subst(struct lt_config_audit *cfg, char *subst) static int match_path(struct lt_config_audit *cfg, const char *name, struct lt_objsearch *s, char **ret) { - PRINT_VERBOSE(cfg->sh.verbose, 2, "name [%s], src [%s], dst [%s]\n", + PRINT_VERBOSE(cfg, 2, "name [%s], src [%s], dst [%s]\n", name, s->src, s->dst); *ret = s->dst; @@ -106,7 +106,7 @@ static int match_ptn(struct lt_config_audit *cfg, const char *name, { char *pat, *r; - PRINT_VERBOSE(cfg->sh.verbose, 2, "name [%s], src [%s], dst [%s]\n", + PRINT_VERBOSE(cfg, 2, "name [%s], src [%s], dst [%s]\n", name, s->src, s->dst); pat = strstr(name, s->src); @@ -124,7 +124,7 @@ static int match_ptn(struct lt_config_audit *cfg, const char *name, strcpy(r, s->dst); strcat(r, pat + strlen(s->src)); - PRINT_VERBOSE(cfg->sh.verbose, 2, "return %s\n", *ret); + PRINT_VERBOSE(cfg, 2, "return %s\n", *ret); return 1; } @@ -142,7 +142,7 @@ static int match_ptn(struct lt_config_audit *cfg, const char *name, static int match_ptn2path(struct lt_config_audit *cfg, const char *name, struct lt_objsearch *s, char **ret) { - PRINT_VERBOSE(cfg->sh.verbose, 2, "name [%s], src [%s], dst [%s]\n", + PRINT_VERBOSE(cfg, 2, "name [%s], src [%s], dst [%s]\n", name, s->src, s->dst); *ret = s->dst; @@ -51,7 +51,7 @@ static int store_config(struct lt_config_app *cfg, char *file) return -1; } - if (-1 == write(fd, &cfg->sh, sizeof(cfg->sh))) { + if (-1 == write(fd, cfg->sh, sizeof(*cfg->sh))) { perror("read failed"); return -1; } @@ -103,7 +103,7 @@ static int get_fifo(struct lt_config_app *cfg, int notify_fd, sscanf(event->name, "fifo-%d", pid); sprintf(str_fifo, "%s/%s", dir, event->name); - PRINT_VERBOSE(cfg->sh.verbose, 1, "thread id %d, got fifo: %s\n", + PRINT_VERBOSE(cfg, 1, "thread id %d, got fifo: %s\n", *pid, str_fifo); return lt_fifo_open(cfg, str_fifo); @@ -120,20 +120,20 @@ static int process_fifo(struct lt_config_app *cfg, struct lt_thread *t) if ((FIFO_MSG_TYPE_ENTRY != mbase->type) && (FIFO_MSG_TYPE_EXIT != mbase->type)) { - PRINT_VERBOSE(cfg->sh.verbose, 1, "unexpected message type %d\n", + PRINT_VERBOSE(cfg, 1, "unexpected message type %d\n", mbase->type); return -1; } struct lt_fifo_msym *msym = (struct lt_fifo_msym*) buf; - if (cfg->sh.counts) + if (lt_sh(cfg, counts)) return lt_stats_sym(cfg, t, msym); if (FIFO_MSG_TYPE_ENTRY == msym->h.type) { - cfg->sh.indent_depth++; - lt_out_entry(&cfg->sh, &msym->h.tv, + lt_sh(cfg, indent_depth)++; + lt_out_entry(cfg->sh, &msym->h.tv, msym->data + msym->sym, msym->data + msym->lib, msym->data + msym->arg, @@ -141,13 +141,13 @@ static int process_fifo(struct lt_config_app *cfg, struct lt_thread *t) } else if (FIFO_MSG_TYPE_EXIT == msym->h.type) { - lt_out_exit(&cfg->sh, &msym->h.tv, + lt_out_exit(cfg->sh, &msym->h.tv, msym->data + msym->sym, msym->data + msym->lib, msym->data + msym->arg, msym->data + msym->argd); - cfg->sh.indent_depth--; + lt_sh(cfg, indent_depth)--; } return 0; @@ -274,7 +274,7 @@ int lt_run(struct lt_config_app *cfg) if (-1 == store_config(cfg, str_cfg)) return -1; - if (cfg->sh.pipe && + if (lt_sh(cfg, pipe) && (-1 == (notify_fd = set_dir_notify(str_dir)))) return -1; @@ -287,7 +287,7 @@ int lt_run(struct lt_config_app *cfg) setenv("LD_AUDIT", str_audit, 1); setenv("LT_DIR", str_dir, 1); - PRINT_VERBOSE(cfg->sh.verbose, 1, "executing %s\n", cfg->prog); + PRINT_VERBOSE(cfg, 1, "executing %s\n", cfg->prog); if (-1 == execvp(cfg->prog, cfg->arg)) { printf("execve failed for \"%s\" : %s\n", @@ -299,7 +299,7 @@ int lt_run(struct lt_config_app *cfg) return -1; } - if (cfg->sh.pipe) + if (lt_sh(cfg, pipe)) status = process(cfg, child_pid, str_dir, notify_fd); else waitpid(child_pid, &status, 0); diff --git a/src/stats.c b/src/stats.c index 59e0d9c..27f588d 100644 --- a/src/stats.c +++ b/src/stats.c @@ -83,8 +83,7 @@ int lt_stats_alloc(struct lt_config_app *cfg, struct lt_thread *t) return 0; } - - PRINT_VERBOSE(cfg->sh.verbose, 1, + PRINT_VERBOSE(cfg, 1, "too bad, out of symbols, reallocation... %p - %d\n", t->sym_array, t->sym_cnt); @@ -92,7 +91,7 @@ int lt_stats_alloc(struct lt_config_app *cfg, struct lt_thread *t) t->sym_max += LT_SYM_HMAX; hdestroy_r(&t->sym_htab); - PRINT_VERBOSE(cfg->sh.verbose, 1, "creating new hash table\n"); + PRINT_VERBOSE(cfg, 1, "creating new hash table\n"); if (!hcreate_r(t->sym_max, &t->sym_htab)) { perror("hcreate_r failed"); @@ -107,7 +106,7 @@ int lt_stats_alloc(struct lt_config_app *cfg, struct lt_thread *t) return -1; } - PRINT_VERBOSE(cfg->sh.verbose, 1, + PRINT_VERBOSE(cfg, 1, "adding symbols to new hash table %p\n", t->sym_array); @@ -119,8 +118,7 @@ int lt_stats_alloc(struct lt_config_app *cfg, struct lt_thread *t) e.key = sym->name; e.data = sym; - PRINT_VERBOSE(cfg->sh.verbose, 1, - "adding symbol %s\n", sym->name); + PRINT_VERBOSE(cfg, 1, "adding symbol %s\n", sym->name); if (0 == hsearch_r(e, ENTER, &ep, &t->sym_htab)) { printf("failed to add hash item during reallocation\n"); @@ -128,7 +126,7 @@ int lt_stats_alloc(struct lt_config_app *cfg, struct lt_thread *t) } } - PRINT_VERBOSE(cfg->sh.verbose, 1, "reallocation ok\n"); + PRINT_VERBOSE(cfg, 1, "reallocation ok\n"); return 0; } @@ -175,7 +173,7 @@ int lt_stats_sym(struct lt_config_app *cfg, struct lt_thread *t, t->sym_array[t->sym_cnt] = sym; t->sym_cnt++; - PRINT_VERBOSE(cfg->sh.verbose, 1, + PRINT_VERBOSE(cfg, 1, "adding symbol %d %s\n", t->sym_cnt, sym->name); } else free(e.key); @@ -246,7 +244,7 @@ static int lt_stats_show_thread(struct lt_config_app *cfg, struct lt_thread *t) struct timeval tv_thread_accu = { 0, 0}; float time_global; - PRINT_VERBOSE(cfg->sh.verbose, 1, "counting total time\n"); + PRINT_VERBOSE(cfg, 1, "counting total time\n"); for(i = 0; i < t->sym_cnt; i++) { struct lt_stats_sym *sym = t->sym_array[i]; tv_add(&tv_thread_accu, &tv_thread_accu, &sym->tv_all); @@ -254,7 +252,7 @@ static int lt_stats_show_thread(struct lt_config_app *cfg, struct lt_thread *t) time_global = tv_thread_accu.tv_sec * 1000000 + tv_thread_accu.tv_usec; - PRINT_VERBOSE(cfg->sh.verbose, 1, "counting post mortem statistics\n"); + PRINT_VERBOSE(cfg, 1, "counting post mortem statistics\n"); for(i = 0; i < t->sym_cnt; i++) { struct lt_stats_sym *sym = t->sym_array[i]; @@ -264,12 +262,12 @@ static int lt_stats_show_thread(struct lt_config_app *cfg, struct lt_thread *t) sym->usec_call = time_sym/sym->call; } - PRINT_VERBOSE(cfg->sh.verbose, 1, "sorting\n"); + PRINT_VERBOSE(cfg, 1, "sorting\n"); csort = cfg->csort; qsort(t->sym_array, t->sym_cnt, sizeof(struct lt_stats_sym*), qsort_compar); - PRINT_VERBOSE(cfg->sh.verbose, 1, "printing\n"); + PRINT_VERBOSE(cfg, 1, "printing\n"); tv_sub(&tv_thread_real, &t->tv_stop, &t->tv_start); printf("\nThread %d (runtime %u.%06u sec)\n", |