[lxc-devel] [lxd/master] Bugfixes

stgraber on Github lxc-bot at linuxcontainers.org
Fri Apr 28 17:21:24 UTC 2017


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170428/ea5a748b/attachment.bin>
-------------- next part --------------
From 3a551bf31c922e49538bf36e750f516184d5deec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 28 Apr 2017 12:48:18 -0400
Subject: [PATCH 1/8] Fix typos
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 client/operations.go  | 2 +-
 lxd/container_exec.go | 2 +-
 lxd/patches.go        | 2 +-
 lxd/storage_btrfs.go  | 6 ++----
 test/README.md        | 2 +-
 5 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/client/operations.go b/client/operations.go
index cd958fb..7f381a0 100644
--- a/client/operations.go
+++ b/client/operations.go
@@ -147,7 +147,7 @@ func (op *Operation) setupListener() error {
 			return
 		}
 
-		// We don't want concurency while processing events
+		// We don't want concurrency while processing events
 		op.listenerLock.Lock()
 		defer op.listenerLock.Unlock()
 
diff --git a/lxd/container_exec.go b/lxd/container_exec.go
index 98d4a31..9c43590 100644
--- a/lxd/container_exec.go
+++ b/lxd/container_exec.go
@@ -171,7 +171,7 @@ func (s *execWs) Do(op *operation) error {
 						break
 					}
 
-					// If an abnormal closure occured, kill the attached process.
+					// If an abnormal closure occurred, kill the attached process.
 					err := syscall.Kill(attachedChildPid, syscall.SIGKILL)
 					if err != nil {
 						logger.Debugf("Failed to send SIGKILL to pid %d.", attachedChildPid)
diff --git a/lxd/patches.go b/lxd/patches.go
index 23dfa7c..2dfa6f4 100644
--- a/lxd/patches.go
+++ b/lxd/patches.go
@@ -1236,7 +1236,7 @@ func upgradeFromStorageTypeLvm(name string, d *Daemon, defaultPoolName string, d
 			newSnapshotsPath := getSnapshotMountPoint(defaultPoolName, ct)
 			if shared.PathExists(snapshotsPath) {
 				// On a broken update snapshotsPath will contain
-				// emtpy directories that need to be removed.
+				// empty directories that need to be removed.
 				err := os.RemoveAll(snapshotsPath)
 				if err != nil {
 					return err
diff --git a/lxd/storage_btrfs.go b/lxd/storage_btrfs.go
index 15ff9c3..56f2d25 100644
--- a/lxd/storage_btrfs.go
+++ b/lxd/storage_btrfs.go
@@ -757,8 +757,7 @@ func (s *storageBtrfs) copyContainer(target container, source container) error {
 	targetContainerSubvolumeName := getContainerMountPoint(s.pool.Name, target.Name())
 
 	containersPath := getContainerMountPoint(s.pool.Name, "")
-	// Ensure that the directories immediately preceeding the
-	// subvolume directory exist.
+	// Ensure that the directories immediately preceding the subvolume directory exist.
 	if !shared.PathExists(containersPath) {
 		err := os.MkdirAll(containersPath, 0700)
 		if err != nil {
@@ -805,8 +804,7 @@ func (s *storageBtrfs) copySnapshot(target container, source container) error {
 		return err
 	}
 
-	// Ensure that the directories immediately preceeding the
-	// subvolume directory exist.
+	// Ensure that the directories immediately preceding the subvolume directory exist.
 	if !shared.PathExists(containersPath) {
 		err := os.MkdirAll(containersPath, 0700)
 		if err != nil {
diff --git a/test/README.md b/test/README.md
index 3c543b6..5d0e285 100644
--- a/test/README.md
+++ b/test/README.md
@@ -13,7 +13,7 @@ To run only the integration tests, run from the test directory:
 Name                            | Default                   | Description
 :--                             | :---                      | :----------
 LXD\_BACKEND                    | dir                       | What backend to test against (btrfs, dir, lvm, zfs, or random)
-LXD\_CONCURRENT                 | 0                         | Run concurency tests, very CPU intensive
+LXD\_CONCURRENT                 | 0                         | Run concurrency tests, very CPU intensive
 LXD\_DEBUG                      | 0                         | Run lxd, lxc and the shell in debug mode (very verbose)
 LXD\_INSPECT                    | 0                         | Don't teardown the test environment on failure
 LXD\_LOGS                       | ""                        | Path to a directory to copy all the LXD logs to

From 1b65db0982872a2fa9ac9aa66530e91249eb79f5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 28 Apr 2017 12:49:22 -0400
Subject: [PATCH 2/8] lxc/storage: Don't ignore yaml errors
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxc/storage.go | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lxc/storage.go b/lxc/storage.go
index 365ca5d..0899c2e 100644
--- a/lxc/storage.go
+++ b/lxc/storage.go
@@ -656,6 +656,10 @@ func (c *storageCmd) doStoragePoolShow(client *lxd.Client, name string) error {
 	sort.Strings(pool.UsedBy)
 
 	data, err := yaml.Marshal(&pool)
+	if err != nil {
+		return err
+	}
+
 	fmt.Printf("%s", data)
 
 	return nil
@@ -786,6 +790,10 @@ func (c *storageCmd) doStoragePoolVolumeShow(client *lxd.Client, pool string, vo
 	sort.Strings(volumeStruct.UsedBy)
 
 	data, err := yaml.Marshal(&volumeStruct)
+	if err != nil {
+		return err
+	}
+
 	fmt.Printf("%s", data)
 
 	return nil

From a1158a873a22882193aba2c2c87b80044eff1931 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 28 Apr 2017 12:50:14 -0400
Subject: [PATCH 3/8] lxd/patches: Drop unused variable
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/patches.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/patches.go b/lxd/patches.go
index 2dfa6f4..7bf8abc 100644
--- a/lxd/patches.go
+++ b/lxd/patches.go
@@ -1789,7 +1789,7 @@ func updatePoolPropertyForAllObjects(d *Daemon, poolName string, allcontainers [
 
 		// Look for a local root device entry
 		localDevices := c.LocalDevices()
-		k, d, _ = containerGetRootDiskDevice(localDevices)
+		k, _, _ = containerGetRootDiskDevice(localDevices)
 		if k != "" {
 			localDevices[k]["pool"] = poolName
 			args.Devices = localDevices

From b2aba905ad36186b6e709e80ea767d0c84631a59 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 28 Apr 2017 12:58:03 -0400
Subject: [PATCH 4/8] shared/logging: Make golint clean
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 shared/logging/format.go       | 2 +-
 shared/logging/log.go          | 3 ++-
 shared/logging/log_posix.go    | 4 ++--
 test/suites/static_analysis.sh | 1 +
 4 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/shared/logging/format.go b/shared/logging/format.go
index 083d40e..93ddda6 100644
--- a/shared/logging/format.go
+++ b/shared/logging/format.go
@@ -67,7 +67,7 @@ func TerminalFormat() log.Format {
 	})
 }
 
-func LogfmtFormat() log.Format {
+func logfmtFormat() log.Format {
 	return log.FormatFunc(func(r *log.Record) []byte {
 		common := []interface{}{r.KeyNames.Time, r.Time, r.KeyNames.Lvl, r.Lvl, r.KeyNames.Msg, r.Msg}
 		buf := &bytes.Buffer{}
diff --git a/shared/logging/log.go b/shared/logging/log.go
index 15b8ac9..8d6bf2a 100644
--- a/shared/logging/log.go
+++ b/shared/logging/log.go
@@ -19,7 +19,7 @@ func GetLogger(syslog string, logfile string, verbose bool, debug bool, customHa
 	var syshandler log.Handler
 
 	// Format handler
-	format := LogfmtFormat()
+	format := logfmtFormat()
 	if term.IsTty(os.Stderr.Fd()) {
 		format = TerminalFormat()
 	}
@@ -81,6 +81,7 @@ func GetLogger(syslog string, logfile string, verbose bool, debug bool, customHa
 	return Log, nil
 }
 
+// AddContext will return a copy of the logger with extra context added
 func AddContext(logger logger.Logger, ctx log.Ctx) logger.Logger {
 	log15logger, ok := logger.(log.Logger)
 	if !ok {
diff --git a/shared/logging/log_posix.go b/shared/logging/log_posix.go
index 7cdbfd9..ffc55da 100644
--- a/shared/logging/log_posix.go
+++ b/shared/logging/log_posix.go
@@ -15,9 +15,9 @@ func getSystemHandler(syslog string, debug bool, format log.Format) log.Handler
 				log.LvlInfo,
 				log.Must.SyslogHandler(syslog, format),
 			)
-		} else {
-			return log.Must.SyslogHandler(syslog, format)
 		}
+
+		return log.Must.SyslogHandler(syslog, format)
 	}
 
 	return nil
diff --git a/test/suites/static_analysis.sh b/test/suites/static_analysis.sh
index fbeeff5..b07d1f8 100644
--- a/test/suites/static_analysis.sh
+++ b/test/suites/static_analysis.sh
@@ -48,6 +48,7 @@ test_static_analysis() {
       golint -set_exit_status shared/gnuflag/
       golint -set_exit_status shared/i18n/
       golint -set_exit_status shared/ioprogress/
+      golint -set_exit_status shared/logging/
       golint -set_exit_status shared/version/
     fi
 

From 9b9fc99a8d539281ba5b1dafa4ae09a5e4acdfa9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 28 Apr 2017 13:04:49 -0400
Subject: [PATCH 5/8] shared/logger: Make golint clean
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 shared/logger/format.go        |  3 ++-
 shared/logger/log.go           | 16 +++++++++++++---
 test/suites/static_analysis.sh |  1 +
 3 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/shared/logger/format.go b/shared/logger/format.go
index 16f2e83..df6d86f 100644
--- a/shared/logger/format.go
+++ b/shared/logger/format.go
@@ -5,10 +5,11 @@ import (
 	"fmt"
 )
 
+// Pretty will attempt to convert any Go structure into a string suitable for logging
 func Pretty(input interface{}) string {
 	pretty, err := json.MarshalIndent(input, "\t", "\t")
 	if err != nil {
-		return fmt.Sprintf("%s", input)
+		return fmt.Sprintf("%v", input)
 	}
 
 	return fmt.Sprintf("\n\t%s", pretty)
diff --git a/shared/logger/log.go b/shared/logger/log.go
index 60148d4..8e737a3 100644
--- a/shared/logger/log.go
+++ b/shared/logger/log.go
@@ -7,6 +7,7 @@ import (
 	"runtime"
 )
 
+// Logger is the main logging interface
 type Logger interface {
 	Debug(msg string, ctx ...interface{})
 	Info(msg string, ctx ...interface{})
@@ -15,6 +16,7 @@ type Logger interface {
 	Crit(msg string, ctx ...interface{})
 }
 
+// Log contains the logger used by all the logging functions
 var Log Logger
 
 type nullLogger struct{}
@@ -29,69 +31,77 @@ func init() {
 	Log = nullLogger{}
 }
 
-// General wrappers around Logger interface functions.
+// Debug logs a message (with optional context) at the DEBUG log level
 func Debug(msg string, ctx ...interface{}) {
 	if Log != nil {
 		Log.Debug(msg, ctx...)
 	}
 }
 
+// Info logs a message (with optional context) at the INFO log level
 func Info(msg string, ctx ...interface{}) {
 	if Log != nil {
 		Log.Info(msg, ctx...)
 	}
 }
 
+// Warn logs a message (with optional context) at the WARNING log level
 func Warn(msg string, ctx ...interface{}) {
 	if Log != nil {
 		Log.Warn(msg, ctx...)
 	}
 }
 
+// Error logs a message (with optional context) at the ERROR log level
 func Error(msg string, ctx ...interface{}) {
 	if Log != nil {
 		Log.Error(msg, ctx...)
 	}
 }
 
+// Crit logs a message (with optional context) at the CRITICAL log level
 func Crit(msg string, ctx ...interface{}) {
 	if Log != nil {
 		Log.Crit(msg, ctx...)
 	}
 }
 
-// Wrappers around Logger interface functions that send a string to the Logger
-// by running it through fmt.Sprintf().
+// Infof logs at the INFO log level using a standard printf format string
 func Infof(format string, args ...interface{}) {
 	if Log != nil {
 		Log.Info(fmt.Sprintf(format, args...))
 	}
 }
 
+// Debugf logs at the DEBUG log level using a standard printf format string
 func Debugf(format string, args ...interface{}) {
 	if Log != nil {
 		Log.Debug(fmt.Sprintf(format, args...))
 	}
 }
 
+// Warnf logs at the WARNING log level using a standard printf format string
 func Warnf(format string, args ...interface{}) {
 	if Log != nil {
 		Log.Warn(fmt.Sprintf(format, args...))
 	}
 }
 
+// Errorf logs at the ERROR log level using a standard printf format string
 func Errorf(format string, args ...interface{}) {
 	if Log != nil {
 		Log.Error(fmt.Sprintf(format, args...))
 	}
 }
 
+// Critf logs at the CRITICAL log level using a standard printf format string
 func Critf(format string, args ...interface{}) {
 	if Log != nil {
 		Log.Crit(fmt.Sprintf(format, args...))
 	}
 }
 
+// PrintStack logs the current Go stack at the ERROR log level
 func PrintStack() {
 	buf := make([]byte, 1<<16)
 	runtime.Stack(buf, true)
diff --git a/test/suites/static_analysis.sh b/test/suites/static_analysis.sh
index b07d1f8..5074ded 100644
--- a/test/suites/static_analysis.sh
+++ b/test/suites/static_analysis.sh
@@ -48,6 +48,7 @@ test_static_analysis() {
       golint -set_exit_status shared/gnuflag/
       golint -set_exit_status shared/i18n/
       golint -set_exit_status shared/ioprogress/
+      golint -set_exit_status shared/logger/
       golint -set_exit_status shared/logging/
       golint -set_exit_status shared/version/
     fi

From ead86fd2bc11a1b950ad1cc914f186cc771265c3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 28 Apr 2017 13:08:59 -0400
Subject: [PATCH 6/8] shared/logger: Replace PrintStack with GetStack
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/containers_get.go   |  2 +-
 lxd/db.go               | 12 ++++++------
 lxd/main_daemon.go      |  2 +-
 shared/logger/format.go |  9 +++++++++
 shared/logger/log.go    |  8 --------
 5 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/lxd/containers_get.go b/lxd/containers_get.go
index 7255345..49ce463 100644
--- a/lxd/containers_get.go
+++ b/lxd/containers_get.go
@@ -26,7 +26,7 @@ func containersGet(d *Daemon, r *http.Request) Response {
 	}
 
 	logger.Debugf("DBERR: containersGet, db is locked")
-	logger.PrintStack()
+	logger.Debugf(logger.GetStack())
 	return InternalError(fmt.Errorf("DB is locked"))
 }
 
diff --git a/lxd/db.go b/lxd/db.go
index 923c293..73216c6 100644
--- a/lxd/db.go
+++ b/lxd/db.go
@@ -345,7 +345,7 @@ func dbBegin(db *sql.DB) (*sql.Tx, error) {
 	}
 
 	logger.Debugf("DbBegin: DB still locked")
-	logger.PrintStack()
+	logger.Debugf(logger.GetStack())
 	return nil, fmt.Errorf("DB is locked")
 }
 
@@ -363,7 +363,7 @@ func txCommit(tx *sql.Tx) error {
 	}
 
 	logger.Debugf("Txcommit: db still locked")
-	logger.PrintStack()
+	logger.Debugf(logger.GetStack())
 	return fmt.Errorf("DB is locked")
 }
 
@@ -383,7 +383,7 @@ func dbQueryRowScan(db *sql.DB, q string, args []interface{}, outargs []interfac
 	}
 
 	logger.Debugf("DbQueryRowScan: query %q args %q, DB still locked", q, args)
-	logger.PrintStack()
+	logger.Debugf(logger.GetStack())
 	return fmt.Errorf("DB is locked")
 }
 
@@ -401,7 +401,7 @@ func dbQuery(db *sql.DB, q string, args ...interface{}) (*sql.Rows, error) {
 	}
 
 	logger.Debugf("DbQuery: query %q args %q, DB still locked", q, args)
-	logger.PrintStack()
+	logger.Debugf(logger.GetStack())
 	return nil, fmt.Errorf("DB is locked")
 }
 
@@ -481,7 +481,7 @@ func dbQueryScan(db *sql.DB, q string, inargs []interface{}, outfmt []interface{
 	}
 
 	logger.Debugf("DbQueryscan: query %q inargs %q, DB still locked", q, inargs)
-	logger.PrintStack()
+	logger.Debugf(logger.GetStack())
 	return nil, fmt.Errorf("DB is locked")
 }
 
@@ -499,6 +499,6 @@ func dbExec(db *sql.DB, q string, args ...interface{}) (sql.Result, error) {
 	}
 
 	logger.Debugf("DbExec: query %q args %q, DB still locked", q, args)
-	logger.PrintStack()
+	logger.Debugf(logger.GetStack())
 	return nil, fmt.Errorf("DB is locked")
 }
diff --git a/lxd/main_daemon.go b/lxd/main_daemon.go
index 0d7851f..e78db8f 100644
--- a/lxd/main_daemon.go
+++ b/lxd/main_daemon.go
@@ -46,7 +46,7 @@ func cmdDaemon() error {
 		go func() {
 			for {
 				time.Sleep(time.Duration(*argPrintGoroutinesEvery) * time.Second)
-				logger.PrintStack()
+				logger.Debugf(logger.GetStack())
 			}
 		}()
 	}
diff --git a/shared/logger/format.go b/shared/logger/format.go
index df6d86f..ddb0321 100644
--- a/shared/logger/format.go
+++ b/shared/logger/format.go
@@ -3,6 +3,7 @@ package logger
 import (
 	"encoding/json"
 	"fmt"
+	"runtime"
 )
 
 // Pretty will attempt to convert any Go structure into a string suitable for logging
@@ -14,3 +15,11 @@ func Pretty(input interface{}) string {
 
 	return fmt.Sprintf("\n\t%s", pretty)
 }
+
+// GetStack will convert the Go stack into a string suitable for logging
+func GetStack() string {
+	buf := make([]byte, 1<<16)
+	runtime.Stack(buf, true)
+
+	return fmt.Sprintf("\n\t%s", buf)
+}
diff --git a/shared/logger/log.go b/shared/logger/log.go
index 8e737a3..a031d8c 100644
--- a/shared/logger/log.go
+++ b/shared/logger/log.go
@@ -4,7 +4,6 @@ package logger
 
 import (
 	"fmt"
-	"runtime"
 )
 
 // Logger is the main logging interface
@@ -100,10 +99,3 @@ func Critf(format string, args ...interface{}) {
 		Log.Crit(fmt.Sprintf(format, args...))
 	}
 }
-
-// PrintStack logs the current Go stack at the ERROR log level
-func PrintStack() {
-	buf := make([]byte, 1<<16)
-	runtime.Stack(buf, true)
-	Errorf("%s", buf)
-}

From 7a0fa1340ae7c881f16c1307462baad9bf3f76d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 28 Apr 2017 13:11:44 -0400
Subject: [PATCH 7/8] test/deps: Make golint clean
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 test/deps/devlxd-client.go     | 13 +++++++------
 test/suites/static_analysis.sh |  1 +
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/test/deps/devlxd-client.go b/test/deps/devlxd-client.go
index 83399bd..f88f4a7 100644
--- a/test/deps/devlxd-client.go
+++ b/test/deps/devlxd-client.go
@@ -1,8 +1,9 @@
+package main
+
 /*
  * An example of how to use lxd's golang /dev/lxd client. This is intended to
  * be run from inside a container.
  */
-package main
 
 import (
 	"encoding/json"
@@ -13,11 +14,11 @@ import (
 	"os"
 )
 
-type DevLxdDialer struct {
+type devLxdDialer struct {
 	Path string
 }
 
-func (d DevLxdDialer) DevLxdDial(network, path string) (net.Conn, error) {
+func (d devLxdDialer) devLxdDial(network, path string) (net.Conn, error) {
 	addr, err := net.ResolveUnixAddr("unix", d.Path)
 	if err != nil {
 		return nil, err
@@ -31,12 +32,12 @@ func (d DevLxdDialer) DevLxdDial(network, path string) (net.Conn, error) {
 	return conn, err
 }
 
-var DevLxdTransport = &http.Transport{
-	Dial: DevLxdDialer{"/dev/lxd/sock"}.DevLxdDial,
+var devLxdTransport = &http.Transport{
+	Dial: devLxdDialer{"/dev/lxd/sock"}.devLxdDial,
 }
 
 func main() {
-	c := http.Client{Transport: DevLxdTransport}
+	c := http.Client{Transport: devLxdTransport}
 	raw, err := c.Get("http://meshuggah-rocks/")
 	if err != nil {
 		fmt.Println(err)
diff --git a/test/suites/static_analysis.sh b/test/suites/static_analysis.sh
index 5074ded..5140f72 100644
--- a/test/suites/static_analysis.sh
+++ b/test/suites/static_analysis.sh
@@ -51,6 +51,7 @@ test_static_analysis() {
       golint -set_exit_status shared/logger/
       golint -set_exit_status shared/logging/
       golint -set_exit_status shared/version/
+      golint -set_exit_status test/deps/
     fi
 
     ## deadcode

From 7548b478096808bb25e470078c0bc6b3b7777020 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 28 Apr 2017 13:18:15 -0400
Subject: [PATCH 8/8] shared/termios: Make golint clean
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 shared/termios/termios.go         | 6 ++++++
 shared/termios/termios_windows.go | 6 ++++++
 test/suites/static_analysis.sh    | 1 +
 3 files changed, 13 insertions(+)

diff --git a/shared/termios/termios.go b/shared/termios/termios.go
index 4004bff..1b841c7 100644
--- a/shared/termios/termios.go
+++ b/shared/termios/termios.go
@@ -12,15 +12,18 @@ import (
 // #include <termios.h>
 import "C"
 
+// State contains the state of a terminal.
 type State struct {
 	Termios syscall.Termios
 }
 
+// IsTerminal returns true if the given file descriptor is a terminal.
 func IsTerminal(fd int) bool {
 	_, err := GetState(fd)
 	return err == nil
 }
 
+// GetState returns the current state of a terminal which may be useful to restore the terminal after a signal.
 func GetState(fd int) (*State, error) {
 	termios := syscall.Termios{}
 
@@ -35,6 +38,7 @@ func GetState(fd int) (*State, error) {
 	return &state, nil
 }
 
+// GetSize returns the dimensions of the given terminal.
 func GetSize(fd int) (int, int, error) {
 	var dimensions [4]uint16
 
@@ -45,6 +49,7 @@ func GetSize(fd int) (int, int, error) {
 	return int(dimensions[1]), int(dimensions[0]), nil
 }
 
+// MakeRaw put the terminal connected to the given file descriptor into raw mode and returns the previous state of the terminal so that it can be restored.
 func MakeRaw(fd int) (*State, error) {
 	var err error
 	var oldState, newState *State
@@ -69,6 +74,7 @@ func MakeRaw(fd int) (*State, error) {
 	return oldState, nil
 }
 
+// Restore restores the terminal connected to the given file descriptor to a previous state.
 func Restore(fd int, state *State) error {
 	ret, err := C.tcsetattr(C.int(fd), C.TCSANOW, (*C.struct_termios)(unsafe.Pointer(&state.Termios)))
 	if ret != 0 {
diff --git a/shared/termios/termios_windows.go b/shared/termios/termios_windows.go
index 9d0b576..64c8b1a 100644
--- a/shared/termios/termios_windows.go
+++ b/shared/termios/termios_windows.go
@@ -6,12 +6,15 @@ import (
 	"golang.org/x/crypto/ssh/terminal"
 )
 
+// State contains the state of a terminal.
 type State terminal.State
 
+// IsTerminal returns true if the given file descriptor is a terminal.
 func IsTerminal(fd int) bool {
 	return terminal.IsTerminal(fd)
 }
 
+// GetState returns the current state of a terminal which may be useful to restore the terminal after a signal.
 func GetState(fd int) (*State, error) {
 	state, err := terminal.GetState(fd)
 	if err != nil {
@@ -22,10 +25,12 @@ func GetState(fd int) (*State, error) {
 	return &currentState, nil
 }
 
+// GetSize returns the dimensions of the given terminal.
 func GetSize(fd int) (int, int, error) {
 	return terminal.GetSize(fd)
 }
 
+// MakeRaw put the terminal connected to the given file descriptor into raw mode and returns the previous state of the terminal so that it can be restored.
 func MakeRaw(fd int) (*State, error) {
 	state, err := terminal.MakeRaw(fd)
 	if err != nil {
@@ -36,6 +41,7 @@ func MakeRaw(fd int) (*State, error) {
 	return &oldState, nil
 }
 
+// Restore restores the terminal connected to the given file descriptor to a previous state.
 func Restore(fd int, state *State) error {
 	newState := terminal.State(*state)
 
diff --git a/test/suites/static_analysis.sh b/test/suites/static_analysis.sh
index 5140f72..8d02c63 100644
--- a/test/suites/static_analysis.sh
+++ b/test/suites/static_analysis.sh
@@ -50,6 +50,7 @@ test_static_analysis() {
       golint -set_exit_status shared/ioprogress/
       golint -set_exit_status shared/logger/
       golint -set_exit_status shared/logging/
+      golint -set_exit_status shared/termios/
       golint -set_exit_status shared/version/
       golint -set_exit_status test/deps/
     fi


More information about the lxc-devel mailing list