Don't output errors in dlogutil outside of logutil.c 65/214365/2
authorMateusz Majewski <m.majewski2@samsung.com>
Fri, 20 Sep 2019 12:07:50 +0000 (14:07 +0200)
committerMateusz Majewski <m.majewski2@samsung.com>
Mon, 23 Sep 2019 06:15:45 +0000 (08:15 +0200)
This is useful, beacuse those functions will probably end up being used
in libdlogutil, and writing to stderr in a library seems like a bad
idea.

Change-Id: Ic07ed3548bf901ea4878d4a54a3824a0760a9b88

src/logutil/logutil.c
src/shared/fdi_logger.c
src/shared/fdi_pipe.c
src/shared/logprint.c
src/shared/logretrieve.c

index 3172d24..cfa0e00 100644 (file)
@@ -289,11 +289,16 @@ int main(int argc, char **argv)
                }
        }
 
-       if (action == ACTION_PRINT)
-               return do_print(fdi_ptrs, fdi_cnt, logfile_callback, &(struct logfile_callback_data) {
+       if (action == ACTION_PRINT) {
+               int r = do_print(fdi_ptrs, fdi_cnt, logfile_callback, &(struct logfile_callback_data) {
                        .file = &l_file,
                        .sort_by = proper_sort_by,
-               }, sorting_needed, proper_sort_by, &conf, &opt) == 0 ? 0 : 1;
+               }, sorting_needed, proper_sort_by, &conf, &opt);
+               if (r < 0) {
+                       ERR("Error while printing logs: %s\n", strerror(-r));
+                       return r;
+               }
+       }
 
        return 0;
 }
index 8faa248..7c26bc4 100644 (file)
@@ -43,11 +43,8 @@ static int logger_ioctl(int fd, int ioctl_id)
        assert(fd >= 0);
 
        int ret = ioctl(fd, ioctl_id);
-       if (ret < 0) {
-               int saved_errno = errno;
-               DBG("Android Logger ioctl %d failed %s\n", ioctl_id, strerror(saved_errno));
-               return -saved_errno;
-       }
+       if (ret < 0)
+               return -errno;
        return ret;
 }
 
index d396719..24d278a 100644 (file)
@@ -66,11 +66,7 @@ static int pipe_clear(struct fd_info *fdi)
        assert(ppd);
        assert(ppd->sock_fd >= 0);
 
-       int r = send_dlog_request(ppd->sock_fd, DLOG_REQ_CLEAR, NULL, 0);
-       if (r < 0)
-               ERR("Error: could not send a CLEAR request to logger %s\n", strerror(-r));
-
-       return r;
+       return send_dlog_request(ppd->sock_fd, DLOG_REQ_CLEAR, NULL, 0);
 }
 
 /**
@@ -107,11 +103,7 @@ static int send_logger_request(list_head filters, int dump, int sock_fd)
                len += needed;
        }
 
-       int r = send_dlog_request(sock_fd, DLOG_REQ_HANDLE_LOGUTIL, request_string, len);
-       if (r < 0)
-               ERR("Error: could not send a logger request; socket write failed\n");
-
-       return r;
+       return send_dlog_request(sock_fd, DLOG_REQ_HANDLE_LOGUTIL, request_string, len);
 }
 
 /**
@@ -131,20 +123,15 @@ static int pipe_create(struct fd_info *fdi, const struct log_config *conf, const
        snprintf(conf_key, sizeof(conf_key), "%s_ctl_sock", name);
 
        const char *sock_path = log_config_get(conf, conf_key);
-       if (!sock_path) {
-               ERR("Error: no config entry for  %s!\n", conf_key);
+       if (!sock_path)
                return -ENOENT;
-       }
 
        int sock_fd = connect_sock(sock_path);
-       if (sock_fd < 0) {
-               ERR("Error: Could not connect to socket %s %s!\n", sock_path, strerror(-sock_fd));
+       if (sock_fd < 0)
                return sock_fd;
-       }
 
        struct pipe_priv_data *ppd = malloc(sizeof *ppd);
        if (!ppd) {
-               ERR("Error: not enough memory\n");
                close(sock_fd);
                return -ENOMEM;
        }
index c8f20d9..4036a34 100644 (file)
@@ -536,10 +536,8 @@ int log_add_filter_tid(log_filter *p_filter, pthread_t tid)
  */
 char* log_buffer_get_tag(const struct logger_entry *entry)
 {
-       if (entry->len - (int) sizeof(struct logger_entry) < 2) {
-               fprintf(stderr, "Entry too small\n");
+       if (entry->len - (int) sizeof(struct logger_entry) < 2)
                return NULL;
-       }
 
        return (char*)entry->msg;
 }
@@ -552,10 +550,8 @@ char* log_buffer_get_tag(const struct logger_entry *entry)
  */
 char* log_buffer_get_message(const struct logger_entry *entry)
 {
-       if (entry->len - (int) sizeof(struct logger_entry) < 2) {
-               fprintf(stderr, "Entry too small\n");
+       if (entry->len - (int) sizeof(struct logger_entry) < 2)
                return NULL;
-       }
 
        return (char*)entry->msg + entry->tag_len + 1 /* NULL delimiter */;
 }
index d18a03c..f1877d2 100644 (file)
@@ -11,10 +11,8 @@ static const int default_buffers = (1 << LOG_ID_MAIN) | (1 << LOG_ID_SYSTEM) | (
 int validate_buffers(int *enabled_buffers)
 {
        if (*enabled_buffers &  (1 << LOG_ID_KMSG)
-       &&  *enabled_buffers & ~(1 << LOG_ID_KMSG)) {
-               ERR("Error: mixing KMSG and other buffers is not allowed\n");
+       &&  *enabled_buffers & ~(1 << LOG_ID_KMSG))
                return -EINVAL;
-       }
 
        if (!*enabled_buffers)
                *enabled_buffers = default_buffers;
@@ -60,10 +58,7 @@ int create_initial_fdis(struct fd_info ***fdis, int enabled_buffers, bool is_pip
 
                int r = fdi->ops->create(fdi, conf, bufname, &used_paths);
                if (r < 0) {
-                       if (r == -EINVAL)
-                               ERR("Error: buffer \"%s\" is not supported (disabled in configuration)\n", bufname);
-                       else if (r != -EALREADY)
-                               ERR("Error: unable to access buffer \"%s\"\n", bufname);
+                       // TODO: Inform about that again somewhere else
                        fdi_free(fdi);
                        continue;
                }
@@ -161,11 +156,8 @@ int do_print(struct fd_info **data_fds, int fd_count, write_callback callback, v
 
        int epoll_cnt = 0;
        __attribute__((cleanup(close_fd))) int epollfd = epoll_create1(0);
-       if (epollfd < 0) {
-               int ret = -errno;
-               DBG("epoll_create failed: %m");
-               return ret;
-       }
+       if (epollfd < 0)
+               return -errno;
 
        __attribute__ ((cleanup(sort_vector_free))) struct sort_vector logs;
        sort_vector_init(&logs);
@@ -174,21 +166,18 @@ int do_print(struct fd_info **data_fds, int fd_count, write_callback callback, v
        logs.size = sorting_needed ? opt->logs_size : 0;
        logs.sort_by = sort_by;
        clock_gettime(get_proper_clock(sort_by), &logs.start);
-       if (!sort_vector_finalize(&logs)) {
-               ERR("Error: unable to allocate memory\n");
+       if (!sort_vector_finalize(&logs))
                return -ENOMEM;
-       }
 
        for (int nfds = 0; nfds < fd_count; ++nfds) {
                int r = data_fds[nfds]->ops->prepare_print(data_fds[nfds], logs.dump, opt->filter_list, opt->filter_object);
+               if (r < 0)
+                       return r;
                if (r > 0) {
                        // everything went fine, but we're not printing this one
                        fdi_free(data_fds[nfds]);
                        data_fds[nfds] = NULL;
                        continue;
-               } else if (r < 0) {
-                       ERR("Error while preparing for printing: %s", strerror(-r));
-                       return r;
                }
                int fd = data_fds[nfds]->fd;
                r = fd_set_flags(fd, O_NONBLOCK);
@@ -203,10 +192,8 @@ int do_print(struct fd_info **data_fds, int fd_count, write_callback callback, v
        }
 
        __attribute__((cleanup(free_ptr))) struct epoll_event *evs = calloc(epoll_cnt, sizeof *evs);
-       if (!evs) {
-               ERR("Error: no memory for epoll array");
+       if (!evs)
                return -ENOMEM;
-       }
 
        while (epoll_cnt > 0) {
                int nfds;