Skip to content

Commit

Permalink
Reland prevent console logging on iOS 11.3+ within WebSocket
Browse files Browse the repository at this point in the history
Reviewed By: shergin

Differential Revision: D7953765

fbshipit-source-id: 6b259d10c719e9ad6b2cfdbf1ebb883dacf08353
  • Loading branch information
Mehdi Mulani authored and facebook-github-bot committed May 11, 2018
1 parent 0e5c263 commit 8125be9
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions Libraries/WebSocket/RCTReconnectingWebSocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,37 @@
#import <React/RCTDefines.h>
#import <fishhook/fishhook.h>

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
#if __has_include(<os/log.h>) && defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 100300 /* __IPHONE_10_3 */
#import <os/log.h>
#endif /* __IPHONE_11_0 */
#endif /* __IPHONE_10_3 */

#import "RCTSRWebSocket.h"

#if RCT_DEV // Only supported in dev mode

#if __has_include(<os/log.h>) && defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 100300 /* __IPHONE_10_3 */

// From https://github.com/apple/swift/blob/ad40c770bfe372f879b530443a3d94761fe258a6/stdlib/public/SDK/os/os_log.m
typedef struct os_log_pack_s {
uint64_t olp_continuous_time;
struct timespec olp_wall_time;
const void *olp_mh;
const void *olp_pc;
const char *olp_format;
uint8_t olp_data[0];
} os_log_pack_s, *os_log_pack_t;

static void (*orig__nwlog_pack)(os_log_pack_t pack, os_log_type_t logType);

static void my__nwlog_pack(os_log_pack_t pack, os_log_type_t logType)
{
if (logType == OS_LOG_TYPE_ERROR && strstr(pack->olp_format, "Connection has no connected handler") == NULL) {
orig__nwlog_pack(pack, logType);
}
}

#endif /* __IPHONE_10_3 */

static void (*orig_nwlog_legacy_v)(int, char*, va_list);

static void my_nwlog_legacy_v(int level, char *format, va_list args) {
Expand Down Expand Up @@ -63,6 +86,11 @@ + (void)load
rebind_symbols((struct rebinding[1]){
{"nwlog_legacy_v", my_nwlog_legacy_v, (void *)&orig_nwlog_legacy_v}
}, 1);
#if __has_include(<os/log.h>) && defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 100300 /* __IPHONE_10_3 */
rebind_symbols((struct rebinding[1]){
{"__nwlog_pack", my__nwlog_pack, (void *)&orig__nwlog_pack}
}, 1);
#endif /* __IPHONE_10_3 */
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
rebind_symbols((struct rebinding[1]){
{"_os_log_error_impl", my_os_log_error_impl, (void *)&orig_os_log_error_impl}
Expand Down

0 comments on commit 8125be9

Please sign in to comment.