Second attempt at preventing zombies (#16326)

* Second attempt at preventing zombies

* Ensure that the pipes are closed in ssh.go
* Ensure that a cancellable context is passed up in cmd/* http requests
* Make cmd.fail return properly so defers are obeyed
* Ensure that something is sent to stdout in case of blocks here

Signed-off-by: Andrew Thornton <art27@cantab.net>

* placate lint

Signed-off-by: Andrew Thornton <art27@cantab.net>

* placate lint 2

Signed-off-by: Andrew Thornton <art27@cantab.net>

* placate lint 3

Signed-off-by: Andrew Thornton <art27@cantab.net>

* fixup

Signed-off-by: Andrew Thornton <art27@cantab.net>

* Apply suggestions from code review

Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
zeripath 2021-07-14 15:43:13 +01:00 committed by GitHub
parent ee43d70a0c
commit 3dcb3e9073
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 229 additions and 143 deletions

View file

@ -236,10 +236,13 @@ func runRemoveLogger(c *cli.Context) error {
group = log.DEFAULT
}
name := c.Args().First()
statusCode, msg := private.RemoveLogger(group, name)
ctx, cancel := installSignals()
defer cancel()
statusCode, msg := private.RemoveLogger(ctx, group, name)
switch statusCode {
case http.StatusInternalServerError:
fail("InternalServerError", msg)
return fail("InternalServerError", msg)
}
fmt.Fprintln(os.Stdout, msg)
@ -371,10 +374,13 @@ func commonAddLogger(c *cli.Context, mode string, vals map[string]interface{}) e
if c.IsSet("name") {
name = c.String("name")
}
statusCode, msg := private.AddLogger(group, name, mode, vals)
ctx, cancel := installSignals()
defer cancel()
statusCode, msg := private.AddLogger(ctx, group, name, mode, vals)
switch statusCode {
case http.StatusInternalServerError:
fail("InternalServerError", msg)
return fail("InternalServerError", msg)
}
fmt.Fprintln(os.Stdout, msg)
@ -382,11 +388,14 @@ func commonAddLogger(c *cli.Context, mode string, vals map[string]interface{}) e
}
func runShutdown(c *cli.Context) error {
ctx, cancel := installSignals()
defer cancel()
setup("manager", c.Bool("debug"))
statusCode, msg := private.Shutdown()
statusCode, msg := private.Shutdown(ctx)
switch statusCode {
case http.StatusInternalServerError:
fail("InternalServerError", msg)
return fail("InternalServerError", msg)
}
fmt.Fprintln(os.Stdout, msg)
@ -394,11 +403,14 @@ func runShutdown(c *cli.Context) error {
}
func runRestart(c *cli.Context) error {
ctx, cancel := installSignals()
defer cancel()
setup("manager", c.Bool("debug"))
statusCode, msg := private.Restart()
statusCode, msg := private.Restart(ctx)
switch statusCode {
case http.StatusInternalServerError:
fail("InternalServerError", msg)
return fail("InternalServerError", msg)
}
fmt.Fprintln(os.Stdout, msg)
@ -406,11 +418,14 @@ func runRestart(c *cli.Context) error {
}
func runFlushQueues(c *cli.Context) error {
ctx, cancel := installSignals()
defer cancel()
setup("manager", c.Bool("debug"))
statusCode, msg := private.FlushQueues(c.Duration("timeout"), c.Bool("non-blocking"))
statusCode, msg := private.FlushQueues(ctx, c.Duration("timeout"), c.Bool("non-blocking"))
switch statusCode {
case http.StatusInternalServerError:
fail("InternalServerError", msg)
return fail("InternalServerError", msg)
}
fmt.Fprintln(os.Stdout, msg)
@ -418,11 +433,14 @@ func runFlushQueues(c *cli.Context) error {
}
func runPauseLogging(c *cli.Context) error {
ctx, cancel := installSignals()
defer cancel()
setup("manager", c.Bool("debug"))
statusCode, msg := private.PauseLogging()
statusCode, msg := private.PauseLogging(ctx)
switch statusCode {
case http.StatusInternalServerError:
fail("InternalServerError", msg)
return fail("InternalServerError", msg)
}
fmt.Fprintln(os.Stdout, msg)
@ -430,11 +448,14 @@ func runPauseLogging(c *cli.Context) error {
}
func runResumeLogging(c *cli.Context) error {
ctx, cancel := installSignals()
defer cancel()
setup("manager", c.Bool("debug"))
statusCode, msg := private.ResumeLogging()
statusCode, msg := private.ResumeLogging(ctx)
switch statusCode {
case http.StatusInternalServerError:
fail("InternalServerError", msg)
return fail("InternalServerError", msg)
}
fmt.Fprintln(os.Stdout, msg)
@ -442,11 +463,14 @@ func runResumeLogging(c *cli.Context) error {
}
func runReleaseReopenLogging(c *cli.Context) error {
ctx, cancel := installSignals()
defer cancel()
setup("manager", c.Bool("debug"))
statusCode, msg := private.ReleaseReopenLogging()
statusCode, msg := private.ReleaseReopenLogging(ctx)
switch statusCode {
case http.StatusInternalServerError:
fail("InternalServerError", msg)
return fail("InternalServerError", msg)
}
fmt.Fprintln(os.Stdout, msg)