void citp_log_fn_ul(const char* msg) { struct iovec v[2]; int tmp_fd = 0; if( citp.log_fd < 0 ) { if( citp.init_level >= CITP_INIT_SYSCALLS ) { citp.log_fd = oo_fcntl_dupfd_cloexec(STDERR_FILENO, 3); if( citp.log_fd >= 0 && citp_fdtable.table != NULL ) citp_fdtable.table[citp.log_fd].fdip = fdi_to_fdip(&citp_the_reserved_fd); } if( citp.log_fd < 0 ) { citp.log_fd = STDERR_FILENO; tmp_fd = 1; } } v[0].iov_base = (void*) msg; v[0].iov_len = strlen(v[0].iov_base); v[1].iov_base = "\n"; v[1].iov_len = strlen(v[1].iov_base); my_syscall3(writev, citp.log_fd, (long) v, 2); if( tmp_fd ) citp.log_fd = -1; }
void citp_log_change_fd(void) { int newfd, prev; /* We need to change logging fd, probably because someone wants to do a ** dup2() onto it. ** ** No need to set 'close-on-exec' (FD_CLOEXEC) again for the newfd as ** it will be copied by the dup(). */ CITP_FDTABLE_LOCK(); prev = citp.log_fd; newfd = oo_fcntl_dupfd_cloexec(prev, 3); if( newfd >= 0 ) { __citp_fdtable_reserve(newfd, 1); citp.log_fd = newfd; } Log_S(log("%s: old=%d new=%d", __FUNCTION__, prev, newfd)); __citp_fdtable_reserve(prev, 0); ci_sys_close(prev); CITP_FDTABLE_UNLOCK(); }
int ef_onload_handle_move_and_do_cloexec(ef_driver_handle* pfd, int do_cloexec) { int fd; if( do_cloexec ) fd = oo_fcntl_dupfd_cloexec(*pfd, CITP_OPTS.fd_base); else fd = ci_sys_fcntl(*pfd, F_DUPFD, CITP_OPTS.fd_base); /* If we've successfully done the dup then we've also set CLOEXEC if * needed on the new fd, so we're done. */ if( fd >= 0 ) { ci_tcp_helper_close_no_trampoline(*pfd); *pfd = fd; return 0; } else { LOG_NV(ci_log("%s: Failed to move fd from %d, rc %d", __func__, *pfd, fd)); } return fd; }