From owner-freebsd-hackers@FreeBSD.ORG Sat Jun 2 22:57:20 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 7C37116A400 for ; Sat, 2 Jun 2007 22:57:20 +0000 (UTC) (envelope-from artifact.one@googlemail.com) Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.230]) by mx1.freebsd.org (Postfix) with ESMTP id 3F49E13C448 for ; Sat, 2 Jun 2007 22:57:20 +0000 (UTC) (envelope-from artifact.one@googlemail.com) Received: by wx-out-0506.google.com with SMTP id h28so762387wxd for ; Sat, 02 Jun 2007 15:57:19 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=googlemail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=OSPNUdqynC1xIAKsCVVpMaARlSg8KQoCj5YYZMEkPAJr9oM5z0eCk7ABNXQTudKXHHaHDaqsFf2VXy4uxXsJ7+1pLMLc5QgOOE/gOWByz1ibC9katU9y6RKxG53E1fihFSNDsyPXLp7PFgX/pgytkglVkEnFoamYmd/1b5w0yNk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=beta; h=received:message-id:date:from:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=Rec7t8MkZsPv/2QSzkhwF88IP5lSJQX9D+n87O+gWoSCx1zDv+NRnxBxFTUJSBpN99IQsvFgPAqOaE65cYsm9cLl2fZVZZeLNjvh8n9i70YC8BTXTVx6tncilqFReGHSf1NnFnMS8mAIudWawvWa6GKhQAE8IwTCGv/bYUHngMY= Received: by 10.90.95.11 with SMTP id s11mr2773695agb.1180825039433; Sat, 02 Jun 2007 15:57:19 -0700 (PDT) Received: by 10.90.51.1 with HTTP; Sat, 2 Jun 2007 15:57:19 -0700 (PDT) Message-ID: <8e96a0b90706021557h2168337emb9b7b59a2084530e@mail.gmail.com> Date: Sat, 2 Jun 2007 23:57:19 +0100 From: "mal content" To: freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Subject: Open FIFO non-blocking but have write() block(?) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Jun 2007 22:57:20 -0000 Hello. The wording of the question in the subject is terrible, I know. What I'm trying to do is write a program that creates two named pipes in the filesystem. Logging date appears on one, to be read by any external program and commands are read by the program from the other. If data is written to the logging FIFO and there's no external reader, the log info is discarded. The problem I'm having is that I can create the 'log' fifo with mkfifo but the open call fails because there's no reader: if (mkfifo("control", 0600) == -1) die(); fd1 = open("control", O_RDONLY | O_NONBLOCK); if (fd1 == -1) die(); if (mkfifo("log", 0600) == -1) die(); fd2 = open("log", O_WRONLY | O_NONBLOCK); if (fd2 == -1) die(); Obviously I can remove the O_NONBLOCK from the second open call, but this causes it to block and I don't want that. The behaviour I'm actually looking for is that the first open() call should succeed but the first write made to the fifo (with no reader) should fail. Is it possible to portably get this behaviour from FIFOs? Or should I be looking at something else like unix domain sockets? thanks, MC