From 074fc0e4b3f5d24306c2995f2f3b0bd4759e8aeb Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Fri, 16 Oct 2009 20:08:01 -0400 Subject: perf: Use die() for error cases in perf-probe Use die() for exiting perf-probe with errors. This replaces perror_exit(), msg_exit() and fprintf()+exit() with die(), and uses die() in semantic_error(). This also renames 'die' local variables to 'dw_die' for avoiding name confliction. Signed-off-by: Masami Hiramatsu Cc: Frederic Weisbecker Cc: Arnaldo Carvalho de Melo Cc: Steven Rostedt Cc: Paul Mackerras Cc: Peter Zijlstra LKML-Reference: <20091017000801.16556.46866.stgit@dhcp-100-2-132.bos.redhat.com> Signed-off-by: Ingo Molnar --- tools/perf/builtin-probe.c | 47 ++++++++++++++-------------------------------- 1 file changed, 14 insertions(+), 33 deletions(-) (limited to 'tools/perf/builtin-probe.c') diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c index 73c883b715cc..a1467d12547a 100644 --- a/tools/perf/builtin-probe.c +++ b/tools/perf/builtin-probe.c @@ -49,6 +49,7 @@ const char *default_search_path[NR_SEARCH_PATH] = { #define MAX_PATH_LEN 256 #define MAX_PROBES 128 +#define MAX_PROBE_ARGS 128 /* Session management structure */ static struct { @@ -60,19 +61,7 @@ static struct { char *events[MAX_PROBES]; } session; -static void semantic_error(const char *msg) -{ - fprintf(stderr, "Semantic error: %s\n", msg); - exit(1); -} - -static void perror_exit(const char *msg) -{ - perror(msg); - exit(1); -} - -#define MAX_PROBE_ARGS 128 +#define semantic_error(msg ...) die("Semantic error :" msg) static int parse_probepoint(const struct option *opt __used, const char *str, int unset __used) @@ -109,7 +98,7 @@ static int parse_probepoint(const struct option *opt __used, /* Duplicate the argument */ argv[argc] = strndup(s, str - s); if (argv[argc] == NULL) - perror_exit("strndup"); + die("strndup"); if (++argc == MAX_PROBE_ARGS) semantic_error("Too many arguments"); debug("argv[%d]=%s\n", argc, argv[argc - 1]); @@ -171,7 +160,7 @@ static int parse_probepoint(const struct option *opt __used, if (pp->nr_args > 0) { pp->args = (char **)malloc(sizeof(char *) * pp->nr_args); if (!pp->args) - perror_exit("malloc"); + die("malloc"); memcpy(pp->args, &argv[2], sizeof(char *) * pp->nr_args); } @@ -260,7 +249,7 @@ static int write_new_event(int fd, const char *buf) printf("Adding new event: %s\n", buf); ret = write(fd, buf, strlen(buf)); if (ret <= 0) - perror("Error: Failed to create event"); + die("failed to create event."); return ret; } @@ -273,7 +262,7 @@ static int synthesize_probepoint(struct probe_point *pp) int i, len, ret; pp->probes[0] = buf = (char *)calloc(MAX_CMDLEN, sizeof(char)); if (!buf) - perror_exit("calloc"); + die("calloc"); ret = snprintf(buf, MAX_CMDLEN, "%s+%d", pp->function, pp->offset); if (ret <= 0 || ret >= MAX_CMDLEN) goto error; @@ -322,10 +311,8 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) ret = synthesize_probepoint(&session.probes[j]); if (ret == -E2BIG) semantic_error("probe point is too long."); - else if (ret < 0) { - perror("snprintf"); - return -1; - } + else if (ret < 0) + die("snprintf"); } #ifndef NO_LIBDWARF @@ -336,10 +323,8 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) fd = open(session.vmlinux, O_RDONLY); else fd = open_default_vmlinux(); - if (fd < 0) { - perror("vmlinux/module file open"); - return -1; - } + if (fd < 0) + die("vmlinux/module file open"); /* Searching probe points */ for (j = 0; j < session.nr_probe; j++) { @@ -349,10 +334,8 @@ int cmd_probe(int argc, const char **argv, const char *prefix __used) lseek(fd, SEEK_SET, 0); ret = find_probepoint(fd, pp); - if (ret <= 0) { - fprintf(stderr, "Error: No probe point found.\n"); - return -1; - } + if (ret <= 0) + die("No probe point found.\n"); debug("probe event %s found\n", session.events[j]); } close(fd); @@ -363,10 +346,8 @@ setup_probes: /* Settng up probe points */ snprintf(buf, MAX_CMDLEN, "%s/../kprobe_events", debugfs_path); fd = open(buf, O_WRONLY, O_APPEND); - if (fd < 0) { - perror("kprobe_events open"); - return -1; - } + if (fd < 0) + die("kprobe_events open"); for (j = 0; j < session.nr_probe; j++) { pp = &session.probes[j]; if (pp->found == 1) { -- cgit v1.2.3