57#if HAVE_SYS_CAPABILITY_H
58#include <sys/capability.h>
68#define LINK_TO_SQUID squid_link
74Win32__WSAFDIsSet(
int fd, fd_set FAR * set)
77 SOCKET s = F->win32.handle;
79 return __WSAFDIsSet(s, set);
85#define LINK_TO_SQUID 1
89using namespace std::literals::chrono_literals;
103 if (std::current_exception())
106 os <<
"An undetermined failure";
114 static bool terminating =
false;
143 int icmp4_worker = -1;
144 int icmp6_worker = -1;
157 if (icmp4_worker < 0) {
160 max_fd =
max(max_fd, icmp4_worker);
164 if (icmp6_worker <0 ) {
167 max_fd =
max(max_fd, icmp6_worker);
171 if (icmp4_worker < 0 && icmp6_worker < 0) {
182 max_fd =
max(max_fd, squid_link);
184 if (setgid(getgid()) < 0) {
191 if (setuid(getuid()) < 0) {
212 if (cap_set_proc(caps) != 0) {
230 if (icmp4_worker >= 0) {
231 FD_SET(icmp4_worker, &R);
233 if (icmp6_worker >= 0) {
234 FD_SET(icmp6_worker, &R);
237 FD_SET(squid_link, &R);
240 const auto x =
xselect(max_fd+1, &R,
nullptr,
nullptr, &tv);
250 if (FD_ISSET(squid_link, &R)) {
254 if (icmp6_worker >= 0 && FD_ISSET(icmp6_worker, &R)) {
257 if (icmp4_worker >= 0 && FD_ISSET(icmp4_worker, &R)) {
261 const auto delay = std::chrono::duration_cast<std::chrono::seconds>(timer.
total());
264 debugs(42,
DBG_CRITICAL,
"Closing. No requests in last " << delay.count() <<
" seconds.");
279main(
int,
char *argv[])
281 std::cerr << argv[0] <<
": ICMP support not compiled in." << std::endl;
std::ostream & CurrentException(std::ostream &os)
prints active (i.e., thrown but not yet handled) exception
static void PrepareToDie()
static void NameThisHelper(const char *name)
void Recv(void) override
Handle ICMP responses.
int Open() override
Start pinger helper and initiate control channel.
int Open() override
Start pinger helper and initiate control channel.
void Recv(void) override
Handle ICMP requests from squid, passing to helpers.
void Close() override
Shutdown pinger helper and control channel.
int Open() override
Start and initiate control channel to squid.
virtual void Close()
Shutdown pinger helper and control channel.
Clock::duration total() const
A const & max(A const &lhs, A const &rhs)
#define debugs(SECTION, LEVEL, CONTENT)
void ProbeTransport(void)
Probe to discover IPv6 capabilities.
IcmpPinger control
pinger helper contains one of these as a global object.
static void OnTerminate()
static const auto PingerTimeout
Icmp6 icmp6
pinger helper contains one of these as a global object.
static std::ostream & TerminationReason(std::ostream &os)
reports std::terminate() cause (e.g., an uncaught or prohibited exception)
Icmp4 icmp4
pinger helper contains one of these as a global object.
int xselect(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
POSIX select(2) equivalent.
ssize_t xsend(int socketFd, const void *buf, size_t bufLength, int flags)
POSIX send(2) equivalent.
time_t getCurrentTime() STUB_RETVAL(0) int tvSubUsec(struct timeval
const char * xstrerr(int error)