full diff: https://github.com/creack/pty/compare/v1.1.9...v1.1.11
- v1.1.11: Add arm support for OpenBSD
- v1.1.10: Fix CTTY to work with go1.15
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
... | ... |
@@ -16,7 +16,7 @@ github.com/moby/term 7f0af18e79f2784809e9cef63d0d |
16 | 16 |
# could be either `mountinfo/vX.Y.Z` or `mount/vX.Y.Z`. |
17 | 17 |
github.com/moby/sys 9a75fe61baf4b9788826b48b0518abecffb79b16 # mountinfo v0.4.0 |
18 | 18 |
|
19 |
-github.com/creack/pty 3a6a957789163cacdfe0e291617a1c8e80612c11 # v1.1.9 |
|
19 |
+github.com/creack/pty 2a38352e8b4d7ab6c336eef107e42a55e72e7fbc # v1.1.11 |
|
20 | 20 |
github.com/sirupsen/logrus 6699a89a232f3db797f2e280639854bbc4b89725 # v1.7.0 |
21 | 21 |
github.com/tchap/go-patricia a7f0089c6f496e8e70402f61733606daa326cac5 # v2.3.0 |
22 | 22 |
golang.org/x/net ab34263943818b32f575efc978a3d24e80b04bd7 |
... | ... |
@@ -11,6 +11,8 @@ import ( |
11 | 11 |
// Start assigns a pseudo-terminal tty os.File to c.Stdin, c.Stdout, |
12 | 12 |
// and c.Stderr, calls c.Start, and returns the File of the tty's |
13 | 13 |
// corresponding pty. |
14 |
+// |
|
15 |
+// Starts the process in a new session and sets the controlling terminal. |
|
14 | 16 |
func Start(c *exec.Cmd) (pty *os.File, err error) { |
15 | 17 |
return StartWithSize(c, nil) |
16 | 18 |
} |
... | ... |
@@ -19,16 +21,35 @@ func Start(c *exec.Cmd) (pty *os.File, err error) { |
19 | 19 |
// and c.Stderr, calls c.Start, and returns the File of the tty's |
20 | 20 |
// corresponding pty. |
21 | 21 |
// |
22 |
-// This will resize the pty to the specified size before starting the command |
|
22 |
+// This will resize the pty to the specified size before starting the command. |
|
23 |
+// Starts the process in a new session and sets the controlling terminal. |
|
23 | 24 |
func StartWithSize(c *exec.Cmd, sz *Winsize) (pty *os.File, err error) { |
25 |
+ if c.SysProcAttr == nil { |
|
26 |
+ c.SysProcAttr = &syscall.SysProcAttr{} |
|
27 |
+ } |
|
28 |
+ c.SysProcAttr.Setsid = true |
|
29 |
+ c.SysProcAttr.Setctty = true |
|
30 |
+ return StartWithAttrs(c, sz, c.SysProcAttr) |
|
31 |
+} |
|
32 |
+ |
|
33 |
+// StartWithAttrs assigns a pseudo-terminal tty os.File to c.Stdin, c.Stdout, |
|
34 |
+// and c.Stderr, calls c.Start, and returns the File of the tty's |
|
35 |
+// corresponding pty. |
|
36 |
+// |
|
37 |
+// This will resize the pty to the specified size before starting the command if a size is provided. |
|
38 |
+// The `attrs` parameter overrides the one set in c.SysProcAttr. |
|
39 |
+// |
|
40 |
+// This should generally not be needed. Used in some edge cases where it is needed to create a pty |
|
41 |
+// without a controlling terminal. |
|
42 |
+func StartWithAttrs(c *exec.Cmd, sz *Winsize, attrs *syscall.SysProcAttr) (pty *os.File, err error) { |
|
24 | 43 |
pty, tty, err := Open() |
25 | 44 |
if err != nil { |
26 | 45 |
return nil, err |
27 | 46 |
} |
28 | 47 |
defer tty.Close() |
48 |
+ |
|
29 | 49 |
if sz != nil { |
30 |
- err = Setsize(pty, sz) |
|
31 |
- if err != nil { |
|
50 |
+ if err := Setsize(pty, sz); err != nil { |
|
32 | 51 |
pty.Close() |
33 | 52 |
return nil, err |
34 | 53 |
} |
... | ... |
@@ -42,15 +63,11 @@ func StartWithSize(c *exec.Cmd, sz *Winsize) (pty *os.File, err error) { |
42 | 42 |
if c.Stdin == nil { |
43 | 43 |
c.Stdin = tty |
44 | 44 |
} |
45 |
- if c.SysProcAttr == nil { |
|
46 |
- c.SysProcAttr = &syscall.SysProcAttr{} |
|
47 |
- } |
|
48 |
- c.SysProcAttr.Setctty = true |
|
49 |
- c.SysProcAttr.Setsid = true |
|
50 |
- c.SysProcAttr.Ctty = int(tty.Fd()) |
|
51 |
- err = c.Start() |
|
52 |
- if err != nil { |
|
53 |
- pty.Close() |
|
45 |
+ |
|
46 |
+ c.SysProcAttr = attrs |
|
47 |
+ |
|
48 |
+ if err := c.Start(); err != nil { |
|
49 |
+ _ = pty.Close() |
|
54 | 50 |
return nil, err |
55 | 51 |
} |
56 | 52 |
return pty, err |