Cleanup: Replace all perror() uses by the PERROR macro
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 5 Jan 2015 21:30:41 +0000 (16:30 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 7 Jan 2015 20:54:10 +0000 (15:54 -0500)
PERROR prints the perror() message in our own logging format rather
than going straight to stderr.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
15 files changed:
TODO
src/bin/lttng-sessiond/fd-limit.c
src/bin/lttng-sessiond/main.c
src/bin/lttng/commands/add_context.c
src/bin/lttng/commands/list.c
src/bin/lttng/commands/view.c
src/bin/lttng/conf.c
src/bin/lttng/lttng.c
src/bin/lttng/utils.c
src/common/compat/compat-poll.c
src/common/compat/poll.h
src/common/consumer.c
src/lib/lttng-ctl/filter/memstream.h
src/lib/lttng-ctl/lttng-ctl.c
tests/regression/tools/live/live_test.c

diff --git a/TODO b/TODO
index 9688bccac2e795de5140bf67318c9093371fbbe4..7ae95c2ab7366c7d06951600574c0af6491845b5 100644 (file)
--- 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).
index 17a18afdc7b3f1d8f968f21b6555c2a6f661508d..aefe62f24222fede390779f1d74b5fa39f0af3c4 100644 (file)
@@ -23,6 +23,7 @@
 #include <errno.h>
 #include <stdio.h>
 #include "fd-limit.h"
+#include <common/error.h>
 
 /* 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;
 }
index bc3a6bb445735baf9937ab699be70cab02c3a11c..0dbec232fe90c3dcca0e9fea4166fee09099e592 100644 (file)
@@ -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;
index 6dc29d0670b3bb5883e7e39b39d2514107eb3b61..cf3f3efcf36f87464e5c5eb05425e6bcfccbbd8e 100644 (file)
@@ -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;
                        }
index 14e390a030445c690f03bae266ca16bb1dead774..aaa8f47a9ec4b157e44ca68fe9b4e0a9d712f161 100644 (file)
@@ -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:
index 1de6940aa8c1612342ba53a56f9e36c7329609e5..e1e1564c16ebe9f0e3650a27ac80eac1d7c34638 100644 (file)
@@ -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;
        }
 
index 3a40ec5208edad530ae923c2d72b791c9f0ee276..7e6c833449857890fa7c8e8a092eaf97d439a750 100644 (file)
@@ -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);
index 34ccd59c517a6a737f8953cc717f4de28e8f9f60..154f6df6b5e31e16d54e275e183290dd61775b33 100644 (file)
@@ -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;
        }
index 3cc254a3c9e40e8b5c5df5c64ebf942bacca82a0..ef8d0235a019229cf0c4c1b92c33a58275f8a6de 100644 (file)
@@ -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;
index 32932448dfdb6816e372546788bc393ed917f924..6d34a0e69cbba04d133430d11fbce0626612bad0 100644 (file)
@@ -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;
        }
 
index f892c832333eb10bdfcc4cf64d66918c17d3ab02..9f59d35c3c84faf821f1237416d743f1412bb2e1 100644 (file)
@@ -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");
                }
        }
 
index 1333263f186e4c2b221fa68d7b73399d1c3be139..f2662cddadd5e8d3b98d7ebcc4f7c386a8552c78 100644 (file)
@@ -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.
                 */
index 2cbb03559b154c322e0bb7f8f3c1518c72fa0f75..7b7797cfaa1ad394ba5aaa4b8d4770fe3c119c27 100644 (file)
@@ -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);
index 4a0a07b14ec1a08faba8c2b94199f2ef7a6e7f54..f879d8ddfd2ea7b036df41a12d256809cee3a715 100644 (file)
@@ -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;
index d2c9050f615fe6e3f04a4935afca7798e45f1de6..e30c3915232e2de44bd7ba23d450129eeaa66f99 100644 (file)
@@ -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 {
This page took 0.038745 seconds and 4 git commands to generate.