From: Jérémie Galarneau Date: Mon, 5 Jan 2015 21:30:41 +0000 (-0500) Subject: Cleanup: Replace all perror() uses by the PERROR macro X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=6f04ed72990f6c72d16fd08d39feac0967da732e Cleanup: Replace all perror() uses by the PERROR macro PERROR prints the perror() message in our own logging format rather than going straight to stderr. Signed-off-by: Jérémie Galarneau --- diff --git a/TODO b/TODO index 9688bccac..7ae95c2ab 100644 --- a/TODO +++ b/TODO @@ -3,7 +3,6 @@ TODOS: * Add --socket option if no HOME found (sessiond) * Use realloc() in ask_sessiond() (liblttngctl) -* perror() --> PERROR() (everywhere in the code) * Add a command to "lttng" to consume data when the tracer is in flightrecorder mode * Fix error handling for UST support when enabling events on all applications. * Support for UST remaining domains (PID, EXEC_NAME, FOLLOW_CHILDREN). diff --git a/src/bin/lttng-sessiond/fd-limit.c b/src/bin/lttng-sessiond/fd-limit.c index 17a18afdc..aefe62f24 100644 --- a/src/bin/lttng-sessiond/fd-limit.c +++ b/src/bin/lttng-sessiond/fd-limit.c @@ -23,6 +23,7 @@ #include #include #include "fd-limit.h" +#include /* total count of fd. */ static long fd_count; @@ -65,7 +66,7 @@ void lttng_fd_init(void) ret = getrlimit(RLIMIT_NOFILE, &rlim); if (ret < 0) { - perror("getrlimit"); + PERROR("getrlimit"); } max_nr_fd = rlim.rlim_cur; } diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index bc3a6bb44..0dbec232f 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -4363,7 +4363,7 @@ static int set_option(int opt, const char *arg, const char *optname) } tracing_group_name = strdup(arg); if (!tracing_group_name) { - perror("strdup"); + PERROR("strdup"); ret = -ENOMEM; } tracing_group_name_override = 1; @@ -4427,7 +4427,7 @@ static int set_option(int opt, const char *arg, const char *optname) } consumerd32_bin = strdup(arg); if (!consumerd32_bin) { - perror("strdup"); + PERROR("strdup"); ret = -ENOMEM; } consumerd32_bin_override = 1; @@ -4438,7 +4438,7 @@ static int set_option(int opt, const char *arg, const char *optname) } consumerd32_libdir = strdup(arg); if (!consumerd32_libdir) { - perror("strdup"); + PERROR("strdup"); ret = -ENOMEM; } consumerd32_libdir_override = 1; @@ -4449,7 +4449,7 @@ static int set_option(int opt, const char *arg, const char *optname) } consumerd64_bin = strdup(arg); if (!consumerd64_bin) { - perror("strdup"); + PERROR("strdup"); ret = -ENOMEM; } consumerd64_bin_override = 1; @@ -4460,7 +4460,7 @@ static int set_option(int opt, const char *arg, const char *optname) } consumerd64_libdir = strdup(arg); if (!consumerd64_libdir) { - perror("strdup"); + PERROR("strdup"); ret = -ENOMEM; } consumerd64_libdir_override = 1; @@ -4469,7 +4469,7 @@ static int set_option(int opt, const char *arg, const char *optname) free(opt_pidfile); opt_pidfile = strdup(arg); if (!opt_pidfile) { - perror("strdup"); + PERROR("strdup"); ret = -ENOMEM; } break; @@ -4495,7 +4495,7 @@ static int set_option(int opt, const char *arg, const char *optname) free(opt_load_session_path); opt_load_session_path = strdup(arg); if (!opt_load_session_path) { - perror("strdup"); + PERROR("strdup"); ret = -ENOMEM; } break; @@ -4503,7 +4503,7 @@ static int set_option(int opt, const char *arg, const char *optname) free(kmod_probes_list); kmod_probes_list = strdup(arg); if (!kmod_probes_list) { - perror("strdup"); + PERROR("strdup"); ret = -ENOMEM; } break; @@ -4511,7 +4511,7 @@ static int set_option(int opt, const char *arg, const char *optname) free(kmod_extra_probes_list); kmod_extra_probes_list = strdup(arg); if (!kmod_extra_probes_list) { - perror("strdup"); + PERROR("strdup"); ret = -ENOMEM; } break; diff --git a/src/bin/lttng/commands/add_context.c b/src/bin/lttng/commands/add_context.c index 6dc29d067..cf3f3efcf 100644 --- a/src/bin/lttng/commands/add_context.c +++ b/src/bin/lttng/commands/add_context.c @@ -718,7 +718,7 @@ int cmd_add_context(int argc, const char **argv) type = zmalloc(sizeof(struct ctx_type)); if (type == NULL) { - perror("malloc ctx_type"); + PERROR("malloc ctx_type"); ret = CMD_FATAL; goto end; } diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.c index 14e390a03..aaa8f47a9 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.c @@ -131,12 +131,12 @@ static char *get_cmdline_by_pid(pid_t pid) /* Caller must free() *cmdline */ cmdline = zmalloc(PATH_MAX); if (!cmdline) { - perror("malloc cmdline"); + PERROR("malloc cmdline"); goto end; } ret = fread(cmdline, 1, PATH_MAX, fp); if (ret < 0) { - perror("fread proc list"); + PERROR("fread proc list"); } end: diff --git a/src/bin/lttng/commands/view.c b/src/bin/lttng/commands/view.c index 1de6940aa..e1e1564c1 100644 --- a/src/bin/lttng/commands/view.c +++ b/src/bin/lttng/commands/view.c @@ -316,14 +316,14 @@ static char *build_live_path(char *session_name) ret = gethostname(hostname, sizeof(hostname)); if (ret < 0) { - perror("gethostname"); + PERROR("gethostname"); goto error; } ret = asprintf(&path, "net://localhost/host/%s/%s", hostname, session_name); if (ret < 0) { - perror("asprintf live path"); + PERROR("asprintf live path"); goto error; } diff --git a/src/bin/lttng/conf.c b/src/bin/lttng/conf.c index 3a40ec520..7e6c83344 100644 --- a/src/bin/lttng/conf.c +++ b/src/bin/lttng/conf.c @@ -144,7 +144,7 @@ void config_destroy(char *path) DBG("Removing %s\n", config_path); ret = remove(config_path); if (ret < 0) { - perror("remove config file"); + PERROR("remove config file"); } end: free(config_path); diff --git a/src/bin/lttng/lttng.c b/src/bin/lttng/lttng.c index 34ccd59c5..154f6df6b 100644 --- a/src/bin/lttng/lttng.c +++ b/src/bin/lttng/lttng.c @@ -238,7 +238,7 @@ static int set_signal_handler(void) sigset_t sigset; if ((ret = sigemptyset(&sigset)) < 0) { - perror("sigemptyset"); + PERROR("sigemptyset"); goto end; } @@ -246,17 +246,17 @@ static int set_signal_handler(void) sa.sa_mask = sigset; sa.sa_flags = 0; if ((ret = sigaction(SIGUSR1, &sa, NULL)) < 0) { - perror("sigaction"); + PERROR("sigaction"); goto end; } if ((ret = sigaction(SIGTERM, &sa, NULL)) < 0) { - perror("sigaction"); + PERROR("sigaction"); goto end; } if ((ret = sigaction(SIGCHLD, &sa, NULL)) < 0) { - perror("sigaction"); + PERROR("sigaction"); goto end; } @@ -324,7 +324,7 @@ static int spawn_sessiond(char *pathname) if (errno == ENOENT) { ERR("No session daemon found. Use --sessiond-path."); } else { - perror("execlp"); + PERROR("execlp"); } kill(getppid(), SIGTERM); /* wake parent */ exit(EXIT_FAILURE); @@ -350,7 +350,7 @@ static int spawn_sessiond(char *pathname) } goto end; } else { - perror("fork"); + PERROR("fork"); ret = -1; goto end; } diff --git a/src/bin/lttng/utils.c b/src/bin/lttng/utils.c index 3cc254a3c..ef8d0235a 100644 --- a/src/bin/lttng/utils.c +++ b/src/bin/lttng/utils.c @@ -321,14 +321,14 @@ int spawn_relayd(const char *pathname, int port) if (errno == ENOENT) { ERR("No relayd found. Use --relayd-path."); } else { - perror("execlp"); + PERROR("execlp"); } kill(getppid(), SIGTERM); /* wake parent */ exit(EXIT_FAILURE); } else if (pid > 0) { goto end; } else { - perror("fork"); + PERROR("fork"); ret = -1; goto end; } @@ -349,7 +349,7 @@ int check_relayd(void) fd = socket(AF_INET, SOCK_STREAM, 0); if (fd < 0) { - perror("socket check relayd"); + PERROR("socket check relayd"); ret = -1; goto error_socket; } @@ -358,7 +358,7 @@ int check_relayd(void) sin.sin_port = htons(DEFAULT_NETWORK_VIEWER_PORT); ret = inet_pton(sin.sin_family, "127.0.0.1", &sin.sin_addr); if (ret < 1) { - perror("inet_pton check relayd"); + PERROR("inet_pton check relayd"); ret = -1; goto error; } @@ -378,7 +378,7 @@ int check_relayd(void) error: if (close(fd) < 0) { - perror("close relayd fd"); + PERROR("close relayd fd"); } error_socket: return ret; diff --git a/src/common/compat/compat-poll.c b/src/common/compat/compat-poll.c index 32932448d..6d34a0e69 100644 --- a/src/common/compat/compat-poll.c +++ b/src/common/compat/compat-poll.c @@ -127,7 +127,7 @@ int compat_poll_create(struct lttng_poll_event *events, int size) /* This *must* be freed by using lttng_poll_free() */ wait->events = zmalloc(size * sizeof(struct pollfd)); if (wait->events == NULL) { - perror("zmalloc struct pollfd"); + PERROR("zmalloc struct pollfd"); goto error; } @@ -135,7 +135,7 @@ int compat_poll_create(struct lttng_poll_event *events, int size) current->events = zmalloc(size * sizeof(struct pollfd)); if (current->events == NULL) { - perror("zmalloc struct current pollfd"); + PERROR("zmalloc struct current pollfd"); goto error; } @@ -279,7 +279,7 @@ int compat_poll_wait(struct lttng_poll_event *events, int timeout) ret = poll(events->wait.events, events->wait.nb_fd, timeout); if (ret < 0) { /* At this point, every error is fatal */ - perror("poll wait"); + PERROR("poll wait"); goto error; } @@ -306,7 +306,7 @@ void compat_poll_set_max_size(void) ret = getrlimit(RLIMIT_NOFILE, &lim); if (ret < 0) { - perror("getrlimit poll RLIMIT_NOFILE"); + PERROR("getrlimit poll RLIMIT_NOFILE"); return; } diff --git a/src/common/compat/poll.h b/src/common/compat/poll.h index f892c8323..9f59d35c3 100644 --- a/src/common/compat/poll.h +++ b/src/common/compat/poll.h @@ -217,7 +217,7 @@ static inline void lttng_poll_clean(struct lttng_poll_event *events) if (events->epfd >= 0) { ret = close(events->epfd); if (ret) { - perror("close"); + PERROR("close"); } } diff --git a/src/common/consumer.c b/src/common/consumer.c index 1333263f1..f2662cdda 100644 --- a/src/common/consumer.c +++ b/src/common/consumer.c @@ -1430,7 +1430,7 @@ static int write_relayd_metadata_id(int fd, ret = lttng_write(fd, (void *) &hdr, sizeof(hdr)); if (ret < sizeof(hdr)) { /* - * This error means that the fd's end is closed so ignore the perror + * This error means that the fd's end is closed so ignore the PERROR * not to clubber the error output since this can happen in a normal * code path. */ diff --git a/src/lib/lttng-ctl/filter/memstream.h b/src/lib/lttng-ctl/filter/memstream.h index 2cbb03559..7b7797cfa 100644 --- a/src/lib/lttng-ctl/filter/memstream.h +++ b/src/lib/lttng-ctl/filter/memstream.h @@ -73,25 +73,25 @@ FILE *lttng_fmemopen(void *buf, size_t size, const char *mode) } ret = fseek(fp, 0L, SEEK_SET); if (ret < 0) { - perror("fseek"); + PERROR("fseek"); goto error_close; } /* We keep the handle open, but can unlink the file on the VFS. */ ret = unlink(tmpname); if (ret < 0) { - perror("unlink"); + PERROR("unlink"); } return fp; error_close: ret = fclose(fp); if (ret < 0) { - perror("close"); + PERROR("close"); } error_unlink: ret = unlink(tmpname); if (ret < 0) { - perror("unlink"); + PERROR("unlink"); } return NULL; } @@ -148,14 +148,14 @@ FILE *lttng_open_memstream(char **ptr, size_t *sizeloc) */ ret = unlink(tmpname); if (ret < 0) { - perror("unlink"); + PERROR("unlink"); } return fp; error_unlink: ret = unlink(tmpname); if (ret < 0) { - perror("unlink"); + PERROR("unlink"); } return NULL; } @@ -170,17 +170,17 @@ int lttng_close_memstream(char **buf, size_t *size, FILE *fp) ret = fflush(fp); if (ret < 0) { - perror("fflush"); + PERROR("fflush"); return ret; } ret = fseek(fp, 0L, SEEK_END); if (ret < 0) { - perror("fseek"); + PERROR("fseek"); return ret; } pos = ftell(fp); if (ret < 0) { - perror("ftell"); + PERROR("ftell"); return ret; } *size = pos; @@ -191,7 +191,7 @@ int lttng_close_memstream(char **buf, size_t *size, FILE *fp) } ret = fseek(fp, 0L, SEEK_SET); if (ret < 0) { - perror("fseek"); + PERROR("fseek"); goto error_free; } /* Copy the entire file into the buffer */ @@ -207,7 +207,7 @@ int lttng_close_memstream(char **buf, size_t *size, FILE *fp) } ret = fclose(fp); if (ret < 0) { - perror("fclose"); + PERROR("fclose"); return ret; } return 0; @@ -215,7 +215,7 @@ int lttng_close_memstream(char **buf, size_t *size, FILE *fp) error_close: ret = fclose(fp); if (ret < 0) { - perror("fclose"); + PERROR("fclose"); } error_free: free(*buf); diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 4a0a07b14..f879d8ddf 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -221,19 +221,19 @@ int lttng_check_tracing_group(void) /* Get number of supplementary group IDs */ grp_list_size = getgroups(0, NULL); if (grp_list_size < 0) { - perror("getgroups"); + PERROR("getgroups"); goto end; } /* Alloc group list of the right size */ grp_list = zmalloc(grp_list_size * sizeof(gid_t)); if (!grp_list) { - perror("malloc"); + PERROR("malloc"); goto end; } grp_id = getgroups(grp_list_size, grp_list); if (grp_id < 0) { - perror("getgroups"); + PERROR("getgroups"); goto free_list; } @@ -275,7 +275,7 @@ static int try_connect_sessiond(const char *sock_path) ret = lttcomm_close_unix_sock(ret); if (ret < 0) { - perror("lttcomm_close_unix_sock"); + PERROR("lttcomm_close_unix_sock"); } return 0; @@ -858,7 +858,7 @@ static int generate_filter(char *filter_expression, /* No need to keep the memory stream. */ if (fclose(fmem) != 0) { - perror("fclose"); + PERROR("fclose"); } *ctxp = ctx; @@ -869,7 +869,7 @@ parse_error: filter_parser_ctx_free(ctx); filter_alloc_error: if (fclose(fmem) != 0) { - perror("fclose"); + PERROR("fclose"); } error: return ret; diff --git a/tests/regression/tools/live/live_test.c b/tests/regression/tools/live/live_test.c index d2c9050f6..e30c39152 100644 --- a/tests/regression/tools/live/live_test.c +++ b/tests/regression/tools/live/live_test.c @@ -93,7 +93,7 @@ int connect_viewer(char *hostname) } if ((control_sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) { - perror("Socket"); + PERROR("Socket"); ret = -1; goto end; } @@ -105,7 +105,7 @@ int connect_viewer(char *hostname) if (connect(control_sock, (struct sockaddr *) &server_addr, sizeof(struct sockaddr)) == -1) { - perror("Connect"); + PERROR("Connect"); ret = -1; goto end; } @@ -420,7 +420,7 @@ int get_metadata(void) data = zmalloc(len); if (!data) { - perror("relay data zmalloc"); + PERROR("relay data zmalloc"); goto error; } do {