lib/Tools/mkfifo
author wenzelm
Sat, 18 Sep 2010 19:38:27 +0200
changeset 39521 7ed922d15827
parent 39520 bad14b7d0520
permissions -rwxr-xr-x
mkfifo: some workaround to ensure reasonably unique id, even on Cygwin where $PPID might fall back on odd default;

#!/usr/bin/env bash
#
# Author: Makarius
#
# DESCRIPTION: create named pipe


PRG="$(basename "$0")"

function usage()
{
  echo
  echo "Usage: isabelle $PRG [SUFFIX]"
  echo
  echo "  Create a temporary named pipe and return its name."
  echo
  exit 1
}

function fail()
{
  echo "$1" >&2
  exit 2
}


## main

SUFFIX=""
[ "$#" != 0 ] && { SUFFIX="-$1"; shift; }

[ "$#" != 0 ] && usage

ID="$PPID"
[ "$ID" = 0 -o "$ID" = 1 ] && ID="$$"  # Cygwin workaround

FIFO="/tmp/isabelle-fifo${ID}${SUFFIX}"

mkfifo -m 600 "$FIFO" || fail "Failed to create fifo: $FIFO"
echo "$FIFO"