| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 /* | 7 /* |
| 8 * SRPC utility functions. | 8 * SRPC utility functions. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <stdarg.h> | 11 #include <stdarg.h> |
| 12 #include <stdlib.h> | 12 #include <stdlib.h> |
| 13 #include <string.h> | 13 #include <string.h> |
| 14 | 14 |
| 15 #include "native_client/src/include/portability.h" | 15 #include "native_client/src/include/portability.h" |
| 16 #include "native_client/src/include/portability_io.h" | 16 #include "native_client/src/include/portability_io.h" |
| 17 #include "native_client/src/include/portability_process.h" | 17 #include "native_client/src/include/portability_process.h" |
| 18 | 18 |
| 19 #include "native_client/src/shared/platform/nacl_sync_checked.h" | |
| 20 #include "native_client/src/shared/srpc/nacl_srpc.h" | 19 #include "native_client/src/shared/srpc/nacl_srpc.h" |
| 21 #include "native_client/src/shared/srpc/nacl_srpc_internal.h" | 20 #include "native_client/src/shared/srpc/nacl_srpc_internal.h" |
| 22 | 21 |
| 23 static struct NaClMutex log_mu; | 22 /* TODO(sehr): Re-enable logging mutex when this does not require C++. */ |
| 23 /* static struct NaClMutex log_mu; */ |
| 24 | 24 |
| 25 #define VERBOSITY_NOT_SET ((int) (((unsigned) -1) >> 1)) | 25 #define VERBOSITY_NOT_SET ((int) (((unsigned) -1) >> 1)) |
| 26 | 26 |
| 27 static int verbosity = VERBOSITY_NOT_SET; | 27 static int verbosity = VERBOSITY_NOT_SET; |
| 28 | 28 |
| 29 int NaClSrpcLogInit() { | 29 int NaClSrpcLogInit() { |
| 30 NaClXMutexCtor(&log_mu); | 30 /* NaClXMutexCtor(&log_mu); */ |
| 31 return 1; | 31 return 1; |
| 32 } | 32 } |
| 33 | 33 |
| 34 void NaClSrpcLogFini() { | 34 void NaClSrpcLogFini() { |
| 35 NaClMutexDtor(&log_mu); | 35 /* NaClMutexDtor(&log_mu); */ |
| 36 } | 36 } |
| 37 | 37 |
| 38 static int getVerbosity() { | 38 static int getVerbosity() { |
| 39 if (VERBOSITY_NOT_SET == verbosity) { | 39 if (VERBOSITY_NOT_SET == verbosity) { |
| 40 const char* env_verbosity = getenv("NACL_SRPC_DEBUG"); | 40 const char* env_verbosity = getenv("NACL_SRPC_DEBUG"); |
| 41 verbosity = 0; | 41 verbosity = 0; |
| 42 if (NULL != env_verbosity) { | 42 if (NULL != env_verbosity) { |
| 43 int v = strtol(env_verbosity, (char**) 0, 0); | 43 int v = strtol(env_verbosity, (char**) 0, 0); |
| 44 if (v >= 0) { | 44 if (v >= 0) { |
| 45 verbosity = v; | 45 verbosity = v; |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 return verbosity; | 49 return verbosity; |
| 50 } | 50 } |
| 51 | 51 |
| 52 void NaClSrpcLog(int detail_level, const char* fmt, ...) { | 52 void NaClSrpcLog(int detail_level, const char* fmt, ...) { |
| 53 if (detail_level <= getVerbosity()) { | 53 if (detail_level <= getVerbosity()) { |
| 54 int pid = GETPID(); | 54 int pid = GETPID(); |
| 55 va_list ap; | 55 va_list ap; |
| 56 #ifdef __native_client__ | 56 #ifdef __native_client__ |
| 57 const char* host_or_nacl = "NACL"; | 57 const char* host_or_nacl = "NACL"; |
| 58 #else | 58 #else |
| 59 const char* host_or_nacl = "HOST"; | 59 const char* host_or_nacl = "HOST"; |
| 60 #endif | 60 #endif |
| 61 va_start(ap, fmt); | 61 va_start(ap, fmt); |
| 62 NaClXMutexLock(&log_mu); | 62 /* NaClXMutexLock(&log_mu); */ |
| 63 fprintf(stderr, "[SRPC: %08x: %s] ", pid, host_or_nacl); | 63 fprintf(stderr, "[SRPC: %08x: %s] ", pid, host_or_nacl); |
| 64 vfprintf(stderr, fmt, ap); | 64 vfprintf(stderr, fmt, ap); |
| 65 NaClXMutexUnlock(&log_mu); | 65 /* NaClXMutexUnlock(&log_mu); */ |
| 66 va_end(ap); | 66 va_end(ap); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 static void formatChar(char cval, char** buf, size_t* bytes_remaining) { | 70 static void formatChar(char cval, char** buf, size_t* bytes_remaining) { |
| 71 if (cval < ' ' || cval >= 0x7f) { | 71 if (cval < ' ' || cval >= 0x7f) { |
| 72 static const size_t kBytesRequiredForHex = 4; | 72 static const size_t kBytesRequiredForHex = 4; |
| 73 if (*bytes_remaining >= kBytesRequiredForHex) { | 73 if (*bytes_remaining >= kBytesRequiredForHex) { |
| 74 SNPRINTF(*buf, kBytesRequiredForHex, "\\x%02x", cval); | 74 SNPRINTF(*buf, kBytesRequiredForHex, "\\x%02x", cval); |
| 75 } | 75 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 return "Output argument type mismatch"; | 234 return "Output argument type mismatch"; |
| 235 case NACL_SRPC_RESULT_INTERNAL: | 235 case NACL_SRPC_RESULT_INTERNAL: |
| 236 return "Internal error in rpc method"; | 236 return "Internal error in rpc method"; |
| 237 case NACL_SRPC_RESULT_APP_ERROR: | 237 case NACL_SRPC_RESULT_APP_ERROR: |
| 238 return "Rpc application returned an error"; | 238 return "Rpc application returned an error"; |
| 239 default: | 239 default: |
| 240 break; | 240 break; |
| 241 } | 241 } |
| 242 return "Unrecognized NaClSrpcError value"; | 242 return "Unrecognized NaClSrpcError value"; |
| 243 } | 243 } |
| OLD | NEW |