Blame lib/old_socket.c

Packit Service 5956c7
/*
Packit Service 5956c7
 * Soft:        Keepalived is a failover program for the LVS project
Packit Service 5956c7
 *              <www.linuxvirtualserver.org>. It monitor & manipulate
Packit Service 5956c7
 *              a loadbalanced server pool using multi-layer checks.
Packit Service 5956c7
 *
Packit Service 5956c7
 * Part:        old_socket.c
Packit Service 5956c7
 *
Packit Service 5956c7
 * Author:      Alexandre Cassen, <acassen@linux-vs.org>
Packit Service 5956c7
 *
Packit Service 5956c7
 *              This program is distributed in the hope that it will be useful,
Packit Service 5956c7
 *              but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 5956c7
 *              MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Packit Service 5956c7
 *              See the GNU General Public License for more details.
Packit Service 5956c7
 *
Packit Service 5956c7
 *              This program is free software; you can redistribute it and/or
Packit Service 5956c7
 *              modify it under the terms of the GNU General Public License
Packit Service 5956c7
 *              as published by the Free Software Foundation; either version
Packit Service 5956c7
 *              2 of the License, or (at your option) any later version.
Packit Service 5956c7
 *
Packit Service 5956c7
 * Copyright (C) 2001-2016 Alexandre Cassen, <acassen@gmail.com>
Packit Service 5956c7
 */
Packit Service 5956c7
Packit Service 5956c7
#include "config.h"
Packit Service 5956c7
Packit Service 5956c7
#include <sys/socket.h>
Packit Service 5956c7
#include <unistd.h>
Packit Service 5956c7
#include <fcntl.h>
Packit Service 5956c7
#include <string.h>
Packit Service 5956c7
#include <errno.h>
Packit Service 5956c7
Packit Service 5956c7
#include "old_socket.h"
Packit Service 5956c7
#include "logger.h"
Packit Service 5956c7
Packit Service 5956c7
bool set_sock_flags(int fd, int cmd, long flags)
Packit Service 5956c7
{
Packit Service 5956c7
	/* This is slightly odd. The man page for fcntl says that the
Packit Service 5956c7
	   parameter passed to F_SETFD/F_SETFL is a long, but fnctl
Packit Service 5956c7
	   only returns an int to F_GETFD/F_GETFL */
Packit Service 5956c7
	long sock_flags;
Packit Service 5956c7
	int get_cmd = (cmd == F_SETFD) ? F_GETFD : F_GETFL;
Packit Service 5956c7
Packit Service 5956c7
	if ((sock_flags = fcntl(fd, get_cmd)) == -1) {
Packit Service 5956c7
		log_message(LOG_INFO, "Netlink: Cannot get socket flags : (%s)", strerror(errno));
Packit Service 5956c7
		return true;
Packit Service 5956c7
	}
Packit Service 5956c7
Packit Service 5956c7
	if (fcntl(fd, cmd, sock_flags | flags) < 0) {
Packit Service 5956c7
		log_message(LOG_INFO, "Netlink: Cannot set socket flags: (%s)", strerror(errno));
Packit Service 5956c7
		return true;
Packit Service 5956c7
	}
Packit Service 5956c7
Packit Service 5956c7
	return false;
Packit Service 5956c7
}