From a04464adaf5b95ae953f8577632d3cf8aa2c80a3 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Wed, 30 Apr 2014 08:50:53 -0700 Subject: liblog: set -Werror - Deal with some -Wunused issues - Cleanup UNUSED to __unused transition Change-Id: Icd33808d4c974625f4fd0a126a90a2b4c90c8314 --- liblog/Android.mk | 8 ++++---- liblog/event_tag_map.c | 28 ++++++---------------------- liblog/fake_log_device.c | 14 +++++++++----- liblog/log_read.c | 19 +++++++++---------- liblog/log_read_kern.c | 21 ++++++++++++--------- liblog/logd_write.c | 13 +++++++++---- liblog/logd_write_kern.c | 8 +++++--- liblog/logprint.c | 38 +++++--------------------------------- liblog/tests/liblog_benchmark.cpp | 4 ++-- liblog/tests/liblog_test.cpp | 2 +- 10 files changed, 62 insertions(+), 93 deletions(-) (limited to 'liblog') diff --git a/liblog/Android.mk b/liblog/Android.mk index 41440ad97..69ca4164f 100644 --- a/liblog/Android.mk +++ b/liblog/Android.mk @@ -57,7 +57,7 @@ endif # ======================================================== LOCAL_MODULE := liblog LOCAL_SRC_FILES := $(liblog_host_sources) -LOCAL_CFLAGS := -DFAKE_LOG_DEVICE=1 +LOCAL_CFLAGS := -DFAKE_LOG_DEVICE=1 -Werror include $(BUILD_HOST_STATIC_LIBRARY) include $(CLEAR_VARS) @@ -74,7 +74,7 @@ include $(BUILD_HOST_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := lib64log LOCAL_SRC_FILES := $(liblog_host_sources) -LOCAL_CFLAGS := -DFAKE_LOG_DEVICE=1 -m64 +LOCAL_CFLAGS := -DFAKE_LOG_DEVICE=1 -m64 -Werror include $(BUILD_HOST_STATIC_LIBRARY) # Shared and static library for target @@ -82,13 +82,13 @@ include $(BUILD_HOST_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := liblog LOCAL_SRC_FILES := $(liblog_target_sources) -LOCAL_CFLAGS := $(liblog_cflags) +LOCAL_CFLAGS := -Werror include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := liblog LOCAL_WHOLE_STATIC_LIBRARIES := liblog -LOCAL_CFLAGS := $(liblog_cflags) +LOCAL_CFLAGS := -Werror include $(BUILD_SHARED_LIBRARY) include $(call first-makefiles-under,$(LOCAL_PATH)) diff --git a/liblog/event_tag_map.c b/liblog/event_tag_map.c index f3d1e2fe2..bea99aae7 100644 --- a/liblog/event_tag_map.c +++ b/liblog/event_tag_map.c @@ -13,15 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include +#include +#include +#include #include #include -#include #include -#include -#include + +#include +#include #define OUT_TAG "EventTagMap" @@ -52,7 +53,6 @@ static int countMapLines(const EventTagMap* map); static int parseMapLines(EventTagMap* map); static int scanTagLine(char** pData, EventTag* tag, int lineNum); static int sortTags(EventTagMap* map); -static void dumpTags(const EventTagMap* map); /* @@ -185,8 +185,6 @@ static inline int isCharDigit(char c) */ static int processFile(EventTagMap* map) { - EventTag* tagArray = NULL; - /* get a tag count */ map->numTags = countMapLines(map); if (map->numTags < 0) @@ -422,17 +420,3 @@ static int sortTags(EventTagMap* map) return 0; } - -/* - * Dump the tag array for debugging. - */ -static void dumpTags(const EventTagMap* map) -{ - int i; - - for (i = 0; i < map->numTags; i++) { - const EventTag* tag = &map->tagArray[i]; - printf(" %3d: %6d '%s'\n", i, tag->tagIndex, tag->tagStr); - } -} - diff --git a/liblog/fake_log_device.c b/liblog/fake_log_device.c index da83a8525..136792ddd 100644 --- a/liblog/fake_log_device.c +++ b/liblog/fake_log_device.c @@ -21,18 +21,22 @@ */ #include "fake_log_device.h" -#include - -#include -#include #include #include #include +#include +#include + +#include #ifdef HAVE_PTHREADS #include #endif +#ifndef __unused +#define __unused __attribute__((__unused__)) +#endif + #define kMaxTagLen 16 /* from the long-dead utils/Log.cpp */ #define kTagSetSize 16 /* arbitrary */ @@ -613,7 +617,7 @@ static int logClose(int fd) /* * Open a log output device and return a fake fd. */ -static int logOpen(const char* pathName, int flags) +static int logOpen(const char* pathName, int flags __unused) { LogState *logState; int fd = -1; diff --git a/liblog/log_read.c b/liblog/log_read.c index 11fe8486b..ca5a1a7fa 100644 --- a/liblog/log_read.c +++ b/liblog/log_read.c @@ -23,6 +23,7 @@ #define NOMINMAX /* for windows to suppress definition of min in stdlib.h */ #include #include +#include #include #include @@ -34,7 +35,9 @@ #define min(x,y) ((y) ^ (((x) ^ (y)) & -((x) < (y)))) #define WEAK __attribute__((weak)) -#define UNUSED __attribute__((unused)) +#ifndef __unused +#define __unused __attribute__((unused)) +#endif /* Private copy of ../libcutils/socket_local_client.c prevent library loops */ @@ -142,11 +145,10 @@ error: * Used by AndroidSocketImpl */ int WEAK socket_local_client_connect(int fd, const char *name, int namespaceId, - int type UNUSED) + int type __unused) { struct sockaddr_un addr; socklen_t alen; - size_t namelen; int err; err = socket_make_sockaddr_un(name, namespaceId, &addr, &alen); @@ -409,7 +411,7 @@ long android_logger_get_log_readable_size(struct logger *logger) /* * returns the logger version */ -int android_logger_get_log_version(struct logger *logger UNUSED) +int android_logger_get_log_version(struct logger *logger __unused) { return 3; } @@ -420,7 +422,6 @@ int android_logger_get_log_version(struct logger *logger UNUSED) ssize_t android_logger_get_statistics(struct logger_list *logger_list, char *buf, size_t len) { - struct listnode *node; struct logger *logger; char *cp = buf; size_t remaining = len; @@ -440,13 +441,13 @@ ssize_t android_logger_get_statistics(struct logger_list *logger_list, return send_log_msg(NULL, NULL, buf, len); } -ssize_t android_logger_get_prune_list(struct logger_list *logger_list UNUSED, +ssize_t android_logger_get_prune_list(struct logger_list *logger_list __unused, char *buf, size_t len) { return send_log_msg(NULL, "getPruneList", buf, len); } -int android_logger_set_prune_list(struct logger_list *logger_list UNUSED, +int android_logger_set_prune_list(struct logger_list *logger_list __unused, char *buf, size_t len) { const char cmd[] = "setPruneList "; @@ -512,9 +513,7 @@ struct logger_list *android_logger_list_alloc_time(int mode, struct logger *android_logger_open(struct logger_list *logger_list, log_id_t id) { - struct listnode *node; struct logger *logger; - char *n; if (!logger_list || (id >= LOG_ID_MAX)) { goto err; @@ -561,7 +560,7 @@ struct logger_list *android_logger_list_open(log_id_t id, return logger_list; } -static void caught_signal(int signum UNUSED) +static void caught_signal(int signum __unused) { } diff --git a/liblog/log_read_kern.c b/liblog/log_read_kern.c index 021fe476e..41b8a51a4 100644 --- a/liblog/log_read_kern.c +++ b/liblog/log_read_kern.c @@ -21,12 +21,13 @@ #include #include #include +#include +#include + #include #include #include -#include - #define __LOGGERIO 0xAE #define LOGGER_GET_LOG_BUF_SIZE _IO(__LOGGERIO, 1) /* size of log */ @@ -51,7 +52,9 @@ typedef char bool; logger != node_to_item(&(logger_list)->node, struct logger, node); \ logger = node_to_item((logger)->node.next, struct logger, node)) -#define UNUSED __attribute__((unused)) +#ifndef __unused +#define __unused __attribute__((unused)) +#endif /* In the future, we would like to make this list extensible */ static const char *LOG_NAME[LOG_ID_MAX] = { @@ -233,8 +236,8 @@ long android_logger_get_log_size(struct logger *logger) return logger_ioctl(logger, LOGGER_GET_LOG_BUF_SIZE, O_RDWR); } -int android_logger_set_log_size(struct logger *logger UNUSED, - unsigned long size UNUSED) +int android_logger_set_log_size(struct logger *logger __unused, + unsigned long size __unused) { return -ENOTSUP; } @@ -262,21 +265,21 @@ int android_logger_get_log_version(struct logger *logger) */ static const char unsupported[] = "18\nNot Supported\n\f"; -ssize_t android_logger_get_statistics(struct logger_list *logger_list UNUSED, +ssize_t android_logger_get_statistics(struct logger_list *logger_list __unused, char *buf, size_t len) { strncpy(buf, unsupported, len); return -ENOTSUP; } -ssize_t android_logger_get_prune_list(struct logger_list *logger_list UNUSED, +ssize_t android_logger_get_prune_list(struct logger_list *logger_list __unused, char *buf, size_t len) { strncpy(buf, unsupported, len); return -ENOTSUP; } -int android_logger_set_prune_list(struct logger_list *logger_list UNUSED, +int android_logger_set_prune_list(struct logger_list *logger_list __unused, char *buf, size_t len) { static const char unsupported_error[] = "Unsupported"; @@ -302,7 +305,7 @@ struct logger_list *android_logger_list_alloc(int mode, } struct logger_list *android_logger_list_alloc_time(int mode, - log_time start UNUSED, + log_time start __unused, pid_t pid) { return android_logger_list_alloc(mode, 0, pid); diff --git a/liblog/logd_write.c b/liblog/logd_write.c index 4c47382e2..121d84dff 100644 --- a/liblog/logd_write.c +++ b/liblog/logd_write.c @@ -49,12 +49,15 @@ static int (*write_to_log)(log_id_t, struct iovec *vec, size_t nr) = __write_to_ static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER; #endif -#define UNUSED __attribute__((__unused__)) +#ifndef __unused +#define __unused __attribute__((__unused__)) +#endif -static int logd_fd = -1; #if FAKE_LOG_DEVICE #define WEAK __attribute__((weak)) static int log_fds[(int)LOG_ID_MAX] = { -1, -1, -1, -1, -1 }; +#else +static int logd_fd = -1; #endif /* @@ -77,12 +80,14 @@ int __android_log_dev_available(void) return (g_log_status == kLogAvailable); } +#if !FAKE_LOG_DEVICE /* give up, resources too limited */ -static int __write_to_log_null(log_id_t log_fd UNUSED, struct iovec *vec UNUSED, - size_t nr UNUSED) +static int __write_to_log_null(log_id_t log_fd __unused, struct iovec *vec __unused, + size_t nr __unused) { return -1; } +#endif /* log_init_lock assumed */ static int __write_to_log_initialize() diff --git a/liblog/logd_write_kern.c b/liblog/logd_write_kern.c index 982beaaed..1d107481d 100644 --- a/liblog/logd_write_kern.c +++ b/liblog/logd_write_kern.c @@ -57,7 +57,9 @@ static int (*write_to_log)(log_id_t, struct iovec *vec, size_t nr) = __write_to_ static pthread_mutex_t log_init_lock = PTHREAD_MUTEX_INITIALIZER; #endif -#define UNUSED __attribute__((__unused__)) +#ifndef __unused +#define __unused __attribute__((__unused__)) +#endif static int log_fds[(int)LOG_ID_MAX] = { -1, -1, -1, -1 }; @@ -81,8 +83,8 @@ int __android_log_dev_available(void) return (g_log_status == kLogAvailable); } -static int __write_to_log_null(log_id_t log_fd UNUSED, struct iovec *vec UNUSED, - size_t nr UNUSED) +static int __write_to_log_null(log_id_t log_fd __unused, struct iovec *vec __unused, + size_t nr __unused) { return -1; } diff --git a/liblog/logprint.c b/liblog/logprint.c index 3bc9f5a67..08e830acc 100644 --- a/liblog/logprint.c +++ b/liblog/logprint.c @@ -17,14 +17,14 @@ #define _GNU_SOURCE /* for asprintf */ +#include +#include #include -#include #include -#include #include +#include +#include #include -#include -#include #include #include @@ -52,15 +52,7 @@ static FilterInfo * filterinfo_new(const char * tag, android_LogPriority pri) return p_ret; } -static void filterinfo_free(FilterInfo *p_info) -{ - if (p_info == NULL) { - return; - } - - free(p_info->mTag); - p_info->mTag = NULL; -} +/* balance to above, filterinfo_free left unimplemented */ /* * Note: also accepts 0-9 priorities @@ -139,23 +131,6 @@ static android_LogPriority filterPriForTag( return p_format->global_pri; } -/** for debugging */ -static void dumpFilters(AndroidLogFormat *p_format) -{ - FilterInfo *p_fi; - - for (p_fi = p_format->filters ; p_fi != NULL ; p_fi = p_fi->p_next) { - char cPri = filterPriToChar(p_fi->mPri); - if (p_fi->mPri == ANDROID_LOG_DEFAULT) { - cPri = filterPriToChar(p_format->global_pri); - } - fprintf(stderr,"%s:%c\n", p_fi->mTag, cPri); - } - - fprintf(stderr,"*:%c\n", filterPriToChar(p_format->global_pri)); - -} - /** * returns 1 if this log line should be printed based on its priority * and tag, and 0 if it should not @@ -234,7 +209,6 @@ AndroidLogPrintFormat android_log_formatFromString(const char * formatString) int android_log_addFilterRule(AndroidLogFormat *p_format, const char *filterExpression) { - size_t i=0; size_t tagNameLength; android_LogPriority pri = ANDROID_LOG_DEFAULT; @@ -718,7 +692,6 @@ char *android_log_formatLogLine ( #endif struct tm* ptm; char timeBuf[32]; - char headerBuf[128]; char prefixBuf[128], suffixBuf[128]; char priChar; int prefixSuffixIsHeaderFooter = 0; @@ -817,7 +790,6 @@ char *android_log_formatLogLine ( /* the following code is tragically unreadable */ size_t numLines; - size_t i; char *p; size_t bufferSize; const char *pm; diff --git a/liblog/tests/liblog_benchmark.cpp b/liblog/tests/liblog_benchmark.cpp index 39fe2ad84..549d79eb4 100644 --- a/liblog/tests/liblog_benchmark.cpp +++ b/liblog/tests/liblog_benchmark.cpp @@ -99,7 +99,7 @@ static void BM_log_overhead(int iters) { } BENCHMARK(BM_log_overhead); -static void caught_latency(int signum) +static void caught_latency(int /*signum*/) { unsigned long long v = 0xDEADBEEFA55A5AA5ULL; @@ -193,7 +193,7 @@ static void BM_log_latency(int iters) { } BENCHMARK(BM_log_latency); -static void caught_delay(int signum) +static void caught_delay(int /*signum*/) { unsigned long long v = 0xDEADBEEFA55A5AA6ULL; diff --git a/liblog/tests/liblog_test.cpp b/liblog/tests/liblog_test.cpp index c6f981f58..ec35e4536 100644 --- a/liblog/tests/liblog_test.cpp +++ b/liblog/tests/liblog_test.cpp @@ -164,7 +164,7 @@ TEST(liblog, __android_log_btwrite__android_logger_list_read) { static unsigned signaled; log_time signal_time; -static void caught_blocking(int signum) +static void caught_blocking(int /*signum*/) { unsigned long long v = 0xDEADBEEFA55A0000ULL; -- cgit v1.2.3-54-g00ecf