criu/test/zdtm/lib/streamutil.c
Andrey Vagin 5a49b9e216 zdtm: Zero Downtime Migration Test Suite
This test suite contains many small test cases for different subsystems.

Example of execution:
 # make busyloop00.pid
 # ../../../../crtools -d -t `cat busyloop00.pid`
 # kill -9 `cat busyloop00.pid`
 # ../../../../crtools -r -t `cat busyloop00.pid`
 # cat busyloop00.out
PASS

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
2011-12-02 17:49:08 +04:00

42 lines
687 B
C

#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include "zdtmtst.h"
int set_nonblock(int fd, int on)
{
int flag;
flag = fcntl(fd, F_GETFL, 0);
if (flag < 0)
return flag;
if (on)
flag |= O_NONBLOCK;
else
flag &= ~O_NONBLOCK;
return fcntl(fd, F_SETFL, flag);
}
int pipe_in2out(int infd, int outfd, uint8_t *buffer, int length)
{
uint8_t *buf;
int rlen, wlen;
while (1) {
rlen = read(infd, buffer, length);
if (rlen <= 0)
return rlen;
/* don't go reading until we're done with writing */
for (buf = buffer; rlen > 0; buf += wlen, rlen -= wlen) {
wlen = write(outfd, buf, rlen);
if (wlen < 0)
return wlen;
}
}
}