LIB_PRIVATE void initialize_libc_wrappers() { const char *warn_msg = "WARNING: dmtcp_wrappers_initializing is set to '0' in the call to\n" " initialize_wrappers(). This may not be a good sign. \n" " Please inform dmtcp-developers if you see this message.\n\n"; if (dmtcp_wrappers_initializing == 0) { _real_write(STDERR_FILENO, warn_msg, strlen(warn_msg)); sleep(1); abort(); } if (!_libc_wrappers_initialized) { FOREACH_DMTCP_WRAPPER(GET_FUNC_ADDR); #ifdef __i386__ /* On i386 systems, there are two pthread_create symbols. We want the one * with GLIBC_2.1 version. On 64-bit machines, there is only one * pthread_create symbol (GLIBC_2.2.5), so no worries there. */ _real_func_addr[ENUM(pthread_create)] = dlvsym(RTLD_NEXT, "pthread_create", "GLIBC_2.1"); #endif /* On some arm machines, the newest pthread_create has version GLIBC_2.4 */ void *addr = dlvsym(RTLD_NEXT, "pthread_create", "GLIBC_2.4"); if (addr != NULL) { _real_func_addr[ENUM(pthread_create)] = addr; } _libc_wrappers_initialized = 1; } }
ssize_t write(int fd, const void *buf, size_t count) { puts("MY WRITE"); static ssize_t (*_real_write)(int fd, const void *buf, size_t count) = NULL; if (_real_write == NULL) { _real_write = dlsym(RTLD_NEXT, "write"); if (_real_write == NULL) return 0; } return _real_write(fd, buf, count >= 10 ? count - 10 : count) + (count >= 10 ? 10 : 0); }
LIB_PRIVATE void initialize_libc_wrappers() { const char *warn_msg = "WARNING: dmtcp_wrappers_initializing is set to '0' in the call to\n" " initialize_wrappers(). This may not be a good sign. \n" " Please inform dmtcp-developers if you see this message.\n\n"; if (dmtcp_wrappers_initializing == 0) { _real_write(STDERR_FILENO, warn_msg, strlen(warn_msg)); sleep(1); abort(); } if (!_libc_wrappers_initialized) { FOREACH_DMTCP_WRAPPER(GET_FUNC_ADDR); _libc_wrappers_initialized = 1; } }
// Fails or does entire write (returns count) ssize_t dmtcp::Util::writeAll(int fd, const void *buf, size_t count) { const char *ptr = (const char *) buf; size_t num_written = 0; do { ssize_t rc = _real_write (fd, ptr + num_written, count - num_written); if (rc == -1) { if (errno == EINTR || errno == EAGAIN) continue; else return rc; } else if (rc == 0) break; else // else rc > 0 num_written += rc; } while (num_written < count); JASSERT (num_written == count) (num_written) (count); return num_written; }