1 Star 0 Fork 0

peter/fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
.github
bccsp
ci
cmd
common
core
aclmgmt
cclifecycle
chaincode
committer
common
config
container
ccintf
dockercontroller
externalbuilder
testdata
copy.go
copy_test.go
externalbuilder.go
externalbuilder_suite_test.go
externalbuilder_test.go
instance.go
instance_test.go
metadataprovider.go
metadataprovider_test.go
session.go
session_test.go
tar.go
tar_test.go
mock
build_registry.go
build_registry_test.go
container.go
container_suite_test.go
container_test.go
deliverservice
dispatcher
endorser
handlers
ledger
middleware
mocks
operations
peer
policy
scc
testutil
transientstore
tx
discovery
docs
gossip
idemix
images
integration
internal
msp
orderer
pkg
protoutil
release_notes
sampleconfig
scripts
vagrant
vendor
.dockerignore
.gitattributes
.gitignore
.mergify.yml
CHANGELOG.md
CODEOWNERS
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Gopkg.lock
Gopkg.toml
LICENSE
MAINTAINERS.md
Makefile
README.md
SECURITY.md
docker-env.mk
gotools.mk
test-pyramid.png
testingInfo.rst
tox.ini
克隆/下载
session.go 1.90 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package externalbuilder
import (
"bufio"
"io"
"os"
"os/exec"
"path/filepath"
"sync"
"syscall"
"github.com/hyperledger/fabric/common/flogging"
)
type Session struct {
mutex sync.Mutex
command *exec.Cmd
exited chan struct{}
exitErr error
waitStatus syscall.WaitStatus
}
// Start will start the provided command and return a Session that can be used
// to await completion or signal the process.
//
// The provided logger is used log stderr from the running process.
func Start(logger *flogging.FabricLogger, cmd *exec.Cmd) (*Session, error) {
logger = logger.With("command", filepath.Base(cmd.Path))
stderr, err := cmd.StderrPipe()
if err != nil {
return nil, err
}
err = cmd.Start()
if err != nil {
return nil, err
}
sess := &Session{
command: cmd,
exited: make(chan struct{}),
}
go sess.waitForExit(logger, stderr)
return sess, nil
}
func (s *Session) waitForExit(logger *flogging.FabricLogger, stderr io.Reader) {
// copy stderr to the logger until stderr is closed
scanner := bufio.NewScanner(stderr)
for scanner.Scan() {
logger.Info(scanner.Text())
}
if err := scanner.Err(); err != nil {
logger.Errorf("command output scanning failed: %s", err)
}
// wait for the command to exit and to complete
err := s.command.Wait()
// update state and close the exited channel
s.mutex.Lock()
defer s.mutex.Unlock()
s.exitErr = err
s.waitStatus = s.command.ProcessState.Sys().(syscall.WaitStatus)
close(s.exited)
}
// Wait waits for the running command to terminate and returns the exit error
// from the command. If the command has already exited, the exit err will be
// returned immediately.
func (s *Session) Wait() error {
<-s.exited
return s.exitErr
}
// Signal will send a signal to the running process.
func (s *Session) Signal(sig os.Signal) {
s.command.Process.Signal(sig)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/peter_code_git/fabric.git
git@gitee.com:peter_code_git/fabric.git
peter_code_git
fabric
fabric
v2.1.1

搜索帮助