engine, lang, lib, pgraph: Plumb through more ctx
This commit is contained in:
@@ -482,7 +482,7 @@ func (obj *ExecRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
|
||||
cmdName = obj.IfShell // usually bash, or sh
|
||||
cmdArgs = []string{"-c", obj.IfCmd}
|
||||
}
|
||||
cmd := exec.Command(cmdName, cmdArgs...)
|
||||
cmd := exec.CommandContext(ctx, cmdName, cmdArgs...)
|
||||
cmd.Dir = obj.IfCwd // run program in pwd if ""
|
||||
// ignore signals sent to parent process (we're in our own group)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
@@ -563,7 +563,7 @@ func (obj *ExecRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
|
||||
cmdName = obj.NIfShell // usually bash, or sh
|
||||
cmdArgs = []string{"-c", obj.NIfCmd}
|
||||
}
|
||||
cmd := exec.Command(cmdName, cmdArgs...)
|
||||
cmd := exec.CommandContext(ctx, cmdName, cmdArgs...)
|
||||
cmd.Dir = obj.NIfCwd // run program in pwd if ""
|
||||
// ignore signals sent to parent process (we're in our own group)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
@@ -817,7 +817,7 @@ func (obj *ExecRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
|
||||
cmdName = obj.DoneShell // usually bash, or sh
|
||||
cmdArgs = []string{"-c", obj.DoneCmd}
|
||||
}
|
||||
cmd := exec.Command(cmdName, cmdArgs...)
|
||||
cmd := exec.CommandContext(ctx, cmdName, cmdArgs...)
|
||||
cmd.Dir = obj.DoneCwd // run program in pwd if ""
|
||||
// ignore signals sent to parent process (we're in our own group)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
|
||||
@@ -197,7 +197,7 @@ func (obj *GroupRes) CheckApply(ctx context.Context, apply bool) (bool, error) {
|
||||
cmdName = "groupdel"
|
||||
}
|
||||
|
||||
cmd := exec.Command(cmdName, args...)
|
||||
cmd := exec.CommandContext(ctx, cmdName, args...)
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
Setpgid: true,
|
||||
Pgid: 0,
|
||||
|
||||
@@ -661,7 +661,7 @@ func TestResources1(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Logf("test #%d: running CheckApply", index)
|
||||
checkOK, err := res.CheckApply(doneCtx, true) // no noop!
|
||||
checkOK, err := res.CheckApply(context.TODO(), true) // no noop!
|
||||
if err != nil {
|
||||
t.Errorf("test #%d: FAIL", index)
|
||||
t.Errorf("test #%d: CheckApply failed: %s", index, err.Error())
|
||||
|
||||
@@ -5624,7 +5624,7 @@ func (obj *StmtProg) SetScope(scope *interfaces.Scope) error {
|
||||
// debugging visualizations
|
||||
if obj.data.Debug && orderingGraphSingleton {
|
||||
obj.data.Logf("running graphviz for ordering graph...")
|
||||
if err := orderingGraph.ExecGraphviz("/tmp/graphviz-ordering.dot"); err != nil {
|
||||
if err := orderingGraph.ExecGraphviz(context.TODO(), "/tmp/graphviz-ordering.dot"); err != nil {
|
||||
obj.data.Logf("graphviz: errored: %+v", err)
|
||||
}
|
||||
//if err := orderingGraphFiltered.ExecGraphviz("/tmp/graphviz-ordering-filtered.dot"); err != nil {
|
||||
|
||||
@@ -961,7 +961,7 @@ func (obj *Engine) Graph() *pgraph.Graph {
|
||||
// ExecGraphviz writes out the diagram of a graph to be used for visualization
|
||||
// and debugging. You must not modify the graph (eg: during Lock) when calling
|
||||
// this method.
|
||||
func (obj *Engine) ExecGraphviz(dir string) error {
|
||||
func (obj *Engine) ExecGraphviz(ctx context.Context, dir string) error {
|
||||
// No mutex needed here since this func runs in a non-concurrent Txn.
|
||||
|
||||
// No mutex is needed at this time because we only run this in txn's and
|
||||
@@ -1019,7 +1019,7 @@ func (obj *Engine) ExecGraphviz(dir string) error {
|
||||
},
|
||||
}
|
||||
|
||||
if err := gv.Exec(); err != nil {
|
||||
if err := gv.Exec(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -567,7 +567,7 @@ func TestAstFunc1(t *testing.T) {
|
||||
}
|
||||
if runGraphviz {
|
||||
t.Logf("test #%d: Running graphviz...", index)
|
||||
if err := fgraph.ExecGraphviz("/tmp/graphviz.dot"); err != nil {
|
||||
if err := fgraph.ExecGraphviz(context.TODO(), "/tmp/graphviz.dot"); err != nil {
|
||||
t.Errorf("test #%d: FAIL", index)
|
||||
t.Errorf("test #%d: writing graph failed: %+v", index, err)
|
||||
return
|
||||
@@ -1120,7 +1120,7 @@ func TestAstFunc2(t *testing.T) {
|
||||
}
|
||||
ast.ScopeGraph(graph)
|
||||
|
||||
if err := graph.ExecGraphviz("/tmp/set-scope.dot"); err != nil {
|
||||
if err := graph.ExecGraphviz(context.TODO(), "/tmp/set-scope.dot"); err != nil {
|
||||
t.Errorf("test #%d: FAIL", index)
|
||||
t.Errorf("test #%d: writing graph failed: %+v", index, err)
|
||||
return
|
||||
@@ -1233,7 +1233,7 @@ func TestAstFunc2(t *testing.T) {
|
||||
|
||||
if runGraphviz {
|
||||
t.Logf("test #%d: Running graphviz...", index)
|
||||
if err := fgraph.ExecGraphviz("/tmp/graphviz.dot"); err != nil {
|
||||
if err := fgraph.ExecGraphviz(context.TODO(), "/tmp/graphviz.dot"); err != nil {
|
||||
t.Errorf("test #%d: FAIL", index)
|
||||
t.Errorf("test #%d: writing graph failed: %+v", index, err)
|
||||
return
|
||||
@@ -1996,7 +1996,7 @@ func TestAstFunc3(t *testing.T) {
|
||||
}
|
||||
ast.ScopeGraph(graph)
|
||||
|
||||
if err := graph.ExecGraphviz("/tmp/set-scope.dot"); err != nil {
|
||||
if err := graph.ExecGraphviz(context.TODO(), "/tmp/set-scope.dot"); err != nil {
|
||||
t.Errorf("test #%d: FAIL", index)
|
||||
t.Errorf("test #%d: writing graph failed: %+v", index, err)
|
||||
return
|
||||
@@ -2088,7 +2088,7 @@ func TestAstFunc3(t *testing.T) {
|
||||
|
||||
if runGraphviz {
|
||||
t.Logf("test #%d: Running graphviz...", index)
|
||||
if err := fgraph.ExecGraphviz("/tmp/graphviz.dot"); err != nil {
|
||||
if err := fgraph.ExecGraphviz(context.TODO(), "/tmp/graphviz.dot"); err != nil {
|
||||
t.Errorf("test #%d: FAIL", index)
|
||||
t.Errorf("test #%d: writing graph failed: %+v", index, err)
|
||||
return
|
||||
|
||||
@@ -1049,7 +1049,8 @@ func (obj *Main) Run() error {
|
||||
obj.ge.Graph(): nil,
|
||||
},
|
||||
}
|
||||
if err := gv.Exec(); err != nil {
|
||||
// FIXME: is this the right ctx?
|
||||
if err := gv.Exec(exitCtx); err != nil {
|
||||
Logf("graphviz: %+v", err)
|
||||
} else {
|
||||
Logf("graphviz: successfully generated graph!")
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
package pgraph // TODO: this should be a subpackage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"html"
|
||||
"os"
|
||||
@@ -153,7 +154,7 @@ func (obj *Graphviz) Text() string {
|
||||
|
||||
// Exec writes out the graphviz data and runs the correct graphviz filter
|
||||
// command.
|
||||
func (obj *Graphviz) Exec() error {
|
||||
func (obj *Graphviz) Exec(ctx context.Context) error {
|
||||
filter := ""
|
||||
switch obj.Filter {
|
||||
case "":
|
||||
@@ -195,7 +196,7 @@ func (obj *Graphviz) Exec() error {
|
||||
}
|
||||
|
||||
out := fmt.Sprintf("%s.png", filename)
|
||||
cmd := exec.Command(path, "-Tpng", fmt.Sprintf("-o%s", out), filename)
|
||||
cmd := exec.CommandContext(ctx, path, "-Tpng", fmt.Sprintf("-o%s", out), filename)
|
||||
|
||||
if err1 == nil && err2 == nil {
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{}
|
||||
@@ -286,7 +287,7 @@ func (obj *Graph) Graphviz() string {
|
||||
|
||||
// ExecGraphviz writes out the graphviz data and runs the correct graphviz
|
||||
// filter command.
|
||||
func (obj *Graph) ExecGraphviz(filename string) error {
|
||||
func (obj *Graph) ExecGraphviz(ctx context.Context, filename string) error {
|
||||
gv := &Graphviz{
|
||||
Graphs: map[*Graph]*GraphvizOpts{
|
||||
obj: nil,
|
||||
@@ -296,5 +297,5 @@ func (obj *Graph) ExecGraphviz(filename string) error {
|
||||
Filename: filename,
|
||||
//Hostname: hostname,
|
||||
}
|
||||
return gv.Exec()
|
||||
return gv.Exec(ctx)
|
||||
}
|
||||
|
||||
@@ -485,7 +485,7 @@ func TestTopoSort3(t *testing.T) {
|
||||
G.AddEdge(v5, v6, e5)
|
||||
G.AddEdge(v4, v2, e6) // cycle
|
||||
|
||||
G.ExecGraphviz("/tmp/g.dot")
|
||||
//G.ExecGraphviz(context.TODO(), "/tmp/g.dot")
|
||||
|
||||
_, err := G.TopologicalSort()
|
||||
if err == nil {
|
||||
|
||||
Reference in New Issue
Block a user