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