1/*++
2/* NAME
3/*	fifo_open 1
4/* SUMMARY
5/*	fifo client test program
6/* SYNOPSIS
7/*	fifo_open
8/* DESCRIPTION
9/*	fifo_open creates a FIFO, then attempts to open it for writing
10/*	with non-blocking mode enabled. According to the POSIX standard
11/*	the open should succeed.
12/* DIAGNOSTICS
13/*	Problems are reported to the standard error stream.
14/* LICENSE
15/* .ad
16/* .fi
17/*	The Secure Mailer license must be distributed with this software.
18/* AUTHOR(S)
19/*	Wietse Venema
20/*	IBM T.J. Watson Research
21/*	P.O. Box 704
22/*	Yorktown Heights, NY 10598, USA
23/*--*/
24
25#include <sys/stat.h>
26#include <stdio.h>
27#include <fcntl.h>
28#include <signal.h>
29#include <unistd.h>
30#include <stdlib.h>
31
32#define FIFO_PATH	"test-fifo"
33#define perrorexit(s)	{ perror(s); exit(1); }
34
35static void cleanup(void)
36{
37    printf("Removing fifo %s...\n", FIFO_PATH);
38    if (unlink(FIFO_PATH))
39	perrorexit("unlink");
40    printf("Done.\n");
41}
42
43static void stuck(int unused_sig)
44{
45    printf("Non-blocking, write-only open of FIFO blocked\n");
46    cleanup();
47    exit(1);
48}
49
50int     main(int unused_argc, char **unused_argv)
51{
52    (void) unlink(FIFO_PATH);
53    printf("Creating fifo %s...\n", FIFO_PATH);
54    if (mkfifo(FIFO_PATH, 0600) < 0)
55	perrorexit("mkfifo");
56    signal(SIGALRM, stuck);
57    alarm(5);
58    printf("Opening fifo %s, non-blocking, write-only mode...\n", FIFO_PATH);
59    if (open(FIFO_PATH, O_WRONLY | O_NONBLOCK, 0) < 0) {
60	perror("open");
61	cleanup();
62	exit(1);
63    }
64    printf("Non-blocking, write-only open of FIFO succeeded\n");
65    cleanup();
66    exit(0);
67}
68