gitlab.com/apertussolutions/u-root@v7.0.0+incompatible/cmds/core/mkfifo/mkfifo.go (about)

     1  // Copyright 2013-2017 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // mkfifo creates a named pipe.
     6  //
     7  // Synopsis:
     8  //     mkfifo [OPTIONS] NAME...
     9  //
    10  // Options:
    11  //     -m: mode (default 0600)
    12  //
    13  package main
    14  
    15  import (
    16  	"flag"
    17  	"log"
    18  	"os"
    19  
    20  	"golang.org/x/sys/unix"
    21  )
    22  
    23  const (
    24  	defaultMode = 0660 | unix.S_IFIFO
    25  	cmd         = "mkfifo [-m] NAME..."
    26  )
    27  
    28  var mode = flag.Int("mode", defaultMode, "Mode to create fifo")
    29  
    30  func init() {
    31  	defUsage := flag.Usage
    32  	flag.Usage = func() {
    33  		os.Args[0] = cmd
    34  		defUsage()
    35  	}
    36  }
    37  
    38  func main() {
    39  	flag.Parse()
    40  
    41  	if flag.NArg() < 1 {
    42  		log.Fatal("please provide a path, or multiple, to create a fifo")
    43  	}
    44  
    45  	for _, path := range flag.Args() {
    46  		if err := unix.Mkfifo(path, uint32(*mode)); err != nil {
    47  			log.Fatalf("Error while creating fifo, %v", err)
    48  		}
    49  	}
    50  }