[lxc-devel] [PATCH 4/5] Implement simple utility functions for reading and writing to fds

Serge Hallyn serge.hallyn at ubuntu.com
Mon May 20 18:37:42 UTC 2013


Quoting Christian Seiler (christian at iwakd.de):
> Signed-off-by: Christian Seiler <christian at iwakd.de>

Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

> ---
>  src/lxc/utils.c |   35 +++++++++++++++++++++++++++++++++++
>  src/lxc/utils.h |    5 +++++
>  2 files changed, 40 insertions(+), 0 deletions(-)
> 
> diff --git a/src/lxc/utils.c b/src/lxc/utils.c
> index 66bd19d..cd35e00 100644
> --- a/src/lxc/utils.c
> +++ b/src/lxc/utils.c
> @@ -281,3 +281,38 @@ again:
>  		goto again;
>  	return status;
>  }
> +
> +int lxc_write_nointr(int fd, const void* buf, size_t count)
> +{
> +	int ret;
> +again:
> +	ret = write(fd, buf, count);
> +	if (ret < 0 && errno == EINTR)
> +		goto again;
> +	return ret;
> +}
> +
> +int lxc_read_nointr(int fd, void* buf, size_t count)
> +{
> +	int ret;
> +again:
> +	ret = read(fd, buf, count);
> +	if (ret < 0 && errno == EINTR)
> +		goto again;
> +	return ret;
> +}
> +
> +int lxc_read_nointr_expect(int fd, void* buf, size_t count, const void* expected_buf)
> +{
> +	int ret;
> +	ret = lxc_read_nointr(fd, buf, count);
> +	if (ret <= 0)
> +		return ret;
> +	if (ret != count)
> +		return -1;
> +	if (expected_buf && memcmp(buf, expected_buf, count) != 0) {
> +		errno = EINVAL;
> +		return -1;
> +	}
> +	return ret;
> +}
> diff --git a/src/lxc/utils.h b/src/lxc/utils.h
> index be1a8a8..d1242b1 100644
> --- a/src/lxc/utils.h
> +++ b/src/lxc/utils.h
> @@ -68,4 +68,9 @@ extern int __build_bug_on_failed;
>  extern int wait_for_pid(pid_t pid);
>  extern int lxc_wait_for_pid_status(pid_t pid);
>  
> +/* send and receive buffers completely */
> +extern int lxc_write_nointr(int fd, const void* buf, size_t count);
> +extern int lxc_read_nointr(int fd, void* buf, size_t count);
> +extern int lxc_read_nointr_expect(int fd, void* buf, size_t count, const void* expected_buf);
> +
>  #endif
> -- 
> 1.7.8.6
> 
> 
> ------------------------------------------------------------------------------
> AlienVault Unified Security Management (USM) platform delivers complete
> security visibility with the essential security capabilities. Easily and
> efficiently configure, manage, and operate all of your security controls
> from a single console and one unified framework. Download a free trial.
> http://p.sf.net/sfu/alienvault_d2d
> _______________________________________________
> Lxc-devel mailing list
> Lxc-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lxc-devel




More information about the lxc-devel mailing list