static void setup_signals(void) { struct sigaction sa; sigemptyset(&sa.sa_mask); sa.sa_handler = term_handler; sa.sa_flags = 0; if (sigaction(SIGTERM, &sa, NULL)) err_errno("sigaction() failed"); if (sigaction(SIGINT, &sa, NULL)) err_errno("sigaction() failed"); }
static int is_tailable(const char *file) { struct stat sb; /* follow symlinks */ if (stat(file, &sb)) err_errno("stat() failed"); return S_ISREG(sb.st_mode); }
//---------------------------------------------------------------------- // close$NOCANCEL() interpose function //---------------------------------------------------------------------- extern "C" int close$NOCANCEL$__interposed__(int fd) { const int pid = get_interposed_pid(); if (pid >= 0) { Locker locker(&g_mutex); const int err = close$NOCANCEL(fd); NegativeErrorErrno err_errno(err); StringSP description_sp(new String); if (err == -1) description_sp->printf( "pid=%i: close$NOCANCEL (fd=%i) => %i errno = %i (%s))", pid, fd, err, err_errno.get_errno(), strerror(err_errno.get_errno())); else description_sp->printf("pid=%i: close$NOCANCEL (fd=%i) => %i", pid, fd, err); if (g_log_all_calls) description_sp->log(get_logging_fd()); if (err == 0) { if (fd >= 0) save_backtrace(fd, err, description_sp, false); } else if (err == -1) { if (err_errno.get_errno() == EBADF && fd != -1) { backtrace_error("close$NOCANCEL (fd=%d) resulted in EBADF\n:", fd); FDEventMap::iterator pos = g_fd_event_map.find(fd); if (pos != g_fd_event_map.end()) { log(get_logging_fd(), pos->second.back().get(), "\nfd=%d was previously %s with this event:\n", fd, pos->second.back()->IsCreateEvent() ? "opened" : "closed"); } } } return err; } else { return close$NOCANCEL(fd); } }
//---------------------------------------------------------------------- // socketpair() interpose function //---------------------------------------------------------------------- extern "C" int socketpair$__interposed__(int domain, int type, int protocol, int fds[2]) { const int pid = get_interposed_pid(); if (pid >= 0) { Locker locker(&g_mutex); fds[0] = -1; fds[1] = -1; const int err = socketpair(domain, type, protocol, fds); NegativeErrorErrno err_errno(err); StringSP description_sp( new String("pid=%i: socketpair (domain=%i, type=%i, protocol=%i, " "{fd=%i, fd=%i}) -> err=%i", pid, domain, type, protocol, fds[0], fds[1], err)); if (g_log_all_calls) description_sp->log(get_logging_fd()); if (fds[0] >= 0) save_backtrace(fds[0], err_errno.get_errno(), description_sp, true); if (fds[1] >= 0) save_backtrace(fds[1], err_errno.get_errno(), description_sp, true); return err; } else { return socketpair(domain, type, protocol, fds); } }