Ejemplo n.º 1
0
int
mgmt_ipc_listen(void)
{
	int fd, err, addr_len;
	struct sockaddr_un addr;

	/* first check if we have fd handled by systemd */
	fd = mgmt_ipc_systemd();
	if (fd >= 0)
		return fd;

	/* manually establish a socket */
	fd = socket(AF_LOCAL, SOCK_STREAM, 0);
	if (fd < 0) {
		log_error("Can not create IPC socket");
		return fd;
	}

	addr_len = setup_abstract_addr(&addr, ISCSIADM_NAMESPACE);

	if ((err = bind(fd, (struct sockaddr *) &addr, addr_len)) < 0 ) {
		log_error("Can not bind IPC socket");
		close(fd);
		return err;
	}

	if ((err = listen(fd, 32)) < 0) {
		log_error("Can not listen IPC socket");
		close(fd);
		return err;
	}

	return fd;
}
Ejemplo n.º 2
0
static int ipc_connect(int *fd, char *unix_sock_name, int start_iscsid)
{
	int nsec, addr_len;
	struct sockaddr_un addr;

	*fd = socket(AF_LOCAL, SOCK_STREAM, 0);
	if (*fd < 0) {
		log_error("can not create IPC socket (%d)!", errno);
		return ISCSI_ERR_ISCSID_NOTCONN;
	}

	addr_len = setup_abstract_addr(&addr, unix_sock_name);

	/*
	 * Trying to connect with exponential backoff
	 */
	for (nsec = 1; nsec <= MAXSLEEP; nsec <<= 1) {
		if (connect(*fd, (struct sockaddr *) &addr, addr_len) == 0)
			/* Connection established */
			return ISCSI_SUCCESS;

		/* If iscsid isn't there, there's no sense
		 * in retrying. */
		if (errno == ECONNREFUSED) {
			if (start_iscsid && nsec == 1)
				iscsid_startup();
			else
				break;
		}

		/*
		 * Delay before trying again
		 */
		if (nsec <= MAXSLEEP/2)
			sleep(nsec);
	}
	log_error("can not connect to iSCSI daemon (%d)!", errno);
	return ISCSI_ERR_ISCSID_NOTCONN;
}