diff options
| author | Jiri Olsa <Jiri Olsa jolsa@redhat.com> | 2010-02-13 21:24:45 +0100 |
|---|---|---|
| committer | Jiri Olsa <Jiri Olsa jolsa@redhat.com> | 2010-02-13 21:24:45 +0100 |
| commit | d2dc8169c4f2c97e4c6a92505cdb97243e22d9cc (patch) | |
| tree | e811001eca9d2d4e7b4dffb6254e2d9aefcde841 /src/ctl.c | |
| parent | 7cfcb7e6a024d27e2bc9756d8a8595d7ecb50811 (diff) | |
| download | latrace-d2dc8169c4f2c97e4c6a92505cdb97243e22d9cc.tar.gz latrace-d2dc8169c4f2c97e4c6a92505cdb97243e22d9cc.tar.xz latrace-d2dc8169c4f2c97e4c6a92505cdb97243e22d9cc.zip | |
controled config feature and disable auditing feature
Diffstat (limited to 'src/ctl.c')
| -rw-r--r-- | src/ctl.c | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/src/ctl.c b/src/ctl.c new file mode 100644 index 0000000..bbbd7ed --- /dev/null +++ b/src/ctl.c @@ -0,0 +1,107 @@ +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <sys/mman.h> +#include <errno.h> +#include <stdlib.h> +#include <string.h> +#include <getopt.h> + +#include "config.h" + + +static void usage() NORETURN; +static void usage() +{ + printf("usage: latrace-ctl [-d] config\n\n"); + printf(" -d <0/1> - disable/enable auditing\n"); + printf("\n"); + + exit(1); +} + +static int mmap_config(struct lt_config_ctl *cfg) +{ + struct lt_config_shared* sh; + int page = sysconf(_SC_PAGE_SIZE); + int fd, len; + + if (-1 == (fd = open(cfg->config, O_RDWR))) { + perror("open failed"); + return -1; + } + + /* align the shared config length */ + len = sizeof(struct lt_config_shared); + len = (len + page) & ~(page - 1); + + sh = mmap(NULL, len, + PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0); + + if ((void *) -1 == sh) { + PRINT_VERBOSE(cfg, 1, + "mmap failed: %s\n", strerror(errno)); + return -1; + } + + cfg->sh = sh; + return 0; +} + +static int config_ctl(struct lt_config_ctl *cfg, int argc, char **argv) +{ + memset(cfg, 0x0, sizeof(*cfg)); + + while (1) { + int c; + int option_index = 0; + static struct option long_options[] = { + {"disable", required_argument, 0, 'd'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0} + }; + + c = getopt_long(argc, argv, "+d:", + long_options, &option_index); + + if (c == -1) + break; + + switch (c) { + case 'd': + cfg->set_disabled = 1; + cfg->disabled = atoi(optarg); + break; + }; /* switch */ + } /* while */ + + if (optind < argc) + cfg->config = argv[optind]; + else { + printf("failed: no config specified\n"); + usage(); + } + + return 0; +} + +int main_ctl(int argc, char **argv) +{ + struct lt_config_ctl cfg; + + if (config_ctl(&cfg, argc, argv)) + return -1; + + if (mmap_config(&cfg)) + return -1; + + printf("controling config %s\n", cfg.config); + + if (cfg.set_disabled) { + printf(" -> disabled = %d\n", cfg.disabled); + lt_sh(&cfg, disabled) = cfg.disabled; + } + + return 0; +} |
