summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorjolsa@redhat.com <jolsa@redhat.com>2011-10-21 11:10:40 +0200
committerJiri Olsa <Jiri Olsa jolsa@redhat.com>2011-11-24 21:20:27 +0100
commit27b90e3d32a6c311fca017f55d0fb8e2a1bd451e (patch)
tree3d374c2cb0f6b81ec98c15b322377f799f876d07 /src
parentbf775c23afef014f9e11796741786e032d0ec374 (diff)
downloadlatrace-27b90e3d32a6c311fca017f55d0fb8e2a1bd451e.tar.gz
latrace-27b90e3d32a6c311fca017f55d0fb8e2a1bd451e.tar.xz
latrace-27b90e3d32a6c311fca017f55d0fb8e2a1bd451e.zip
error simulation: automation library part
Diffstat (limited to 'src')
-rw-r--r--src/audit-error.c64
-rw-r--r--src/audit-init.c14
2 files changed, 58 insertions, 20 deletions
diff --git a/src/audit-error.c b/src/audit-error.c
index b313a56..3824d18 100644
--- a/src/audit-error.c
+++ b/src/audit-error.c
@@ -119,6 +119,7 @@ int lt_error_sym_exit(struct lt_config_audit *cfg,
La_retval *outregs)
{
struct lt_error_sym *esym;
+ struct lt_error_config *cfg_err = cfg->error_config;
/* we're not interested in this symbol */
if (!sym || !sym->error)
@@ -127,10 +128,10 @@ int lt_error_sym_exit(struct lt_config_audit *cfg,
esym = sym->error;
PRINT_VERBOSE(cfg, 1, "symbol %s, call %lu, n %ld\n",
- sym->name, esym->call, lt_sh(cfg, error_def.n));
+ sym->name, esym->call, cfg_err->n);
/* we are not interested in this call number */
- if (esym->call++ != lt_sh(cfg, error_def.n))
+ if (esym->call++ != cfg_err->n)
return -1;
PRINT_VERBOSE(cfg, 1, "changing retval to %lu\n",
@@ -150,13 +151,13 @@ int lt_error_sym_exit(struct lt_config_audit *cfg,
}
static int symbol_add(struct lt_config_audit *cfg,
- struct lt_error_def_sym *def_sym)
+ struct lt_error_config_sym *cfg_sym)
{
ENTRY e, *ep;
struct lt_error_sym *sym;
PRINT_VERBOSE(cfg, 1, "symbol %s, ret %ld\n",
- def_sym->symbol, def_sym->ret);
+ cfg_sym->symbol, cfg_sym->ret);
/* should be safe, since only one thread
* is doing the initialization */
@@ -175,9 +176,9 @@ static int symbol_add(struct lt_config_audit *cfg,
return -1;
}
- sym->name = strdup(def_sym->symbol);
- sym->ret = def_sym->ret;
- sym->handle_sigsegv = def_sym->handle_sigsegv;
+ sym->name = strdup(cfg_sym->symbol);
+ sym->ret = cfg_sym->ret;
+ sym->handle_sigsegv = cfg_sym->handle_sigsegv;
e.key = sym->name;
e.data = sym;
@@ -198,20 +199,17 @@ static int symbol_add(struct lt_config_audit *cfg,
int lt_error_init(struct lt_config_audit *cfg)
{
- struct lt_error_def *error_def = &lt_sh(cfg, error_def);
- int i = 0, ok = 1;
+ struct lt_error_config *cfg_err = cfg->error_config;
+ int sym_cnt = cfg_err->sym_cnt, i, ok = 1;
lt_sh(cfg, error_sim) = 0;
+ for(i = 0; i < sym_cnt; i++) {
+ struct lt_error_config_sym *cfg_sym;
- for(i = 0; (i < LT_ERROR_MAXSYM); i++) {
- struct lt_error_def_sym *sym_def;
+ cfg_sym = &cfg_err->sym[i];
- sym_def = &error_def->sym[i];
- if (!*sym_def->symbol)
- break;
-
- if (symbol_add(cfg, sym_def)) {
+ if (symbol_add(cfg, cfg_sym)) {
ok = 0;
break;
}
@@ -226,3 +224,37 @@ int lt_error_init(struct lt_config_audit *cfg)
lt_sh(cfg, error_sim) = 1;
return 0;
}
+
+int lt_error_config_read(struct lt_config_audit *cfg, int fd)
+{
+ int size;
+ struct lt_error_config *cfg_err, cfg_err_st;
+
+ if (-1 == read(fd, &cfg_err_st, sizeof(cfg_err_st))) {
+ perror("read failed");
+ return -1;
+ }
+
+ size = cfg_err_st.sym_cnt * sizeof(struct lt_error_config_sym);
+ if (size <= 0) {
+ PRINT_VERBOSE(cfg, 1, "failed: no error symbols defined\n");
+ return -1;
+ }
+
+ cfg_err = malloc(sizeof(*cfg_err) + size);
+ if (!cfg_err) {
+ perror("malloc failed");
+ return -1;
+ }
+
+ *cfg_err = cfg_err_st;
+
+ if (size != read(fd, cfg_err->sym, size)) {
+ PRINT_VERBOSE(cfg, 1, "failed: no error symbols defined\n");
+ return -1;
+ }
+
+ cfg->error_config = cfg_err;
+
+ return size + sizeof(cfg_err_st);
+}
diff --git a/src/audit-init.c b/src/audit-init.c
index 092bb0c..0324508 100644
--- a/src/audit-init.c
+++ b/src/audit-init.c
@@ -70,7 +70,7 @@ static int init_ctl_config(char *file)
static int read_config(char *dir)
{
int fd;
- off_t len;
+ off_t len, extra_size = 0;
char file[LT_MAXFILE];
memset(&cfg, 0, sizeof(cfg));
@@ -88,12 +88,20 @@ static int read_config(char *dir)
return -1;
}
+ cfg.sh = cfg.sh_storage.sh = &cfg.sh_storage;
+
+ if (lt_sh(&cfg, error_sim)) {
+ extra_size = lt_error_config_read(&cfg, fd);
+ if (extra_size < 0)
+ return -1;
+ }
+
if (-1 == (len = lseek(fd, 0, SEEK_END))) {
perror("lseek failed");
return -1;
}
- if (len != sizeof(cfg.sh_storage)) {
+ if ((len - extra_size) != sizeof(cfg.sh_storage)) {
printf("config file size differs\n");
return -1;
}
@@ -103,8 +111,6 @@ static int read_config(char *dir)
return -1;
}
- cfg.sh = cfg.sh_storage.sh = &cfg.sh_storage;
-
/*
* If we are not controled, we can close the file,
* since we read everything we needed.