|
nsz |
462b4f |
#ifndef _XOPEN_SOURCE
|
|
nsz |
73214b |
#define _XOPEN_SOURCE 700
|
|
nsz |
462b4f |
#endif
|
|
nsz |
73214b |
#include <stdlib.h>
|
|
nsz |
73214b |
#include <unistd.h>
|
|
nsz |
73214b |
#include <stdio.h>
|
|
nsz |
73214b |
#include <errno.h>
|
|
nsz |
73214b |
#include <string.h>
|
|
nsz |
73214b |
#include <spawn.h>
|
|
nsz |
73214b |
#include <sys/wait.h>
|
|
nsz |
73214b |
#include "test.h"
|
|
nsz |
73214b |
|
|
nsz |
462b4f |
#define TEST(f, x) (void)( \
|
|
nsz |
462b4f |
(r = (f)) == (x) || \
|
|
Szabolcs Nagy |
cfa23c |
t_error("%s failed, got %d want %d\n", #f, r, x) )
|
|
nsz |
73214b |
|
|
nsz |
462b4f |
#define TEST_E(f) (void)( \
|
|
nsz |
462b4f |
(errno = 0), (f) || \
|
|
Szabolcs Nagy |
cfa23c |
t_error("%s failed (errno = %d \"%s\")\n", #f, errno, strerror(errno)) )
|
|
nsz |
73214b |
|
|
nsz |
462b4f |
int main(void)
|
|
nsz |
462b4f |
{
|
|
nsz |
73214b |
int r;
|
|
nsz |
73214b |
char foo[10];
|
|
nsz |
73214b |
int p[2];
|
|
nsz |
73214b |
pid_t pid;
|
|
nsz |
73214b |
int status;
|
|
nsz |
73214b |
posix_spawn_file_actions_t fa;
|
|
nsz |
73214b |
|
|
nsz |
73214b |
TEST_E(!pipe(p));
|
|
nsz |
462b4f |
TEST(posix_spawn_file_actions_init(&fa), 0);
|
|
nsz |
462b4f |
TEST(posix_spawn_file_actions_addclose(&fa, p[0]), 0);
|
|
nsz |
462b4f |
TEST(posix_spawn_file_actions_adddup2(&fa, p[1], 1), 0);
|
|
nsz |
462b4f |
TEST(posix_spawn_file_actions_addclose(&fa, p[1]), 0);
|
|
nsz |
462b4f |
TEST(posix_spawnp(&pid, "echo", &fa, 0, (char *[]){"echo","hello",0}, 0), 0);
|
|
nsz |
73214b |
close(p[1]);
|
|
nsz |
462b4f |
TEST(waitpid(pid, &status, 0), pid);
|
|
nsz |
462b4f |
TEST(read(p[0], foo, sizeof foo), 6);
|
|
nsz |
73214b |
close(p[0]);
|
|
nsz |
462b4f |
TEST(posix_spawn_file_actions_destroy(&fa), 0);
|
|
Szabolcs Nagy |
cfa23c |
return t_status;
|
|
nsz |
73214b |
}
|