14 Commits

377 changed files with 168822 additions and 87 deletions
Split View
  1. +1
    -1
      .gitignore
  2. +13
    -0
      Dockerfile
  3. +43
    -0
      Jenkinsfile
  4. +0
    -24
      build.sh
  5. +12
    -0
      build/package/build.sh
  6. +13
    -0
      build/package/control
  7. +0
    -0
      build/package/debian/etc/gogocron/configs/.tasks_placeholder
  8. +0
    -0
      build/package/debian/etc/gogocron/gogocron.yml
  9. +0
    -0
      build/package/debian/etc/systemd/system/gogocron.service
  10. BIN
      build/package/debian/usr/bin/gogocron
  11. +1
    -0
      build/package/debian/usr/share/gogocron/samples/test1.yml
  12. +0
    -0
      build/package/debian/usr/share/gogocron/samples/test2.yml
  13. +4
    -2
      config.go
  14. +0
    -10
      debian/DEBIAN/control
  15. +16
    -3
      file_utils.go
  16. +9
    -0
      go.mod
  17. +9
    -0
      go.sum
  18. +21
    -15
      gogocron.go
  19. +105
    -27
      readme.md
  20. +4
    -0
      vendor/github.com/creack/pty/.gitignore
  21. +14
    -0
      vendor/github.com/creack/pty/Dockerfile.riscv
  22. +23
    -0
      vendor/github.com/creack/pty/LICENSE
  23. +100
    -0
      vendor/github.com/creack/pty/README.md
  24. +16
    -0
      vendor/github.com/creack/pty/doc.go
  25. +13
    -0
      vendor/github.com/creack/pty/ioctl.go
  26. +39
    -0
      vendor/github.com/creack/pty/ioctl_bsd.go
  27. +30
    -0
      vendor/github.com/creack/pty/ioctl_solaris.go
  28. +19
    -0
      vendor/github.com/creack/pty/mktypes.bash
  29. +65
    -0
      vendor/github.com/creack/pty/pty_darwin.go
  30. +80
    -0
      vendor/github.com/creack/pty/pty_dragonfly.go
  31. +78
    -0
      vendor/github.com/creack/pty/pty_freebsd.go
  32. +51
    -0
      vendor/github.com/creack/pty/pty_linux.go
  33. +33
    -0
      vendor/github.com/creack/pty/pty_openbsd.go
  34. +139
    -0
      vendor/github.com/creack/pty/pty_solaris.go
  35. +11
    -0
      vendor/github.com/creack/pty/pty_unsupported.go
  36. +57
    -0
      vendor/github.com/creack/pty/run.go
  37. +50
    -0
      vendor/github.com/creack/pty/test_crosscompile.sh
  38. +64
    -0
      vendor/github.com/creack/pty/util.go
  39. +51
    -0
      vendor/github.com/creack/pty/util_solaris.go
  40. +9
    -0
      vendor/github.com/creack/pty/ztypes_386.go
  41. +9
    -0
      vendor/github.com/creack/pty/ztypes_amd64.go
  42. +9
    -0
      vendor/github.com/creack/pty/ztypes_arm.go
  43. +11
    -0
      vendor/github.com/creack/pty/ztypes_arm64.go
  44. +14
    -0
      vendor/github.com/creack/pty/ztypes_dragonfly_amd64.go
  45. +13
    -0
      vendor/github.com/creack/pty/ztypes_freebsd_386.go
  46. +14
    -0
      vendor/github.com/creack/pty/ztypes_freebsd_amd64.go
  47. +13
    -0
      vendor/github.com/creack/pty/ztypes_freebsd_arm.go
  48. +12
    -0
      vendor/github.com/creack/pty/ztypes_mipsx.go
  49. +13
    -0
      vendor/github.com/creack/pty/ztypes_openbsd_386.go
  50. +13
    -0
      vendor/github.com/creack/pty/ztypes_openbsd_amd64.go
  51. +11
    -0
      vendor/github.com/creack/pty/ztypes_ppc64.go
  52. +11
    -0
      vendor/github.com/creack/pty/ztypes_ppc64le.go
  53. +11
    -0
      vendor/github.com/creack/pty/ztypes_riscvx.go
  54. +11
    -0
      vendor/github.com/creack/pty/ztypes_s390x.go
  55. +4
    -0
      vendor/github.com/kr/pty/.gitignore
  56. +23
    -0
      vendor/github.com/kr/pty/LICENSE
  57. +9
    -0
      vendor/github.com/kr/pty/README.md
  58. +5
    -0
      vendor/github.com/kr/pty/go.mod
  59. +2
    -0
      vendor/github.com/kr/pty/go.sum
  60. +76
    -0
      vendor/github.com/kr/pty/shim.go
  61. +3
    -0
      vendor/golang.org/x/sys/AUTHORS
  62. +3
    -0
      vendor/golang.org/x/sys/CONTRIBUTORS
  63. +27
    -0
      vendor/golang.org/x/sys/LICENSE
  64. +22
    -0
      vendor/golang.org/x/sys/PATENTS
  65. +30
    -0
      vendor/golang.org/x/sys/internal/unsafeheader/unsafeheader.go
  66. +2
    -0
      vendor/golang.org/x/sys/unix/.gitignore
  67. +184
    -0
      vendor/golang.org/x/sys/unix/README.md
  68. +86
    -0
      vendor/golang.org/x/sys/unix/affinity_linux.go
  69. +14
    -0
      vendor/golang.org/x/sys/unix/aliases.go
  70. +17
    -0
      vendor/golang.org/x/sys/unix/asm_aix_ppc64.s
  71. +29
    -0
      vendor/golang.org/x/sys/unix/asm_darwin_386.s
  72. +29
    -0
      vendor/golang.org/x/sys/unix/asm_darwin_amd64.s
  73. +30
    -0
      vendor/golang.org/x/sys/unix/asm_darwin_arm.s
  74. +30
    -0
      vendor/golang.org/x/sys/unix/asm_darwin_arm64.s
  75. +29
    -0
      vendor/golang.org/x/sys/unix/asm_dragonfly_amd64.s
  76. +29
    -0
      vendor/golang.org/x/sys/unix/asm_freebsd_386.s
  77. +29
    -0
      vendor/golang.org/x/sys/unix/asm_freebsd_amd64.s
  78. +29
    -0
      vendor/golang.org/x/sys/unix/asm_freebsd_arm.s
  79. +29
    -0
      vendor/golang.org/x/sys/unix/asm_freebsd_arm64.s
  80. +65
    -0
      vendor/golang.org/x/sys/unix/asm_linux_386.s
  81. +57
    -0
      vendor/golang.org/x/sys/unix/asm_linux_amd64.s
  82. +56
    -0
      vendor/golang.org/x/sys/unix/asm_linux_arm.s
  83. +52
    -0
      vendor/golang.org/x/sys/unix/asm_linux_arm64.s
  84. +56
    -0
      vendor/golang.org/x/sys/unix/asm_linux_mips64x.s
  85. +54
    -0
      vendor/golang.org/x/sys/unix/asm_linux_mipsx.s
  86. +44
    -0
      vendor/golang.org/x/sys/unix/asm_linux_ppc64x.s
  87. +47
    -0
      vendor/golang.org/x/sys/unix/asm_linux_riscv64.s
  88. +56
    -0
      vendor/golang.org/x/sys/unix/asm_linux_s390x.s
  89. +29
    -0
      vendor/golang.org/x/sys/unix/asm_netbsd_386.s
  90. +29
    -0
      vendor/golang.org/x/sys/unix/asm_netbsd_amd64.s
  91. +29
    -0
      vendor/golang.org/x/sys/unix/asm_netbsd_arm.s
  92. +29
    -0
      vendor/golang.org/x/sys/unix/asm_netbsd_arm64.s
  93. +29
    -0
      vendor/golang.org/x/sys/unix/asm_openbsd_386.s
  94. +29
    -0
      vendor/golang.org/x/sys/unix/asm_openbsd_amd64.s
  95. +29
    -0
      vendor/golang.org/x/sys/unix/asm_openbsd_arm.s
  96. +29
    -0
      vendor/golang.org/x/sys/unix/asm_openbsd_arm64.s
  97. +17
    -0
      vendor/golang.org/x/sys/unix/asm_solaris_amd64.s
  98. +36
    -0
      vendor/golang.org/x/sys/unix/bluetooth_linux.go
  99. +195
    -0
      vendor/golang.org/x/sys/unix/cap_freebsd.go
  100. +13
    -0
      vendor/golang.org/x/sys/unix/constants.go

+ 1
- 1
.gitignore View File

@ -1,2 +1,2 @@
gogocron
./gogocron
*.deb

+ 13
- 0
Dockerfile View File

@ -0,0 +1,13 @@
FROM golang:1.13-alpine
RUN apk update
RUN apk add git mercurial
WORKDIR /app
COPY . .
RUN CGO_ENABLED=0 go build -mod vendor -ldflags "-w -s"
FROM alpine:3.11
COPY --from=0 /app/gogocron /usr/bin/gogocron

+ 43
- 0
Jenkinsfile View File

@ -0,0 +1,43 @@
node {
checkout scm
def registry = "registry.blindage.org"
def tag = env.TAG_NAME
def image
def repository = "gogocron"
def image_name = "${repository}:${tag}"
stage("Build binary") {
sh "docker run --rm -v jenkins_jenkins-data:/var/jenkins_home golang:1.13 /bin/sh -c 'cd ${WORKSPACE} && CGO_ENABLED=0 go build -mod vendor -ldflags \"-w -s\"'"
}
stage("Build image") {
try {
sh "docker build -t ${image_name} ."
image = docker.image(image_name)
} catch (Exception e) {
error("Failed to build image")
}
}
stage("Build package") {
sh "./build/package/build.sh"
archiveArtifacts "gogocron-${tag}.deb"
sh "mv *.deb /var/packages/"
}
stage("Push Image") {
try {
docker.withRegistry("https://${registry}", "registry") {
image.push()
}
} catch(Exception e) {
error("Failed to push image")
} finally {
sh "docker rmi ${registry}/${image_name} || true"
}
}
}

+ 0
- 24
build.sh View File

@ -1,24 +0,0 @@
#!/bin/bash
VERSION="1.1"
# build gogocron
go build
# prepage control file
sed -i "s/Version.*/Version: ${VERSION}/" ./debian/DEBIAN/control
# copy files to deb package structure
mkdir -p ./debian/etc/gogocron
mkdir -p ./debian/usr/bin
mkdir -p ./debian/usr/share/gogocron/samples/
mkdir -p ./debian/DEBIAN
cp gogocron ./debian/usr/bin/
cp config/gogocron.yml ./debian/etc/gogocron/
cp configs/*.yml ./debian/usr/share/gogocron/samples/
# build deb package
dpkg-deb --build debian gogocron-${VERSION}.deb

+ 12
- 0
build/package/build.sh View File

@ -0,0 +1,12 @@
#!/bin/bash
VERSION=${TAG_NAME}
mkdir -p ./build/package/debian/usr/bin
mkdir -p ./build/package/debian/DEBIAN/
mv ./gogocron ./build/package/debian/usr/bin/
DSIZE=$(du -hs ./build/package/debian/usr/bin|awk '{ print $1 }')
echo "Making deb config"
cp ./build/package/control ./build/package/debian/DEBIAN/control
sed -i "s/VERSION/${VERSION}/g" ./build/package/debian/DEBIAN/control
sed -i "s/DSIZE/${DSIZE}/g" ./build/package/debian/DEBIAN/control
echo "Building deb package"
dpkg-deb --build ./build/package/debian ./gogocron-${VERSION}.deb

+ 13
- 0
build/package/control View File

@ -0,0 +1,13 @@
Package: gogocron
Version: VERSION
Section: base
Priority: optional
Installed-Size: DSIZE
Architecture: amd64
Depends: coreutils (>= 5.0-5)
Maintainer: Vladimir Smagin <21h@blindage.org>
Homepage: https://git.blindage.org/21h/gogocron
Description: Cron daemon for Linux with 1 second minimal interval
This package provides gogocron daemon, that can run tasks with 1s
minimal interval and execution timeout. Higly configurable tasks with
adjustable run precision.

+ 0
- 0
build/package/debian/etc/gogocron/configs/.tasks_placeholder View File


config/gogocron.yml → build/package/debian/etc/gogocron/gogocron.yml View File


debian/etc/systemd/system/gogocron.service → build/package/debian/etc/systemd/system/gogocron.service View File


BIN
build/package/debian/usr/bin/gogocron View File


configs/test1.yml → build/package/debian/usr/share/gogocron/samples/test1.yml View File

@ -3,6 +3,7 @@ name: "TASK #1"
runsecond: "*/5"
logtype: full
user: vlad
gracefulstop: 30ss
env:
- TESTVAR="test variable"
commands:

configs/test2.yml → build/package/debian/usr/share/gogocron/samples/test2.yml View File


+ 4
- 2
config.go View File

@ -53,13 +53,15 @@ func readTaskConfigFile(path string) cronTask {
log.Fatalf("Error opening file %v", err)
}
//log.Printf(string(yamldata))
marshErr := yaml.Unmarshal(yamldata, &config)
if marshErr != nil {
log.Fatalf("Task file malformed: %v", marshErr)
}
if config.GracefulStop == "" {
config.GracefulStop = "10s"
}
return config
}


+ 0
- 10
debian/DEBIAN/control View File

@ -1,10 +0,0 @@
Package: gogocron
Version: 1.1
Section: base
Priority: optional
Architecture: all
Depends: coreutils (>= 5.0-5)
Maintainer: Vladimir Smagin <21h@blindage.org>
Description: Linux cron daemon with 1 second minimal interval
This package provides gogocron daemon, that can run tasks with 1s
minimal interval and execution timeout.

+ 16
- 3
file_utils.go View File

@ -53,6 +53,20 @@ func inArray(val interface{}, array interface{}) (exists bool, index int) {
// run commands
func runCmd(ctx context.Context, env []string, cmdname string, params ...string) error {
// Read graceful stop value from context
var gracefulStop string
if v := ctx.Value("gracefulstopvalue"); v != nil {
gracefulStop = v.(string)
} else {
gracefulStop = "10s"
}
gracefulStopSeconds, err := time.ParseDuration(gracefulStop)
if err != nil {
log.Fatalln("Error parsing gracefulstop value as time duration")
}
//log.Println("Executing", cmdname, params)
cmd := exec.Command(cmdname, params...)
@ -82,9 +96,8 @@ func runCmd(ctx context.Context, env []string, cmdname string, params ...string)
case <-ctx.Done():
// Timeout happened first, kill the process and print a message.
cmd.Process.Signal(syscall.SIGTERM)
// graceful stop 10 seconds
// if task must be killed instead of normal termination
time.AfterFunc(10*time.Second, func() {
// gracefulStopSeconds is a time between SIGTERM and SIGKILL, default 10s, minimum 1s
time.AfterFunc(gracefulStopSeconds, func() {
if !cmd.ProcessState.Exited() {
cmd.Process.Kill()
}


+ 9
- 0
go.mod View File

@ -0,0 +1,9 @@
module git.blindage.org/21h/gogocron
go 1.13
require (
github.com/kr/pty v1.1.8
golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3 // indirect
gopkg.in/yaml.v2 v2.2.8
)

+ 9
- 0
go.sum View File

@ -0,0 +1,9 @@
github.com/creack/pty v1.1.7 h1:6pwm8kMQKCmgUg0ZHTm5+/YvRK0s3THD/28+T6/kk4A=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/kr/pty v1.1.8 h1:AkaSdXYQOWeaO3neb8EM634ahkXXe3jYbVh/F9lq+GI=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3 h1:5B6i6EAiSYyejWfvc5Rc9BbI3rzIsrrXfAQBWnYfn+w=
golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

+ 21
- 15
gogocron.go View File

@ -31,18 +31,19 @@ type cronConfig struct {
}
type cronTask struct {
Name string `yaml:"name"` // name of task
AsUser string `yaml:"user,omitempty"` // run as user
RunSecond string `yaml:"runsecond,omitempty"` // second
RunMinute string `yaml:"runminute,omitempty"` // minute
RunHour string `yaml:"runhour,omitempty"` // hour
RunDom string `yaml:"rundom,omitempty"` // day of month
RunMonth string `yaml:"runmonth,omitempty"` // month
RunDow string `yaml:"rundow,omitempty"` // day of week
TimeOut string `yaml:"timeout,omitempty"` // exec with timeout, seconds
Env []string `yaml:"env,omitempty"` // array of env variables
Commands []string `yaml:"commands"` // array of commands to exec
LogType string `yaml:"logtype,omitempty"` // type of logging: info, full, disabled
Name string `yaml:"name"` // name of task
AsUser string `yaml:"user,omitempty"` // run as user
RunSecond string `yaml:"runsecond,omitempty"` // second
RunMinute string `yaml:"runminute,omitempty"` // minute
RunHour string `yaml:"runhour,omitempty"` // hour
RunDom string `yaml:"rundom,omitempty"` // day of month
RunMonth string `yaml:"runmonth,omitempty"` // month
RunDow string `yaml:"rundow,omitempty"` // day of week
TimeOut string `yaml:"timeout,omitempty"` // exec with timeout, seconds
Env []string `yaml:"env,omitempty"` // array of env variables
Commands []string `yaml:"commands"` // array of commands to exec
LogType string `yaml:"logtype,omitempty"` // type of logging: info, full, disabled
GracefulStop string `yaml:"gracefulstop,omitempty"` // seconds between task term and kill
}
type cronTasks []cronTask
@ -133,6 +134,11 @@ func executeTask(ctx context.Context, task cronTask) {
// flag to stop timed out tasks
timeoutFlag := false
// send gracefulstop with context
type contextKey string
gracefulStop := contextKey("gracefulstopvalue")
ctxRunCmd := context.WithValue(ctx, gracefulStop, task.GracefulStop)
// iterate commands list
for _, cmd := range task.Commands {
if timeoutFlag {
@ -140,19 +146,19 @@ func executeTask(ctx context.Context, task cronTask) {
}
select {
case <-ctx.Done():
case <-ctxRunCmd.Done():
log.Printf("Timeout exceeded for task %v", task.Name)
timeoutFlag = true
default:
// su required to run as other users, requires pty to run
runCmd(ctx, task.Env, "su", "-c", cmd, task.AsUser)
runCmd(ctxRunCmd, task.Env, "su", "-c", cmd, task.AsUser)
}
}
}
func main() {
log.Println("gogocron 1.1 by Vladimir Smagin (http://gogocron.blindage.org)")
log.Println("gogocron 1.1.1 by Vladimir Smagin (http://gogocron.blindage.org)")
// Load config at startup, once
gogoConfig := loadConfig()


+ 105
- 27
readme.md View File

@ -1,48 +1,93 @@
# gogocron - one second crontab daemon
Cron daemon with crontab syntax, small interval and execution timeout for each task. Report bugs here 21h@blindage.org.
## Features
- customizing tasks files location
- traditional crontab syntax for defining run intervals
- 1 second minimal interval
- 10 ms precision
- run command as other user
- batch of commands
- timeout for whole task
- your own ENV variables
- traditional crontab syntax
- your own ENV variables for whole task
- adjustable run precision from 10 ms to 500 ms
- batch of commands to run in one task
- run task commands as other user
- timeout for whole task with default graceful period 10s
- SIGHUP process to reload config files
- adjustable graceful timeout period for each command in task
## Install
You can find binary code in [Releases](/21h/gogocron/releases) tab or build code yourself.
## Installation
Requires:
- root user privileges to run su command
- available su command in $PATH
- root user privileges to run `su` command
- available `su` command in `$PATH`
### Ubuntu\Debian repository
Installation:
Check before that `curl` and `tee` installed.
```
$ wget https://git.blindage.org/attachments/b02e74bf-b000-4a62-978e-97f91c7f2a64 -O gogocron.deb
$ dpkg -i gogocron.deb
curl http://deb.blindage.org/gpg-key.asc | sudo apt-key add -
echo "deb http://deb.blindage.org bionic main" | sudo tee /etc/apt/sources.list.d/21h.list
sudo apt install gogocron
```
### Manual deb package installation
You can find binary code in [Releases](/21h/gogocron/releases) tab or build code yourself.
Installation example (change download url to last release):
```
$ wget --content-disposition "https://git.blindage.org/attachments/deaaa74f-efbe-4254-bf10-18e108b81065"
$ dpkg -i gogocron-1.1.deb
$ systemctl enable gogocron
$ systemctl start gogocron
```
## Build code yourself
### Build code yourself
This is a Go code. Install required libraries and build:
Install [Golang](https://golang.org/dl/), then build:
```
go get github.com/kr/pty
go get gopkg.in/yaml.v2
go build
./build.sh
```
## Configuration
### Global configuration options
All global options loads once at daemon start and HUP signal have no effect on them, use restart command: `systemctl restart gogocron`.
#### Precision
Run precision means how frequently gogocron checks that second was incremented. What this means to you? Answer is how fast task will run after new second begin + some delta time for filtering tasks to run. Default value is 100 ms, but if you lower this value the checking circle get more CPU resources because checks to be more frequent.
Edit `/etc/gogocron/gogocron.yml`:
```
ticktack_precision: 100ms
```
#### Tasks location
Set location where tasks files stored.
Edit `/etc/gogocron/gogocron.yml`:
```
tasks_location: /etc/gogocron/configs
```
### Tasks configuration options
## Interval
gogocron reloads all tasks configurations after receiving HUP signal, use `reload` or `restart` command to apply new task configuration: `systemctl reload gogocron`.
Use traditional crontab syntax
#### Interval
Set interval how often run task (whole batch of commands in task). Use traditional crontab syntax.
```
runsecond // second
@ -53,16 +98,38 @@ runmonth // month
rundow // day of week
```
## Timeout
#### Timeout
If whole task (not one command in task) running more than timeout cron send SIGTERM signal, by default timeout is turned off.
```
timeout: 3h12m4s
```
It's a golang's [time.Duration](https://golang.org/pkg/time/#Duration) definition, string:
- 1s - one second
- 1m10s - one minute and 10 seconds
#### Graceful stop
By default if task's command not die after SIGTERM in 10s cron send SIGKILL signal. You may need this if your program receiving signals but internal queue not empty for immidiately stop.
You can change this time with:
```
timeout: 3h12m4s
gracefulstop: 30s
```
## ENV variables
It's a golang's [time.Duration](https://golang.org/pkg/time/#Duration) definition, string:
- 1s - one second
- 1m10s - one minute and 10 seconds
#### ENV
Array of environment variables (strings). Defines additional to gogocron's env variables for each command in `commands` array.
Syntax:
```
@ -70,7 +137,9 @@ env:
- TESTVAR="test variable"
```
## Commands
#### Commands
Array of commands (strings). Commands in one task running line by line with environment variables defined in `ENV`.
Syntax:
@ -83,27 +152,36 @@ commands:
- echo $TESTVAR
```
## Logging of task
#### Logging of task
`logtype` can accept:
- info (default, logging only fact of run)
- full (log fact of run and stdout/stderr, useful for debugging)
- disabled (completely disable logs)
## Sample config file
## Sample task configuration file
You never see variable value because timeout kill this task earlier.
```
---
name: "Print base64 of 20 random symbols"
runsecond: "*/5"
logtype: info
timeout: 10s
user: vlad
env:
- TESTVAR="test variable"
- TESTVAR="text you never see"
commands:
- whoami
- sleep 3
- head -c 20 /dev/urandom |base64
- ls
- sleep 10
- echo $TESTVAR
```
```
---
Copyright by Vladimir Smagin (21h) 2019-2020
http://blindage.org email: 21h@blindage.org
Project page: https://git.blindage.org/21h/gogocron

+ 4
- 0
vendor/github.com/creack/pty/.gitignore View File

@ -0,0 +1,4 @@
[568].out
_go*
_test*
_obj

+ 14
- 0
vendor/github.com/creack/pty/Dockerfile.riscv View File

@ -0,0 +1,14 @@
FROM golang:1.12
# Clone and complie a riscv compatible version of the go compiler.
RUN git clone https://review.gerrithub.io/riscv/riscv-go /riscv-go
# riscvdev branch HEAD as of 2019-06-29.
RUN cd /riscv-go && git checkout 04885fddd096d09d4450726064d06dd107e374bf
ENV PATH=/riscv-go/misc/riscv:/riscv-go/bin:$PATH
RUN cd /riscv-go/src && GOROOT_BOOTSTRAP=$(go env GOROOT) ./make.bash
ENV GOROOT=/riscv-go
# Make sure we compile.
WORKDIR pty
ADD . .
RUN GOOS=linux GOARCH=riscv go build

+ 23
- 0
vendor/github.com/creack/pty/LICENSE View File

@ -0,0 +1,23 @@
Copyright (c) 2011 Keith Rarick
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall
be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 100
- 0
vendor/github.com/creack/pty/README.md View File

@ -0,0 +1,100 @@
# pty
Pty is a Go package for using unix pseudo-terminals.
## Install
go get github.com/creack/pty
## Example
### Command
```go
package main
import (
"github.com/creack/pty"
"io"
"os"
"os/exec"
)
func main() {
c := exec.Command("grep", "--color=auto", "bar")
f, err := pty.Start(c)
if err != nil {
panic(err)
}
go func() {
f.Write([]byte("foo\n"))
f.Write([]byte("bar\n"))
f.Write([]byte("baz\n"))
f.Write([]byte{4}) // EOT
}()
io.Copy(os.Stdout, f)
}
```
### Shell
```go
package main
import (
"io"
"log"
"os"
"os/exec"
"os/signal"
"syscall"
"github.com/creack/pty"
"golang.org/x/crypto/ssh/terminal"
)
func test() error {
// Create arbitrary command.
c := exec.Command("bash")
// Start the command with a pty.
ptmx, err := pty.Start(c)
if err != nil {
return err
}
// Make sure to close the pty at the end.
defer func() { _ = ptmx.Close() }() // Best effort.
// Handle pty size.
ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGWINCH)
go func() {
for range ch {
if err := pty.InheritSize(os.Stdin, ptmx); err != nil {
log.Printf("error resizing pty: %s", err)
}
}
}()
ch <- syscall.SIGWINCH // Initial resize.
// Set stdin in raw mode.
oldState, err := terminal.MakeRaw(int(os.Stdin.Fd()))
if err != nil {
panic(err)
}
defer func() { _ = terminal.Restore(int(os.Stdin.Fd()), oldState) }() // Best effort.
// Copy stdin to the pty and the pty to stdout.
go func() { _, _ = io.Copy(ptmx, os.Stdin) }()
_, _ = io.Copy(os.Stdout, ptmx)
return nil
}
func main() {
if err := test(); err != nil {
log.Fatal(err)
}
}
```

+ 16
- 0
vendor/github.com/creack/pty/doc.go View File

@ -0,0 +1,16 @@
// Package pty provides functions for working with Unix terminals.
package pty
import (
"errors"
"os"
)
// ErrUnsupported is returned if a function is not
// available on the current platform.
var ErrUnsupported = errors.New("unsupported")
// Opens a pty and its corresponding tty.
func Open() (pty, tty *os.File, err error) {
return open()
}

+ 13
- 0
vendor/github.com/creack/pty/ioctl.go View File

@ -0,0 +1,13 @@
// +build !windows,!solaris
package pty
import "syscall"
func ioctl(fd, cmd, ptr uintptr) error {
_, _, e := syscall.Syscall(syscall.SYS_IOCTL, fd, cmd, ptr)
if e != 0 {
return e
}
return nil
}

+ 39
- 0
vendor/github.com/creack/pty/ioctl_bsd.go View File

@ -0,0 +1,39 @@
// +build darwin dragonfly freebsd netbsd openbsd
package pty
// from <sys/ioccom.h>
const (
_IOC_VOID uintptr = 0x20000000
_IOC_OUT uintptr = 0x40000000
_IOC_IN uintptr = 0x80000000
_IOC_IN_OUT uintptr = _IOC_OUT | _IOC_IN
_IOC_DIRMASK = _IOC_VOID | _IOC_OUT | _IOC_IN
_IOC_PARAM_SHIFT = 13
_IOC_PARAM_MASK = (1 << _IOC_PARAM_SHIFT) - 1
)
func _IOC_PARM_LEN(ioctl uintptr) uintptr {
return (ioctl >> 16) & _IOC_PARAM_MASK
}
func _IOC(inout uintptr, group byte, ioctl_num uintptr, param_len uintptr) uintptr {
return inout | (param_len&_IOC_PARAM_MASK)<<16 | uintptr(group)<<8 | ioctl_num
}
func _IO(group byte, ioctl_num uintptr) uintptr {
return _IOC(_IOC_VOID, group, ioctl_num, 0)
}
func _IOR(group byte, ioctl_num uintptr, param_len uintptr) uintptr {
return _IOC(_IOC_OUT, group, ioctl_num, param_len)
}
func _IOW(group byte, ioctl_num uintptr, param_len uintptr) uintptr {
return _IOC(_IOC_IN, group, ioctl_num, param_len)
}
func _IOWR(group byte, ioctl_num uintptr, param_len uintptr) uintptr {
return _IOC(_IOC_IN_OUT, group, ioctl_num, param_len)
}

+ 30
- 0
vendor/github.com/creack/pty/ioctl_solaris.go View File

@ -0,0 +1,30 @@
package pty
import (
"golang.org/x/sys/unix"
"unsafe"
)
const (
// see /usr/include/sys/stropts.h
I_PUSH = uintptr((int32('S')<<8 | 002))
I_STR = uintptr((int32('S')<<8 | 010))
I_FIND = uintptr((int32('S')<<8 | 013))
// see /usr/include/sys/ptms.h
ISPTM = (int32('P') << 8) | 1
UNLKPT = (int32('P') << 8) | 2
PTSSTTY = (int32('P') << 8) | 3
ZONEPT = (int32('P') << 8) | 4
OWNERPT = (int32('P') << 8) | 5
)
type strioctl struct {
ic_cmd int32
ic_timout int32
ic_len int32
ic_dp unsafe.Pointer
}
func ioctl(fd, cmd, ptr uintptr) error {
return unix.IoctlSetInt(int(fd), uint(cmd), int(ptr))
}

+ 19
- 0
vendor/github.com/creack/pty/mktypes.bash View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
GOOSARCH="${GOOS}_${GOARCH}"
case "$GOOSARCH" in
_* | *_ | _)
echo 'undefined $GOOS_$GOARCH:' "$GOOSARCH" 1>&2
exit 1
;;
esac
GODEFS="go tool cgo -godefs"
$GODEFS types.go |gofmt > ztypes_$GOARCH.go
case $GOOS in
freebsd|dragonfly|openbsd)
$GODEFS types_$GOOS.go |gofmt > ztypes_$GOOSARCH.go
;;
esac

+ 65
- 0
vendor/github.com/creack/pty/pty_darwin.go View File

@ -0,0 +1,65 @@
package pty
import (
"errors"
"os"
"syscall"
"unsafe"
)
func open() (pty, tty *os.File, err error) {
pFD, err := syscall.Open("/dev/ptmx", syscall.O_RDWR|syscall.O_CLOEXEC, 0)
if err != nil {
return nil, nil, err
}
p := os.NewFile(uintptr(pFD), "/dev/ptmx")
// In case of error after this point, make sure we close the ptmx fd.
defer func() {
if err != nil {
_ = p.Close() // Best effort.
}
}()
sname, err := ptsname(p)
if err != nil {
return nil, nil, err
}
if err := grantpt(p); err != nil {
return nil, nil, err
}
if err := unlockpt(p); err != nil {
return nil, nil, err
}
t, err := os.OpenFile(sname, os.O_RDWR, 0)
if err != nil {
return nil, nil, err
}
return p, t, nil
}
func ptsname(f *os.File) (string, error) {
n := make([]byte, _IOC_PARM_LEN(syscall.TIOCPTYGNAME))
err := ioctl(f.Fd(), syscall.TIOCPTYGNAME, uintptr(unsafe.Pointer(&n[0])))
if err != nil {
return "", err
}
for i, c := range n {
if c == 0 {
return string(n[:i]), nil
}
}
return "", errors.New("TIOCPTYGNAME string not NUL-terminated")
}
func grantpt(f *os.File) error {
return ioctl(f.Fd(), syscall.TIOCPTYGRANT, 0)
}
func unlockpt(f *os.File) error {
return ioctl(f.Fd(), syscall.TIOCPTYUNLK, 0)
}

+ 80
- 0
vendor/github.com/creack/pty/pty_dragonfly.go View File

@ -0,0 +1,80 @@
package pty
import (
"errors"
"os"
"strings"
"syscall"
"unsafe"
)
// same code as pty_darwin.go
func open() (pty, tty *os.File, err error) {
p, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0)
if err != nil {
return nil, nil, err
}
// In case of error after this point, make sure we close the ptmx fd.
defer func() {
if err != nil {
_ = p.Close() // Best effort.
}
}()
sname, err := ptsname(p)
if err != nil {
return nil, nil, err
}
if err := grantpt(p); err != nil {
return nil, nil, err
}
if err := unlockpt(p); err != nil {
return nil, nil, err
}
t, err := os.OpenFile(sname, os.O_RDWR, 0)
if err != nil {
return nil, nil, err
}
return p, t, nil
}
func grantpt(f *os.File) error {
_, err := isptmaster(f.Fd())
return err
}
func unlockpt(f *os.File) error {
_, err := isptmaster(f.Fd())
return err
}
func isptmaster(fd uintptr) (bool, error) {
err := ioctl(fd, syscall.TIOCISPTMASTER, 0)
return err == nil, err
}
var (
emptyFiodgnameArg fiodgnameArg
ioctl_FIODNAME = _IOW('f', 120, unsafe.Sizeof(emptyFiodgnameArg))
)
func ptsname(f *os.File) (string, error) {
name := make([]byte, _C_SPECNAMELEN)
fa := fiodgnameArg{Name: (*byte)(unsafe.Pointer(&name[0])), Len: _C_SPECNAMELEN, Pad_cgo_0: [4]byte{0, 0, 0, 0}}
err := ioctl(f.Fd(), ioctl_FIODNAME, uintptr(unsafe.Pointer(&fa)))
if err != nil {
return "", err
}
for i, c := range name {
if c == 0 {
s := "/dev/" + string(name[:i])
return strings.Replace(s, "ptm", "pts", -1), nil
}
}
return "", errors.New("TIOCPTYGNAME string not NUL-terminated")
}

+ 78
- 0
vendor/github.com/creack/pty/pty_freebsd.go View File

@ -0,0 +1,78 @@
package pty
import (
"errors"
"os"
"syscall"
"unsafe"
)
func posixOpenpt(oflag int) (fd int, err error) {
r0, _, e1 := syscall.Syscall(syscall.SYS_POSIX_OPENPT, uintptr(oflag), 0, 0)
fd = int(r0)
if e1 != 0 {
err = e1
}
return fd, err
}
func open() (pty, tty *os.File, err error) {
fd, err := posixOpenpt(syscall.O_RDWR | syscall.O_CLOEXEC)
if err != nil {
return nil, nil, err
}
p := os.NewFile(uintptr(fd), "/dev/pts")
// In case of error after this point, make sure we close the pts fd.
defer func() {
if err != nil {
_ = p.Close() // Best effort.
}
}()
sname, err := ptsname(p)
if err != nil {
return nil, nil, err
}
t, err := os.OpenFile("/dev/"+sname, os.O_RDWR, 0)
if err != nil {
return nil, nil, err
}
return p, t, nil
}
func isptmaster(fd uintptr) (bool, error) {
err := ioctl(fd, syscall.TIOCPTMASTER, 0)
return err == nil, err
}
var (
emptyFiodgnameArg fiodgnameArg
ioctlFIODGNAME = _IOW('f', 120, unsafe.Sizeof(emptyFiodgnameArg))
)
func ptsname(f *os.File) (string, error) {
master, err := isptmaster(f.Fd())
if err != nil {
return "", err
}
if !master {
return "", syscall.EINVAL
}
const n = _C_SPECNAMELEN + 1
var (
buf = make([]byte, n)
arg = fiodgnameArg{Len: n, Buf: (*byte)(unsafe.Pointer(&buf[0]))}
)
if err := ioctl(f.Fd(), ioctlFIODGNAME, uintptr(unsafe.Pointer(&arg))); err != nil {
return "", err
}
for i, c := range buf {
if c == 0 {
return string(buf[:i]), nil
}
}
return "", errors.New("FIODGNAME string not NUL-terminated")
}

+ 51
- 0
vendor/github.com/creack/pty/pty_linux.go View File

@ -0,0 +1,51 @@
package pty
import (
"os"
"strconv"
"syscall"
"unsafe"
)
func open() (pty, tty *os.File, err error) {
p, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0)
if err != nil {
return nil, nil, err
}
// In case of error after this point, make sure we close the ptmx fd.
defer func() {
if err != nil {
_ = p.Close() // Best effort.
}
}()
sname, err := ptsname(p)
if err != nil {
return nil, nil, err
}
if err := unlockpt(p); err != nil {
return nil, nil, err
}
t, err := os.OpenFile(sname, os.O_RDWR|syscall.O_NOCTTY, 0)
if err != nil {
return nil, nil, err
}
return p, t, nil
}
func ptsname(f *os.File) (string, error) {
var n _C_uint
err := ioctl(f.Fd(), syscall.TIOCGPTN, uintptr(unsafe.Pointer(&n)))
if err != nil {
return "", err
}
return "/dev/pts/" + strconv.Itoa(int(n)), nil
}
func unlockpt(f *os.File) error {
var u _C_int
// use TIOCSPTLCK with a pointer to zero to clear the lock
return ioctl(f.Fd(), syscall.TIOCSPTLCK, uintptr(unsafe.Pointer(&u)))
}

+ 33
- 0
vendor/github.com/creack/pty/pty_openbsd.go View File

@ -0,0 +1,33 @@
package pty
import (
"os"
"syscall"
"unsafe"
)
func open() (pty, tty *os.File, err error) {
/*
* from ptm(4):
* The PTMGET command allocates a free pseudo terminal, changes its
* ownership to the caller, revokes the access privileges for all previous
* users, opens the file descriptors for the pty and tty devices and
* returns them to the caller in struct ptmget.
*/
p, err := os.OpenFile("/dev/ptm", os.O_RDWR|syscall.O_CLOEXEC, 0)
if err != nil {
return nil, nil, err
}
defer p.Close()
var ptm ptmget
if err := ioctl(p.Fd(), uintptr(ioctl_PTMGET), uintptr(unsafe.Pointer(&ptm))); err != nil {
return nil, nil, err
}
pty = os.NewFile(uintptr(ptm.Cfd), "/dev/ptm")
tty = os.NewFile(uintptr(ptm.Sfd), "/dev/ptm")
return pty, tty, nil
}

+ 139
- 0
vendor/github.com/creack/pty/pty_solaris.go View File

@ -0,0 +1,139 @@
package pty
/* based on:
http://src.illumos.org/source/xref/illumos-gate/usr/src/lib/libc/port/gen/pt.c
*/
import (
"errors"
"golang.org/x/sys/unix"
"os"
"strconv"
"syscall"
"unsafe"
)
const NODEV = ^uint64(0)
func open() (pty, tty *os.File, err error) {
masterfd, err := syscall.Open("/dev/ptmx", syscall.O_RDWR|unix.O_NOCTTY, 0)
//masterfd, err := syscall.Open("/dev/ptmx", syscall.O_RDWR|syscall.O_CLOEXEC|unix.O_NOCTTY, 0)
if err != nil {
return nil, nil, err
}
p := os.NewFile(uintptr(masterfd), "/dev/ptmx")
sname, err := ptsname(p)
if err != nil {
return nil, nil, err
}
err = grantpt(p)
if err != nil {
return nil, nil, err
}
err = unlockpt(p)
if err != nil {
return nil, nil, err
}
slavefd, err := syscall.Open(sname, os.O_RDWR|unix.O_NOCTTY, 0)
if err != nil {
return nil, nil, err
}
t := os.NewFile(uintptr(slavefd), sname)
// pushing terminal driver STREAMS modules as per pts(7)
for _, mod := range([]string{"ptem", "ldterm", "ttcompat"}) {
err = streams_push(t, mod)
if err != nil {
return nil, nil, err
}
}
return p, t, nil
}
func minor(x uint64) uint64 {
return x & 0377
}
func ptsdev(fd uintptr) uint64 {
istr := strioctl{ISPTM, 0, 0, nil}
err := ioctl(fd, I_STR, uintptr(unsafe.Pointer(&istr)))
if err != nil {
return NODEV
}
var status unix.Stat_t
err = unix.Fstat(int(fd), &status)
if err != nil {
return NODEV
}
return uint64(minor(status.Rdev))
}
func ptsname(f *os.File) (string, error) {
dev := ptsdev(f.Fd())
if dev == NODEV {
return "", errors.New("not a master pty")
}
fn := "/dev/pts/" + strconv.FormatInt(int64(dev), 10)
// access(2) creates the slave device (if the pty exists)
// F_OK == 0 (unistd.h)
err := unix.Access(fn, 0)
if err != nil {
return "", err
}
return fn, nil
}
type pt_own struct {
pto_ruid int32
pto_rgid int32
}
func grantpt(f *os.File) error {
if ptsdev(f.Fd()) == NODEV {
return errors.New("not a master pty")
}
var pto pt_own
pto.pto_ruid = int32(os.Getuid())
// XXX should first attempt to get gid of DEFAULT_TTY_GROUP="tty"
pto.pto_rgid = int32(os.Getgid())
var istr strioctl
istr.ic_cmd = OWNERPT
istr.ic_timout = 0
istr.ic_len = int32(unsafe.Sizeof(istr))
istr.ic_dp = unsafe.Pointer(&pto)
err := ioctl(f.Fd(), I_STR, uintptr(unsafe.Pointer(&istr)))
if err != nil {
return errors.New("access denied")
}
return nil
}
func unlockpt(f *os.File) error {
istr := strioctl{UNLKPT, 0, 0, nil}
return ioctl(f.Fd(), I_STR, uintptr(unsafe.Pointer(&istr)))
}
// push STREAMS modules if not already done so
func streams_push(f *os.File, mod string) error {
var err error
buf := []byte(mod)
// XXX I_FIND is not returning an error when the module
// is already pushed even though truss reports a return
// value of 1. A bug in the Go Solaris syscall interface?
// XXX without this we are at risk of the issue
// https://www.illumos.org/issues/9042
// but since we are not using libc or XPG4.2, we should not be
// double-pushing modules
err = ioctl(f.Fd(), I_FIND, uintptr(unsafe.Pointer(&buf[0])))
if err != nil {
return nil
}
err = ioctl(f.Fd(), I_PUSH, uintptr(unsafe.Pointer(&buf[0])))
return err
}

+ 11
- 0
vendor/github.com/creack/pty/pty_unsupported.go View File

@ -0,0 +1,11 @@
// +build !linux,!darwin,!freebsd,!dragonfly,!openbsd,!solaris
package pty
import (
"os"
)
func open() (pty, tty *os.File, err error) {
return nil, nil, ErrUnsupported
}

+ 57
- 0
vendor/github.com/creack/pty/run.go View File

@ -0,0 +1,57 @@
// +build !windows
package pty
import (
"os"
"os/exec"
"syscall"
)
// Start assigns a pseudo-terminal tty os.File to c.Stdin, c.Stdout,
// and c.Stderr, calls c.Start, and returns the File of the tty's
// corresponding pty.
func Start(c *exec.Cmd) (pty *os.File, err error) {
return StartWithSize(c, nil)
}
// StartWithSize assigns a pseudo-terminal tty os.File to c.Stdin, c.Stdout,
// and c.Stderr, calls c.Start, and returns the File of the tty's
// corresponding pty.
//
// This will resize the pty to the specified size before starting the command
func StartWithSize(c *exec.Cmd, sz *Winsize) (pty *os.File, err error) {
pty, tty, err := Open()
if err != nil {
return nil, err
}
defer tty.Close()
if sz != nil {
err = Setsize(pty, sz)
if err != nil {
pty.Close()
return nil, err
}
}
if c.Stdout == nil {
c.Stdout = tty
}
if c.Stderr == nil {
c.Stderr = tty
}
if c.Stdin == nil {
c.Stdin = tty
}
if c.SysProcAttr == nil {
c.SysProcAttr = &syscall.SysProcAttr{}
}
c.SysProcAttr.Setctty = true
c.SysProcAttr.Setsid = true
c.SysProcAttr.Ctty = int(tty.Fd())
err = c.Start()
if err != nil {
pty.Close()
return nil, err
}
return pty, err
}

+ 50
- 0
vendor/github.com/creack/pty/test_crosscompile.sh View File

@ -0,0 +1,50 @@
#!/usr/bin/env sh
# Test script checking that all expected os/arch compile properly.
# Does not actually test the logic, just the compilation so we make sure we don't break code depending on the lib.
echo2() {
echo $@ >&2
}
trap end 0
end() {
[ "$?" = 0 ] && echo2 "Pass." || (echo2 "Fail."; exit 1)
}
cross() {
os=$1
shift
echo2 "Build for $os."
for arch in $@; do
echo2 " - $os/$arch"
GOOS=$os GOARCH=$arch go build
done
echo2
}
set -e
cross linux amd64 386 arm arm64 ppc64 ppc64le s390x mips mipsle mips64 mips64le
cross darwin amd64 386 arm arm64
cross freebsd amd64 386 arm
cross netbsd amd64 386 arm
cross openbsd amd64 386
cross dragonfly amd64
cross solaris amd64
# Not expected to work but should still compile.
cross windows amd64 386 arm
# TODO: Fix compilation error on openbsd/arm.
# TODO: Merge the solaris PR.
# Some os/arch require a different compiler. Run in docker.
if ! hash docker; then
# If docker is not present, stop here.
return
fi
echo2 "Build for linux."
echo2 " - linux/riscv"
docker build -t test -f Dockerfile.riscv .

+ 64
- 0
vendor/github.com/creack/pty/util.go View File

@ -0,0 +1,64 @@
// +build !windows,!solaris
package pty
import (
"os"
"syscall"
"unsafe"
)
// InheritSize applies the terminal size of pty to tty. This should be run
// in a signal handler for syscall.SIGWINCH to automatically resize the tty when
// the pty receives a window size change notification.
func InheritSize(pty, tty *os.File) error {
size, err := GetsizeFull(pty)
if err != nil {
return err
}
err = Setsize(tty, size)
if err != nil {
return err
}
return nil
}
// Setsize resizes t to s.
func Setsize(t *os.File, ws *Winsize) error {
return windowRectCall(ws, t.Fd(), syscall.TIOCSWINSZ)
}
// GetsizeFull returns the full terminal size description.
func GetsizeFull(t *os.File) (size *Winsize, err error) {
var ws Winsize
err = windowRectCall(&ws, t.Fd(), syscall.TIOCGWINSZ)
return &ws, err
}
// Getsize returns the number of rows (lines) and cols (positions
// in each line) in terminal t.
func Getsize(t *os.File) (rows, cols int, err error) {
ws, err := GetsizeFull(t)
return int(ws.Rows), int(ws.Cols), err
}
// Winsize describes the terminal size.
type Winsize struct {
Rows uint16 // ws_row: Number of rows (in cells)
Cols uint16 // ws_col: Number of columns (in cells)
X uint16 // ws_xpixel: Width in pixels
Y uint16 // ws_ypixel: Height in pixels
}
func windowRectCall(ws *Winsize, fd, a2 uintptr) error {
_, _, errno := syscall.Syscall(
syscall.SYS_IOCTL,
fd,
a2,
uintptr(unsafe.Pointer(ws)),
)
if errno != 0 {
return syscall.Errno(errno)
}
return nil
}

+ 51
- 0
vendor/github.com/creack/pty/util_solaris.go View File

@ -0,0 +1,51 @@
//
package pty
import (
"os"
"golang.org/x/sys/unix"
)
const (
TIOCGWINSZ = 21608 // 'T' << 8 | 104
TIOCSWINSZ = 21607 // 'T' << 8 | 103
)
// Winsize describes the terminal size.
type Winsize struct {
Rows uint16 // ws_row: Number of rows (in cells)
Cols uint16 // ws_col: Number of columns (in cells)
X uint16 // ws_xpixel: Width in pixels
Y uint16 // ws_ypixel: Height in pixels
}
// GetsizeFull returns the full terminal size description.
func GetsizeFull(t *os.File) (size *Winsize, err error) {
var wsz *unix.Winsize
wsz, err = unix.IoctlGetWinsize(int(t.Fd()), TIOCGWINSZ)
if err != nil {
return nil, err
} else {
return &Winsize{wsz.Row, wsz.Col, wsz.Xpixel, wsz.Ypixel}, nil
}
}
// Get Windows Size
func Getsize(t *os.File) (rows, cols int, err error) {
var wsz *unix.Winsize
wsz, err = unix.IoctlGetWinsize(int(t.Fd()), TIOCGWINSZ)
if err != nil {
return 80, 25, err
} else {
return int(wsz.Row), int(wsz.Col), nil
}
}
// Setsize resizes t to s.
func Setsize(t *os.File, ws *Winsize) error {
wsz := unix.Winsize{ws.Rows, ws.Cols, ws.X, ws.Y}
return unix.IoctlSetWinsize(int(t.Fd()), TIOCSWINSZ, &wsz)
}

+ 9
- 0
vendor/github.com/creack/pty/ztypes_386.go View File

@ -0,0 +1,9 @@
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types.go
package pty
type (
_C_int int32
_C_uint uint32
)

+ 9
- 0
vendor/github.com/creack/pty/ztypes_amd64.go View File

@ -0,0 +1,9 @@
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types.go
package pty
type (
_C_int int32
_C_uint uint32
)

+ 9
- 0
vendor/github.com/creack/pty/ztypes_arm.go View File

@ -0,0 +1,9 @@
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types.go
package pty
type (
_C_int int32
_C_uint uint32
)

+ 11
- 0
vendor/github.com/creack/pty/ztypes_arm64.go View File

@ -0,0 +1,11 @@
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types.go
// +build arm64
package pty
type (
_C_int int32
_C_uint uint32
)

+ 14
- 0
vendor/github.com/creack/pty/ztypes_dragonfly_amd64.go View File

@ -0,0 +1,14 @@
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types_dragonfly.go
package pty
const (
_C_SPECNAMELEN = 0x3f
)
type fiodgnameArg struct {
Name *byte
Len uint32
Pad_cgo_0 [4]byte
}

+ 13
- 0
vendor/github.com/creack/pty/ztypes_freebsd_386.go View File

@ -0,0 +1,13 @@
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types_freebsd.go
package pty
const (
_C_SPECNAMELEN = 0x3f
)
type fiodgnameArg struct {
Len int32
Buf *byte
}

+ 14
- 0
vendor/github.com/creack/pty/ztypes_freebsd_amd64.go View File

@ -0,0 +1,14 @@
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types_freebsd.go
package pty
const (
_C_SPECNAMELEN = 0x3f
)
type fiodgnameArg struct {
Len int32
Pad_cgo_0 [4]byte
Buf *byte
}

+ 13
- 0
vendor/github.com/creack/pty/ztypes_freebsd_arm.go View File

@ -0,0 +1,13 @@
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types_freebsd.go
package pty
const (
_C_SPECNAMELEN = 0x3f
)
type fiodgnameArg struct {
Len int32
Buf *byte
}

+ 12
- 0
vendor/github.com/creack/pty/ztypes_mipsx.go View File

@ -0,0 +1,12 @@
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types.go
// +build linux
// +build mips mipsle mips64 mips64le
package pty
type (
_C_int int32
_C_uint uint32
)

+ 13
- 0
vendor/github.com/creack/pty/ztypes_openbsd_386.go View File

@ -0,0 +1,13 @@
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types_openbsd.go
package pty
type ptmget struct {
Cfd int32
Sfd int32
Cn [16]int8
Sn [16]int8
}
var ioctl_PTMGET = 0x40287401

+ 13
- 0
vendor/github.com/creack/pty/ztypes_openbsd_amd64.go View File

@ -0,0 +1,13 @@
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types_openbsd.go
package pty
type ptmget struct {
Cfd int32
Sfd int32
Cn [16]int8
Sn [16]int8
}
var ioctl_PTMGET = 0x40287401

+ 11
- 0
vendor/github.com/creack/pty/ztypes_ppc64.go View File

@ -0,0 +1,11 @@
// +build ppc64
// Created by cgo -godefs - DO NOT EDIT
// cgo -godefs types.go
package pty
type (
_C_int int32
_C_uint uint32
)

+ 11
- 0
vendor/github.com/creack/pty/ztypes_ppc64le.go View File

@ -0,0 +1,11 @@
// +build ppc64le
// Created by cgo -godefs - DO NOT EDIT