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