Пример #1
0
int
_tap_ctl_stats_connect_and_send(pid_t pid, int minor)
{
	struct timeval timeout = { .tv_sec = 10, .tv_usec = 0 };
	tapdisk_message_t message;
	int sfd, err;

	err = tap_ctl_connect_id(pid, &sfd);
	if (err)
		return err;

	memset(&message, 0, sizeof(message));
	message.type   = TAPDISK_MESSAGE_STATS;
	message.cookie = minor;

	err = tap_ctl_write_message(sfd, &message, &timeout);
	if (err)
		return err;

	return sfd;
}

ssize_t
tap_ctl_stats(pid_t pid, int minor, char *buf, size_t size)
{
	tapdisk_message_t message;
	int sfd, err;
	size_t len;

	sfd = _tap_ctl_stats_connect_and_send(pid, minor);
	if (sfd < 0)
		return sfd;

	err = tap_ctl_read_message(sfd, &message, NULL);
	if (err)
		return err;

	len= message.u.info.length;
	if (len < 0) {
		err = len;
		goto out;
	}
	if (size < len + 1)
		len = size - 1;

	err = tap_ctl_read_raw(sfd, buf, len, NULL);
	if (err)
		goto out;

	buf[len] = 0;

out:
	close(sfd);
	return err;
}
Пример #2
0
int
tap_ctl_connect_send_and_receive(int id, tapdisk_message_t * message,
                                 struct timeval *timeout)
{
    int err, sfd;

    err = tap_ctl_connect_id(id, &sfd);
    if (err)
        return err;

    err = tap_ctl_send_and_receive(sfd, message, timeout);

    close(sfd);
    return err;
}
Пример #3
0
int
tap_ctl_connect_send_receive_with_logpath(int id, tapdisk_message_t *message,
				 const char *logpath, struct timeval *timeout)
{
	int err, sfd;

	err = tap_ctl_connect_id(id, &sfd);
	if (err)
		return err;

	err = tap_ctl_send_and_receive_with_logpath(sfd, message, logpath, timeout);

	close(sfd);
	return err;
}