-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shimdiag flag to find shim process ID for shims
* Adds a new -pids flag to the `shimdiag list` command that will print out the process ID of the shim executable. Sample output: PS C:\> shimdiag.exe list -pids Shim Pid k8s.io-3719754aab39925924b0beb27d2a195a4a6784c6ebe3690b81b2e7274a7021af 65892 k8s.io-908ea3697874891fd5814b1967515d3214257b65fc1974bdafd17276ee8ba3e5 69444 Signed-off-by: Daniel Canter <[email protected]>
- Loading branch information
Showing
4 changed files
with
422 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,69 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"text/tabwriter" | ||
|
||
"github.com/Microsoft/hcsshim/internal/appargs" | ||
"github.com/Microsoft/hcsshim/internal/shimdiag" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
var listCommand = cli.Command{ | ||
Name: "list", | ||
Usage: "Lists running shims", | ||
ArgsUsage: " ", | ||
Before: appargs.Validate(), | ||
Flags: []cli.Flag{ | ||
cli.BoolFlag{ | ||
Name: "pids", | ||
Usage: "Shows the process IDs of each shim", | ||
}, | ||
}, | ||
Before: appargs.Validate(), | ||
Action: func(ctx *cli.Context) error { | ||
pids := ctx.Bool("pids") | ||
shims, err := findShims("") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
getPid := func(shimStr string) (int32, error) { | ||
shim, err := getShim(shimStr) | ||
if err != nil { | ||
return 0, err | ||
} | ||
defer shim.Close() | ||
|
||
svc := shimdiag.NewShimDiagClient(shim) | ||
resp, err := svc.DiagPid(context.Background(), &shimdiag.PidRequest{}) | ||
if err != nil { | ||
return 0, err | ||
} | ||
return resp.Pid, nil | ||
} | ||
|
||
w := new(tabwriter.Writer) | ||
w.Init(os.Stdout, 0, 8, 0, '\t', 0) | ||
|
||
if pids { | ||
fmt.Fprintln(w, "Shim \t Pid") | ||
} | ||
|
||
for _, shim := range shims { | ||
fmt.Println(shim) | ||
output := shim | ||
if pids { | ||
pid, err := getPid(shim) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Fprintf(w, "%s \t %d\n", output, pid) | ||
} else { | ||
fmt.Println(shim) | ||
} | ||
} | ||
w.Flush() | ||
return nil | ||
}, | ||
} |
Oops, something went wrong.