kdnotify/fifo/mk.go
Paul Stemmet 59204d6bd1
fifo: add MkPipe/1
for creating the underlying IPC channel that we'll use for communication
with keepalived
2022-12-09 18:05:54 +00:00

32 lines
782 B
Go

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package fifo
import (
"context"
"fmt"
"io"
"syscall"
"github.com/containerd/fifo"
)
const Flags = syscall.O_CREAT | syscall.O_RDONLY | syscall.O_NONBLOCK
// Create a FIFO pipe at the provided path, returning a read handle.
//
// FIFO is opened non blocking, so this is save to call before keepalived
// is ready to transmit notifications
func MkPipe(path string) (io.ReadCloser, error) {
npipe, err := fifo.OpenFifo(context.TODO(), path, Flags, 0640)
if err != nil {
return nil, fmt.Errorf("failed to open fifo '%s': %w", path, err)
}
return npipe, nil
}