Line data Source code
1 : #include "platform_util.h" 2 : 3 : #ifdef _MSC_VER 4 : #include <processthreadsapi.h> 5 : #include <winsock.h> 6 : #else 7 : #include <pthread.h> 8 : #include <unistd.h> 9 : #endif 10 : 11 : namespace datadog { 12 : namespace tracing { 13 : 14 612 : Optional<std::string> get_hostname() { 15 : char buffer[256]; 16 612 : if (::gethostname(buffer, sizeof buffer)) { 17 0 : return nullopt; 18 : } 19 612 : return buffer; 20 : } 21 : 22 2 : int get_process_id() { 23 : #ifdef _MSC_VER 24 : return GetCurrentProcessId(); 25 : #else 26 2 : return ::getpid(); 27 : #endif 28 : } 29 : 30 2 : int at_fork_in_child(void (*on_fork)()) { 31 : // Windows does not have `fork`, and so this is not relevant there. 32 : #ifdef _MSC_VER 33 : return 0; 34 : #else 35 : // https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_atfork.html 36 2 : return pthread_atfork(/*before fork*/ nullptr, /*in parent*/ nullptr, 37 2 : /*in child*/ on_fork); 38 : #endif 39 : } 40 : 41 : } // namespace tracing 42 : } // namespace datadog