1 Star 0 Fork 1

mysnapcore / mysnapd

forked from tupelo-shen / mysnapd 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
fifo.go 1.64 KB
一键复制 编辑 原始数据 按行查看 历史
tupelo-shen 提交于 2022-11-08 21:16 . fix: secboot commit
// -*- Mode: Go; indent-tabs-mode: t -*-
/*
* Copyright (C) 2022 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package luks2
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"golang.org/x/sys/unix"
"golang.org/x/xerrors"
"gitee.com/mysnapcore/mysnapd/dirs"
)
func mkFifo() (string, func(), error) {
// /run is not world writable but we create a unique directory here because this
// code can be invoked by a public API and we shouldn't fail if more than one
// process reaches here at the same time.
dir, err := ioutil.TempDir(dirs.RunDir, filepath.Base(os.Args[0])+".")
if err != nil {
return "", nil, xerrors.Errorf("cannot create temporary directory: %w", err)
}
cleanup := func() {
if err := os.RemoveAll(dir); err != nil {
fmt.Fprintf(stderr, "luks2.mkFifo: cannot remove fifo: %v\n", err)
}
}
succeeded := false
defer func() {
if succeeded {
return
}
cleanup()
}()
fifo := filepath.Join(dir, "fifo")
if err := unix.Mkfifo(fifo, 0600); err != nil {
return "", nil, xerrors.Errorf("cannot create FIFO: %w", err)
}
succeeded = true
return fifo, cleanup, nil
}
Go
1
https://gitee.com/mysnapcore/mysnapd.git
git@gitee.com:mysnapcore/mysnapd.git
mysnapcore
mysnapd
mysnapd
v0.1.0

搜索帮助