Esempio n. 1
0
static void signal_SIGTERM(int sig)
{
    static const char message[] = "\nCaught SIGTERM!\n";

    sRet = EXIT_QUIT;

    // Can't use syslog() because it isn't async signal safe.
    // So we write to stderr
    IGNORE_RETURN_VALUE(write(STDERR_FILENO, message, sizeof(message)-1));

    // Restore the previous handler so that if we end up getting
    // this signal again we perform the system default action.
    signal(SIGTERM, sPreviousHandlerForSIGTERM);
    sPreviousHandlerForSIGTERM = NULL;
    (void) sig;
}
Esempio n. 2
0
static void signal_SIGHUP(int sig)
{
    static const char message[] = "\nCaught SIGHUP!\n";

    sRet = EXIT_FAILURE;

    // Can't use syslog() because it isn't async signal safe.
    // So we write to stderr
    IGNORE_RETURN_VALUE(write(STDERR_FILENO, message, sizeof(message)-1));

    // We don't restore the "previous handler"
    // because we always want to let the main
    // loop decide what to do for hangups.

    (void) sig;
}
Esempio n. 3
0
void
TunnelIPv6Interface::setup_signals()
{
	int status;
	int fd;
	struct sockaddr_nl la;

	fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);

	require(fd != -1, bail);

	memset(&la, 0, sizeof(la));
	la.nl_family = AF_NETLINK;
	la.nl_pad = 0;
	la.nl_groups = RTMGRP_LINK | RTMGRP_IPV6_IFADDR;

	// We calculate the PID in a pseudo-random way based on the
	// address pointer and the actual process ID.
	la.nl_pid = LCG32(getpid()) ^ LCG32((uint32_t)reinterpret_cast<uintptr_t>(this));

	status = bind(fd, (struct sockaddr*) &la, sizeof(la));

	require(status != -1, bail);

	// Success!
	IGNORE_RETURN_VALUE(fcntl(fd, F_SETFL, FNDELAY));

	mNetlinkFD = fd;
	fd = -1;

bail:

	// Cleanup (If necessary)
	if (fd > 0) {
		close(fd);
	}

	return;
}