[lxc-devel] [distrobuilder/master] main: Add --timeout flag
monstermunchkin on Github
lxc-bot at linuxcontainers.org
Wed Mar 6 19:27:39 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 387 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190306/ad512e64/attachment.bin>
-------------- next part --------------
From 795fd7178f5de8950bc70b1b15819b5f09d42594 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Wed, 6 Mar 2019 20:25:14 +0100
Subject: [PATCH] main: Add --timeout flag
Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
distrobuilder/main.go | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/distrobuilder/main.go b/distrobuilder/main.go
index a2b96a2..2761737 100644
--- a/distrobuilder/main.go
+++ b/distrobuilder/main.go
@@ -61,6 +61,7 @@ import (
"os"
"path/filepath"
"strings"
+ "time"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"
@@ -73,6 +74,7 @@ type cmdGlobal struct {
flagCleanup bool
flagCacheDir string
flagOptions []string
+ flagTimeout uint
definition *shared.Definition
sourceDir string
@@ -113,6 +115,8 @@ func main() {
"", "Cache directory"+"``")
app.PersistentFlags().StringSliceVarP(&globalCmd.flagOptions, "options", "o",
[]string{}, "Override options (list of key=value)"+"``")
+ app.PersistentFlags().UintVarP(&globalCmd.flagTimeout, "timeout", "t", 0,
+ "Timeout in seconds"+"``")
// LXC sub-commands
LXCCmd := cmdLXC{global: &globalCmd}
@@ -128,6 +132,18 @@ func main() {
buildDirCmd := cmdBuildDir{global: &globalCmd}
app.AddCommand(buildDirCmd.command())
+ // Timeout handler
+ go func() {
+ // No timeout set
+ if globalCmd.flagTimeout == 0 {
+ return
+ }
+
+ time.Sleep(time.Duration(globalCmd.flagTimeout) * time.Second)
+ fmt.Println("Timed out")
+ os.Exit(1)
+ }()
+
// Run the main command and handle errors
err := app.Execute()
if err != nil {
More information about the lxc-devel
mailing list