From: Jonathan Rajotte Date: Wed, 3 Jul 2019 21:46:45 +0000 (-0400) Subject: Fix: log_level usage on mingw platform X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=95c324a414e7d862985caaf49bdb58f0cdfa2647 Fix: log_level usage on mingw platform The mingw build was simply broken. For example: mman.c: In function 'mmap_lock': mman.c:29:30: error: 'mapping' undeclared (first use in this function) 29 | #define BT_LOG_OUTPUT_LEVEL (mapping->log_level) | ^~~~~~~ ../../src/logging/log.h:165:31: note: in expansion of macro 'BT_LOG_OUTPUT_LEVEL' 165 | #define _BT_LOG_OUTPUT_LEVEL BT_LOG_OUTPUT_LEVEL | ^~~~~~~~~~~~~~~~~~~ ../../src/logging/log.h:671:38: note: in expansion of macro '_BT_LOG_OUTPUT_LEVEL' 671 | (BT_LOG_ENABLED((lvl)) && (lvl) >= _BT_LOG_OUTPUT_LEVEL) | ^~~~~~~~~~~~~~~~~~~~ ../../src/logging/log.h:835:9: note: in expansion of macro 'BT_LOG_ON' 835 | if (BT_LOG_ON(lvl)) \ | ^~~~~~~~~ ../../src/logging/log.h:974:4: note: in expansion of macro 'BT_LOG_WRITE' 974 | BT_LOG_WRITE(BT_LOG_FATAL, _BT_LOG_TAG, __VA_ARGS__) | ^~~~~~~~~~~~ ../../src/logging/log.h:995:24: note: in expansion of macro 'BT_LOGF' 995 | #define BT_LOGF_STR(s) BT_LOGF("%s", (s)) | ^~~~~~~ mman.c:122:3: note: in expansion of macro 'BT_LOGF_STR' 122 | BT_LOGF_STR("Failed to acquire mmap_mutex."); | ^~~~~~~~~~~ mman.c:29:30: note: each undeclared identifier is reported only once for each function it appears in 29 | #define BT_LOG_OUTPUT_LEVEL (mapping->log_level) | ^~~~~~~ ../../src/logging/log.h:165:31: note: in expansion of macro 'BT_LOG_OUTPUT_LEVEL' 165 | #define _BT_LOG_OUTPUT_LEVEL BT_LOG_OUTPUT_LEVEL | ^~~~~~~~~~~~~~~~~~~ ../../src/logging/log.h:671:38: note: in expansion of macro '_BT_LOG_OUTPUT_LEVEL' 671 | (BT_LOG_ENABLED((lvl)) && (lvl) >= _BT_LOG_OUTPUT_LEVEL) | ^~~~~~~~~~~~~~~~~~~~ ../../src/logging/log.h:835:9: note: in expansion of macro 'BT_LOG_ON' 835 | if (BT_LOG_ON(lvl)) \ | ^~~~~~~~~ ../../src/logging/log.h:974:4: note: in expansion of macro 'BT_LOG_WRITE' 974 | BT_LOG_WRITE(BT_LOG_FATAL, _BT_LOG_TAG, __VA_ARGS__) | ^~~~~~~~~~~~ ../../src/logging/log.h:995:24: note: in expansion of macro 'BT_LOGF' 995 | #define BT_LOGF_STR(s) BT_LOGF("%s", (s)) | ^~~~~~~ mman.c:122:3: note: in expansion of macro 'BT_LOGF_STR' 122 | BT_LOGF_STR("Failed to acquire mmap_mutex."); | ^~~~~~~~~~~ mman.c: In function 'mmap_unlock': mman.c:29:30: error: 'mapping' undeclared (first use in this function) 29 | #define BT_LOG_OUTPUT_LEVEL (mapping->log_level) | ^~~~~~~ ../../src/logging/log.h:165:31: note: in expansion of macro 'BT_LOG_OUTPUT_LEVEL' 165 | #define _BT_LOG_OUTPUT_LEVEL BT_LOG_OUTPUT_LEVEL | ^~~~~~~~~~~~~~~~~~~ ../../src/logging/log.h:671:38: note: in expansion of macro '_BT_LOG_OUTPUT_LEVEL' 671 | (BT_LOG_ENABLED((lvl)) && (lvl) >= _BT_LOG_OUTPUT_LEVEL) | ^~~~~~~~~~~~~~~~~~~~ ../../src/logging/log.h:835:9: note: in expansion of macro 'BT_LOG_ON' 835 | if (BT_LOG_ON(lvl)) \ | ^~~~~~~~~ ../../src/logging/log.h:974:4: note: in expansion of macro 'BT_LOG_WRITE' 974 | BT_LOG_WRITE(BT_LOG_FATAL, _BT_LOG_TAG, __VA_ARGS__) | ^~~~~~~~~~~~ ../../src/logging/log.h:995:24: note: in expansion of macro 'BT_LOGF' 995 | #define BT_LOGF_STR(s) BT_LOGF("%s", (s)) | ^~~~~~~ mman.c:131:3: note: in expansion of macro 'BT_LOGF_STR' 131 | BT_LOGF_STR("Failed to release mmap_mutex."); | ^~~~~~~~~~~ mman.c: At top level: mman.c:173:7: error: conflicting types for 'bt_mmap' 173 | void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd, | ^~~~~~~ In file included from mman.c:53: ../../src/compat/mman.h:48:7: note: previous declaration of 'bt_mmap' was here 48 | void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd, | ^~~~~~~ mman.c: In function 'bt_mmap': mman.c:202:12: error: too many arguments to function 'mapping_create' 202 | mapping = mapping_create(log_level); | ^~~~~~~~~~~~~~ mman.c:73:22: note: declared here 73 | struct mmap_mapping *mapping_create(void) | ^~~~~~~~~~~~~~ make[2]: *** [Makefile:501: mman.lo] Error 1 Change-Id: I71b36504541382cadf09953d9e113adc6c3641b6 Signed-off-by: Jonathan Rajotte Reviewed-on: https://review.lttng.org/c/babeltrace/+/1610 Tested-by: jenkins Reviewed-by: Philippe Proulx --- diff --git a/src/common/mmap-align.h b/src/common/mmap-align.h index 5d91c035..033d6c4a 100644 --- a/src/common/mmap-align.h +++ b/src/common/mmap-align.h @@ -93,7 +93,7 @@ struct mmap_align *mmap_align(size_t length, int prot, */ mma->page_aligned_length = ALIGN(length + offset - page_aligned_offset, page_size); mma->page_aligned_addr = bt_mmap(NULL, mma->page_aligned_length, - prot, flags, fd, page_aligned_offset); + prot, flags, fd, page_aligned_offset, log_level); if (mma->page_aligned_addr == MAP_FAILED) { free(mma); return MAP_FAILED; diff --git a/src/compat/mman.c b/src/compat/mman.c index de1d7b34..72c4cc28 100644 --- a/src/compat/mman.c +++ b/src/compat/mman.c @@ -70,7 +70,7 @@ GHashTable *mmap_mappings = NULL; static pthread_mutex_t mmap_mutex = PTHREAD_MUTEX_INITIALIZER; static -struct mmap_mapping *mapping_create(void) +struct mmap_mapping *mapping_create(int log_level) { struct mmap_mapping *mapping; @@ -78,6 +78,7 @@ struct mmap_mapping *mapping_create(void) if (mapping != NULL) { mapping->file_handle = NULL; mapping->map_handle = NULL; + mapping->log_level = log_level; } return mapping; @@ -119,7 +120,7 @@ static void mmap_lock(int log_level) { if (pthread_mutex_lock(&mmap_mutex)) { - BT_LOGF_STR("Failed to acquire mmap_mutex."); + BT_LOG_WRITE_CUR_LVL(BT_LOG_FATAL, log_level, BT_LOG_TAG, "Failed to acquire mmap_mutex."); abort(); } } @@ -128,7 +129,7 @@ static void mmap_unlock(int log_level) { if (pthread_mutex_unlock(&mmap_mutex)) { - BT_LOGF_STR("Failed to release mmap_mutex."); + BT_LOG_WRITE_CUR_LVL(BT_LOG_FATAL, log_level, BT_LOG_TAG, "Failed to release mmap_mutex."); abort(); } } diff --git a/src/compat/mman.h b/src/compat/mman.h index 9f494526..bdab9d19 100644 --- a/src/compat/mman.h +++ b/src/compat/mman.h @@ -46,7 +46,7 @@ * mappings to exceed the file's size (even within a page). */ void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd, - off_t offset); + off_t offset, int log_level); int bt_munmap(void *addr, size_t length); @@ -56,7 +56,7 @@ int bt_munmap(void *addr, size_t length); static inline void *bt_mmap(void *addr, size_t length, int prot, int flags, int fd, - off_t offset) + off_t offset, int log_level) { return (void *) mmap(addr, length, prot, flags, fd, offset); } diff --git a/src/compat/socket.h b/src/compat/socket.h index b1fe1597..be63d31e 100644 --- a/src/compat/socket.h +++ b/src/compat/socket.h @@ -33,7 +33,7 @@ #define BT_SOCKET SOCKET static inline -int bt_socket_init(void) +int bt_socket_init(int log_level) { WORD verreq; WSADATA wsa; @@ -44,15 +44,17 @@ int bt_socket_init(void) ret = WSAStartup(verreq, &wsa); if (ret != 0) { -#ifdef BT_LOGE - BT_LOGE("Winsock init failed with error: %d", ret); +#ifdef BT_LOG_WRITE_CUR_LVL + BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR, log_level, BT_LOG_TAG, + "Winsock init failed with error: %d", ret); #endif goto end; } if (LOBYTE(wsa.wVersion) != 2 || HIBYTE(wsa.wVersion) != 2) { -#ifdef BT_LOGE_STR - BT_LOGE_STR("Could not init winsock 2.2 support"); +#ifdef BT_LOG_WRITE_CUR_LVL + BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR, log_level, BT_LOG_TAG, + "Could not init winsock 2.2 support"); #endif WSACleanup(); ret = -1; @@ -282,7 +284,7 @@ const char *bt_socket_errormsg(void) #define BT_SOCKET int static inline -int bt_socket_init(void) +int bt_socket_init(int log_level) { return 0; } diff --git a/src/plugins/ctf/fs-src/data-stream-file.c b/src/plugins/ctf/fs-src/data-stream-file.c index 880eb852..b4022c32 100644 --- a/src/plugins/ctf/fs-src/data-stream-file.c +++ b/src/plugins/ctf/fs-src/data-stream-file.c @@ -108,7 +108,7 @@ enum bt_msg_iter_medium_status ds_file_mmap_next( BT_ASSERT(ds_file->mmap_len); ds_file->mmap_addr = bt_mmap((void *) 0, ds_file->mmap_len, PROT_READ, MAP_PRIVATE, fileno(ds_file->file->fp), - ds_file->mmap_offset); + ds_file->mmap_offset, ds_file->log_level); if (ds_file->mmap_addr == MAP_FAILED) { BT_COMP_LOGE("Cannot memory-map address (size %zu) of file \"%s\" (%p) at offset %jd: %s", ds_file->mmap_len, ds_file->file->path->str, diff --git a/src/plugins/ctf/lttng-live/viewer-connection.c b/src/plugins/ctf/lttng-live/viewer-connection.c index 0badf75b..01b4b823 100644 --- a/src/plugins/ctf/lttng-live/viewer-connection.c +++ b/src/plugins/ctf/lttng-live/viewer-connection.c @@ -1479,7 +1479,7 @@ struct live_viewer_connection *live_viewer_connection_create( viewer_connection = g_new0(struct live_viewer_connection, 1); - if (bt_socket_init() != 0) { + if (bt_socket_init(lttng_live_msg_iter->log_level) != 0) { goto error; }