test-istream-unix.c revision bcb4e51a409d94ae670de96afb8483a4f7855294
/* Copyright (c) 2015-2018 Dovecot authors, see the included COPYING file */
#include "test-lib.h"
#include "net.h"
#include "fdpass.h"
#include "istream.h"
#include "istream-unix.h"
#include <unistd.h>
#include <fcntl.h>
{
i_fatal("write() failed: %m");
}
{
char buf;
i_fatal("read() failed: m");
}
static void
{
const unsigned char *data;
}
static void
{
const unsigned char *data;
int recv_fd;
if (recv_fd != -1) {
i_fatal("fstat() failed: %m");
}
}
static void test_istream_unix_server(int fd)
{
const unsigned char *data;
/* 1) simple read */
/* 2) fd was sent but we won't get it */
/* we still shouldn't have the fd */
/* 3) the previous fd should be lost now */
/* 4) we should get the fd now */
/* 5) the previous fd shouldn't be returned anymore */
/* 6) with i_stream_unix_unset_read_fd() we shouldn't get fd anymore */
/* 7-8) two fds were sent, but we'll get only the first one */
/* 9-10) two fds were sent, and we'll get them both */
i_close_fd(&fd);
}
static void test_istream_unix_client(int fd)
{
/* 1) */
/* 2) */
i_fatal("fd_send() failed: %m");
/* 3) */
/* 4) */
i_fatal("fd_send() failed: %m");
/* 5) */
/* 6) */
i_fatal("fd_send() failed: %m");
/* 7-8) */
i_fatal("fd_send() failed: %m");
i_fatal("fd_send() failed: %m");
/* 9-10) */
i_fatal("fd_send() failed: %m");
i_fatal("fd_send() failed: %m");
i_close_fd(&fd);
}
void test_istream_unix(void)
{
int fd[2];
test_begin("istream unix");
i_fatal("socketpair() failed: %m");
switch (fork()) {
case -1:
i_fatal("fork() failed: %m");
case 0:
i_close_fd(&fd[0]);
test_exit(0);
default:
break;
}
test_end();
}