diff options
| author | Taras Madan <tarasmadan@google.com> | 2022-09-26 09:23:11 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-26 09:23:11 +0200 |
| commit | d59ba98314e02be939938f682fd67cd68bbb3b68 (patch) | |
| tree | 27a44d1d8315577110c0c9e09fb825a386b6255b /vm/proxyapp/init.go | |
| parent | 0042f2b4c00ce1ceeaa44a0147909fe3a6f86c5c (diff) | |
vm: add the proxyapp support (#3269)
* vm: add pool.Close() support
* vm: add proxyapp client implementation
* vm/proxyapp: autogenerate mocks
* vm/proxyapp: add proxyapp tests
* pkg/mgrconfig: add proxyapp type tests
Diffstat (limited to 'vm/proxyapp/init.go')
| -rw-r--r-- | vm/proxyapp/init.go | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/vm/proxyapp/init.go b/vm/proxyapp/init.go new file mode 100644 index 000000000..17db527f9 --- /dev/null +++ b/vm/proxyapp/init.go @@ -0,0 +1,63 @@ +// Copyright 2022 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +package proxyapp + +import ( + "context" + "encoding/json" + "fmt" + "io" + "time" + + "github.com/google/syzkaller/pkg/config" + "github.com/google/syzkaller/pkg/osutil" + "github.com/google/syzkaller/vm/vmimpl" +) + +func makeDefaultParams() *proxyAppParams { + return &proxyAppParams{ + CommandRunner: osutilCommandContext, + InitRetryDelay: 10 * time.Second, + } +} + +func init() { + vmimpl.Register( + "proxyapp", + func(env *vmimpl.Env) (vmimpl.Pool, error) { + return ctor(makeDefaultParams(), env) + }, + false) +} + +// Package configuration VARs are mostly needed for tests. +type proxyAppParams struct { + CommandRunner func(context.Context, string, ...string) subProcessCmd + InitRetryDelay time.Duration +} + +func osutilCommandContext(ctx context.Context, bin string, args ...string) subProcessCmd { + return osutil.CommandContext(ctx, bin, args...) +} + +type subProcessCmd interface { + StdinPipe() (io.WriteCloser, error) + StdoutPipe() (io.ReadCloser, error) + StderrPipe() (io.ReadCloser, error) + Start() error + Wait() error +} + +type Config struct { + Command string `json:"cmd"` + ProxyAppConfig json.RawMessage `json:"config"` +} + +func parseConfig(conf []byte) (*Config, error) { + vmCfg := new(Config) + if err := config.LoadData(conf, vmCfg); err != nil { + return nil, fmt.Errorf("failed to parseConfig(): %w", err) + } + return vmCfg, nil +} |
