liblog: set -Werror

- Deal with some -Wunused issues
- Cleanup UNUSED to __unused transition

Change-Id: Icd33808d4c974625f4fd0a126a90a2b4c90c8314
diff --git a/liblog/Android.mk b/liblog/Android.mk
index 41440ad..69ca416 100644
--- a/liblog/Android.mk
+++ b/liblog/Android.mk
@@ -57,7 +57,7 @@
 # ========================================================
 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 $(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 $(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 f3d1e2f..bea99aa 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 <log/event_tag_map.h>
-#include <log/log.h>
 
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
 #include <stdlib.h>
 #include <string.h>
-#include <fcntl.h>
 #include <sys/mman.h>
-#include <errno.h>
-#include <assert.h>
+
+#include <log/event_tag_map.h>
+#include <log/log.h>
 
 #define OUT_TAG "EventTagMap"
 
@@ -52,7 +53,6 @@
 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 int processFile(EventTagMap* map)
 {
-    EventTag* tagArray = NULL;
-
     /* get a tag count */
     map->numTags = countMapLines(map);
     if (map->numTags < 0)
@@ -422,17 +420,3 @@
 
     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 da83a85..136792d 100644
--- a/liblog/fake_log_device.c
+++ b/liblog/fake_log_device.c
@@ -21,18 +21,22 @@
  */
 #include "fake_log_device.h"
 
-#include <log/logd.h>
-
-#include <stdlib.h>
-#include <string.h>
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <log/logd.h>
 
 #ifdef HAVE_PTHREADS
 #include <pthread.h>
 #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 @@
 /*
  * 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 11fe848..ca5a1a7 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 <stdlib.h>
 #include <string.h>
+#include <sys/cdefs.h>
 #include <unistd.h>
 
 #include <cutils/list.h>
@@ -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 @@
  * 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 @@
 /*
  * 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 @@
 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 @@
     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 *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 @@
     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 021fe47..41b8a51 100644
--- a/liblog/log_read_kern.c
+++ b/liblog/log_read_kern.c
@@ -21,12 +21,13 @@
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/cdefs.h>
+#include <sys/ioctl.h>
+
 #include <cutils/list.h>
 #include <log/log.h>
 #include <log/logger.h>
 
-#include <sys/ioctl.h>
-
 #define __LOGGERIO     0xAE
 
 #define LOGGER_GET_LOG_BUF_SIZE    _IO(__LOGGERIO, 1) /* size of log */
@@ -51,7 +52,9 @@
          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 @@
     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 @@
  */
 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_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 4c47382..121d84d 100644
--- a/liblog/logd_write.c
+++ b/liblog/logd_write.c
@@ -49,12 +49,15 @@
 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 @@
     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 982beaa..1d10748 100644
--- a/liblog/logd_write_kern.c
+++ b/liblog/logd_write_kern.c
@@ -57,7 +57,9 @@
 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 @@
     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 3bc9f5a..08e830a 100644
--- a/liblog/logprint.c
+++ b/liblog/logprint.c
@@ -17,14 +17,14 @@
 
 #define _GNU_SOURCE /* for asprintf */
 
-#include <ctype.h>
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-#include <assert.h>
 #include <arpa/inet.h>
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 #include <log/logd.h>
 #include <log/logprint.h>
@@ -52,15 +52,7 @@
     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 @@
     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 @@
 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 @@
 #endif
     struct tm* ptm;
     char timeBuf[32];
-    char headerBuf[128];
     char prefixBuf[128], suffixBuf[128];
     char priChar;
     int prefixSuffixIsHeaderFooter = 0;
@@ -817,7 +790,6 @@
     /* 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 39fe2ad..549d79e 100644
--- a/liblog/tests/liblog_benchmark.cpp
+++ b/liblog/tests/liblog_benchmark.cpp
@@ -99,7 +99,7 @@
 }
 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 @@
 }
 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 c6f981f..ec35e45 100644
--- a/liblog/tests/liblog_test.cpp
+++ b/liblog/tests/liblog_test.cpp
@@ -164,7 +164,7 @@
 static unsigned signaled;
 log_time signal_time;
 
-static void caught_blocking(int signum)
+static void caught_blocking(int /*signum*/)
 {
     unsigned long long v = 0xDEADBEEFA55A0000ULL;