Giter Club home page Giter Club logo

console's Introduction

containerd banner light mode containerd banner dark mode

PkgGoDev Build Status Nightlies Go Report Card CII Best Practices Check Links

containerd is an industry-standard container runtime with an emphasis on simplicity, robustness, and portability. It is available as a daemon for Linux and Windows, which can manage the complete container lifecycle of its host system: image transfer and storage, container execution and supervision, low-level storage and network attachments, etc.

containerd is a member of CNCF with 'graduated' status.

containerd is designed to be embedded into a larger system, rather than being used directly by developers or end-users.

architecture

Announcements

Now Recruiting

We are a large inclusive OSS project that is welcoming help of any kind shape or form:

  • Documentation help is needed to make the product easier to consume and extend.
  • We need OSS community outreach/organizing help to get the word out; manage and create messaging and educational content; and help with social media, community forums/groups, and google groups.
  • We are actively inviting new security advisors to join the team.
  • New subprojects are being created, core and non-core that could use additional development help.
  • Each of the containerd projects has a list of issues currently being worked on or that need help resolving.
    • If the issue has not already been assigned to someone or has not made recent progress, and you are interested, please inquire.
    • If you are interested in starting with a smaller/beginner-level issue, look for issues with an exp/beginner tag, for example containerd/containerd beginner issues.

Getting Started

See our documentation on containerd.io:

To get started contributing to containerd, see CONTRIBUTING.

If you are interested in trying out containerd see our example at Getting Started.

Nightly builds

There are nightly builds available for download here. Binaries are generated from main branch every night for Linux and Windows.

Please be aware: nightly builds might have critical bugs, it's not recommended for use in production and no support provided.

Kubernetes (k8s) CI Dashboard Group

The k8s CI dashboard group for containerd contains test results regarding the health of kubernetes when run against main and a number of containerd release branches.

Runtime Requirements

Runtime requirements for containerd are very minimal. Most interactions with the Linux and Windows container feature sets are handled via runc and/or OS-specific libraries (e.g. hcsshim for Microsoft). The current required version of runc is described in RUNC.md.

There are specific features used by containerd core code and snapshotters that will require a minimum kernel version on Linux. With the understood caveat of distro kernel versioning, a reasonable starting point for Linux is a minimum 4.x kernel version.

The overlay filesystem snapshotter, used by default, uses features that were finalized in the 4.x kernel series. If you choose to use btrfs, there may be more flexibility in kernel version (minimum recommended is 3.18), but will require the btrfs kernel module and btrfs tools to be installed on your Linux distribution.

To use Linux checkpoint and restore features, you will need criu installed on your system. See more details in Checkpoint and Restore.

Build requirements for developers are listed in BUILDING.

Supported Registries

Any registry which is compliant with the OCI Distribution Specification is supported by containerd.

For configuring registries, see registry host configuration documentation

Features

Client

containerd offers a full client package to help you integrate containerd into your platform.

import (
  "context"

  containerd "github.com/containerd/containerd/v2/client"
  "github.com/containerd/containerd/v2/pkg/cio"
  "github.com/containerd/containerd/v2/pkg/namespaces"
)


func main() {
	client, err := containerd.New("/run/containerd/containerd.sock")
	defer client.Close()
}

Namespaces

Namespaces allow multiple consumers to use the same containerd without conflicting with each other. It has the benefit of sharing content while maintaining separation with containers and images.

To set a namespace for requests to the API:

context = context.Background()
// create a context for docker
docker = namespaces.WithNamespace(context, "docker")

containerd, err := client.NewContainer(docker, "id")

To set a default namespace on the client:

client, err := containerd.New(address, containerd.WithDefaultNamespace("docker"))

Distribution

// pull an image
image, err := client.Pull(context, "docker.io/library/redis:latest")

// push an image
err := client.Push(context, "docker.io/library/redis:latest", image.Target())

Containers

In containerd, a container is a metadata object. Resources such as an OCI runtime specification, image, root filesystem, and other metadata can be attached to a container.

redis, err := client.NewContainer(context, "redis-master")
defer redis.Delete(context)

OCI Runtime Specification

containerd fully supports the OCI runtime specification for running containers. We have built-in functions to help you generate runtime specifications based on images as well as custom parameters.

You can specify options when creating a container about how to modify the specification.

redis, err := client.NewContainer(context, "redis-master", containerd.WithNewSpec(oci.WithImageConfig(image)))

Root Filesystems

containerd allows you to use overlay or snapshot filesystems with your containers. It comes with built-in support for overlayfs and btrfs.

// pull an image and unpack it into the configured snapshotter
image, err := client.Pull(context, "docker.io/library/redis:latest", containerd.WithPullUnpack)

// allocate a new RW root filesystem for a container based on the image
redis, err := client.NewContainer(context, "redis-master",
	containerd.WithNewSnapshot("redis-rootfs", image),
	containerd.WithNewSpec(oci.WithImageConfig(image)),
)

// use a readonly filesystem with multiple containers
for i := 0; i < 10; i++ {
	id := fmt.Sprintf("id-%s", i)
	container, err := client.NewContainer(ctx, id,
		containerd.WithNewSnapshotView(id, image),
		containerd.WithNewSpec(oci.WithImageConfig(image)),
	)
}

Tasks

Taking a container object and turning it into a runnable process on a system is done by creating a new Task from the container. A task represents the runnable object within containerd.

// create a new task
task, err := redis.NewTask(context, cio.NewCreator(cio.WithStdio))
defer task.Delete(context)

// the task is now running and has a pid that can be used to setup networking
// or other runtime settings outside of containerd
pid := task.Pid()

// start the redis-server process inside the container
err := task.Start(context)

// wait for the task to exit and get the exit status
status, err := task.Wait(context)

Checkpoint and Restore

If you have criu installed on your machine you can checkpoint and restore containers and their tasks. This allows you to clone and/or live migrate containers to other machines.

// checkpoint the task then push it to a registry
checkpoint, err := task.Checkpoint(context)

err := client.Push(context, "myregistry/checkpoints/redis:master", checkpoint)

// on a new machine pull the checkpoint and restore the redis container
checkpoint, err := client.Pull(context, "myregistry/checkpoints/redis:master")

redis, err = client.NewContainer(context, "redis-master", containerd.WithNewSnapshot("redis-rootfs", checkpoint))
defer container.Delete(context)

task, err = redis.NewTask(context, cio.NewCreator(cio.WithStdio), containerd.WithTaskCheckpoint(checkpoint))
defer task.Delete(context)

err := task.Start(context)

Snapshot Plugins

In addition to the built-in Snapshot plugins in containerd, additional external plugins can be configured using GRPC. An external plugin is made available using the configured name and appears as a plugin alongside the built-in ones.

To add an external snapshot plugin, add the plugin to containerd's config file (by default at /etc/containerd/config.toml). The string following proxy_plugin. will be used as the name of the snapshotter and the address should refer to a socket with a GRPC listener serving containerd's Snapshot GRPC API. Remember to restart containerd for any configuration changes to take effect.

[proxy_plugins]
  [proxy_plugins.customsnapshot]
    type = "snapshot"
    address =  "/var/run/mysnapshotter.sock"

See PLUGINS.md for how to create plugins

Releases and API Stability

Please see RELEASES.md for details on versioning and stability of containerd components.

Downloadable 64-bit Intel/AMD binaries of all official releases are available on our releases page.

For other architectures and distribution support, you will find that many Linux distributions package their own containerd and provide it across several architectures, such as Canonical's Ubuntu packaging.

Enabling command auto-completion

Starting with containerd 1.4, the urfave client feature for auto-creation of bash and zsh autocompletion data is enabled. To use the autocomplete feature in a bash shell for example, source the autocomplete/ctr file in your .bashrc, or manually like:

$ source ./contrib/autocomplete/ctr

Distribution of ctr autocomplete for bash and zsh

For bash, copy the contrib/autocomplete/ctr script into /etc/bash_completion.d/ and rename it to ctr. The zsh_autocomplete file is also available and can be used similarly for zsh users.

Provide documentation to users to source this file into their shell if you don't place the autocomplete file in a location where it is automatically loaded for the user's shell environment.

CRI

cri is a containerd plugin implementation of the Kubernetes container runtime interface (CRI). With it, you are able to use containerd as the container runtime for a Kubernetes cluster.

cri

CRI Status

cri is a native plugin of containerd. Since containerd 1.1, the cri plugin is built into the release binaries and enabled by default.

The cri plugin has reached GA status, representing that it is:

See results on the containerd k8s test dashboard

Validating Your cri Setup

A Kubernetes incubator project, cri-tools, includes programs for exercising CRI implementations. More importantly, cri-tools includes the program critest which is used for running CRI Validation Testing.

CRI Guides

Communication

For async communication and long-running discussions please use issues and pull requests on the GitHub repo. This will be the best place to discuss design and implementation.

For sync communication catch us in the #containerd and #containerd-dev Slack channels on Cloud Native Computing Foundation's (CNCF) Slack - cloud-native.slack.com. Everyone is welcome to join and chat. Get Invite to CNCF Slack.

Security audit

Security audits for the containerd project are hosted on our website. Please see the security page at containerd.io for more information.

Reporting security issues

Please follow the instructions at containerd/project

Licenses

The containerd codebase is released under the Apache 2.0 license. The README.md file and files in the "docs" folder are licensed under the Creative Commons Attribution 4.0 International License. You may obtain a copy of the license, titled CC-BY-4.0, at http://creativecommons.org/licenses/by/4.0/.

Project details

containerd is the primary open source project within the broader containerd GitHub organization. However, all projects within the repo have common maintainership, governance, and contributing guidelines which are stored in a project repository commonly for all containerd projects.

Please find all these core project documents, including the:

information in our containerd/project repository.

Adoption

Interested to see who is using containerd? Are you using containerd in a project? Please add yourself via pull request to our ADOPTERS.md file.

console's People

Contributors

akihirosuda avatar austinvazquez avatar crosbymichael avatar davidhsingyuchen avatar dependabot[bot] avatar dmcgowan avatar dqminh avatar epilatow avatar estesp avatar fangn2 avatar fuweid avatar iamleot avatar justincormack avatar kolyshkin avatar ktock avatar kzys avatar mat007 avatar mikebrow avatar mlaventure avatar muesli avatar mxpv avatar najohnsn avatar pmorjan avatar samuelkarp avatar sipsma avatar thajeztah avatar tklauser avatar ulyssessouza avatar unkaktus avatar zhsj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

console's Issues

console.NewPty panics on macOS

macOS Ventura, M1, go 1.20.6, console 1.0.3

A trivial program

package main

import "github.com/containerd/console"

func main() {
	_, _, _ = console.NewPty()
}

Crashes with

% go run cmd/main.go 
runtime: g 1: unexpected return pc for runtime.sigpanic called from 0x0
stack: frame={sp:0x14000070f10, fp:0x14000070f50} stack=[0x14000070000,0x14000071000)
0x0000014000070e10:  0x0000014000070ef0  0x00000140000021a0 
0x0000014000070e20:  0x0000000000000000  0x0000014000070ee8 
0x0000014000070e30:  0x0000000102b2dae8 <runtime.panicmem+0x0000000000000048>  0x0000000020007452 
0x0000014000070e40:  0x0000014000070f04  0xffffffffffffffff 
0x0000014000070e50:  0xffffffffffffffff  0x0000000000000009 
0x0000014000070e60:  0x0000000102b8d210 <libc_ioctl_trampoline+0x0000000000000000>  0x0000014000070e98 
0x0000014000070e70:  0x0000000102b8cf40 <golang.org/x/sys/unix.ioctlPtr+0x00000000000000a0>  0x00000140000021a0 
0x0000014000070e80:  0x0000000000000000  0x0000000000000000 
0x0000014000070e90:  0x0000000000000000  0x0000014000070ed8 
0x0000014000070ea0:  0x0000000102b8d710 <github.com/containerd/console.unlockpt+0x0000000000000060>  0x00000140000021c0 
0x0000014000070eb0:  0x0000000000000000  0x0000000102bbaf40 
0x0000014000070ec0:  0x0000000102c412e0  0x0000000000000000 
0x0000014000070ed0:  0x0000000000000000  0x0000000000000000 
0x0000014000070ee0:  0x0000000000000000  0x0000014000070f08 
0x0000014000070ef0:  0x0000000102b44b38 <runtime.sigpanic+0x0000000000000218>  0x0000000102bbaf40 
0x0000014000070f00:  0x0000000102c412e0  0x0000000000000000 
0x0000014000070f10: <0x0000000000000000  0x0000000000000000 
0x0000014000070f20:  0x0000000000000000  0x0000000000000000 
0x0000014000070f30:  0x0000000000000000  0x0000000000000000 
0x0000014000070f40:  0x00000140000021a0  0x0000000000000000 
0x0000014000070f50: >0x0000000000000000  0x0000000000000000 
0x0000014000070f60:  0x0000000000000000  0x0000000000000000 
0x0000014000070f70:  0x0000000102b5cb54 <runtime.goexit+0x0000000000000004>  0x000001400006a000 
0x0000014000070f80:  0x0000000000000000  0x0000000000000000 
0x0000014000070f90:  0x0000000000000000  0x0100000000000000 
0x0000014000070fa0:  0x0000000000000000  0x0000000102c48c40 
0x0000014000070fb0:  0x0000000102b31c30 <runtime.main.func2+0x0000000000000000>  0x0000014000070f9e 
0x0000014000070fc0:  0x0000014000070fb0  0x0000000000000000 
0x0000014000070fd0:  0x0000000000000000  0x0000000000000000 
0x0000014000070fe0:  0x0000000000000000  0x0000000000000000 
0x0000014000070ff0:  0x0000000000000000  0x0000000000000000 
fatal error: unknown caller pc

runtime stack:
runtime.throw({0x102b8ff13?, 0x102c36060?})
        /opt/homebrew/opt/go/libexec/src/runtime/panic.go:1047 +0x40 fp=0x16d2ff040 sp=0x16d2ff010 pc=0x102b2f4b0
runtime.gentraceback(0x102d98000?, 0x16d2ff3d0?, 0x2b370001873cc434?, 0x140000021a0, 0x0, 0x0, 0x7fffffff, 0x16d2ff410, 0x8124800102b5e12c?, 0x0)
        /opt/homebrew/opt/go/libexec/src/runtime/traceback.go:270 +0x14bc fp=0x16d2ff3b0 sp=0x16d2ff040 pc=0x102b529ac
runtime.addOneOpenDeferFrame.func1()
        /opt/homebrew/opt/go/libexec/src/runtime/panic.go:645 +0x64 fp=0x16d2ff430 sp=0x16d2ff3b0 pc=0x102b2e6c4
runtime.systemstack()
        /opt/homebrew/opt/go/libexec/src/runtime/asm_arm64.s:243 +0x6c fp=0x16d2ff440 sp=0x16d2ff430 pc=0x102b5a70c

goroutine 1 [running]:
runtime.systemstack_switch()
        /opt/homebrew/opt/go/libexec/src/runtime/asm_arm64.s:200 +0x8 fp=0x14000070df0 sp=0x14000070de0 pc=0x102b5a688
runtime.addOneOpenDeferFrame(0x20007452?, 0x14000070f04?, 0xffffffffffffffff?)
        /opt/homebrew/opt/go/libexec/src/runtime/panic.go:644 +0x64 fp=0x14000070e30 sp=0x14000070df0 pc=0x102b2e624
panic({0x102bbaf40, 0x102c412e0})
        /opt/homebrew/opt/go/libexec/src/runtime/panic.go:844 +0xf4 fp=0x14000070ef0 sp=0x14000070e30 pc=0x102b2ee54
runtime.panicmem()
        /opt/homebrew/opt/go/libexec/src/runtime/panic.go:260 +0x48 fp=0x14000070f10 sp=0x14000070ef0 pc=0x102b2dae8
runtime: g 1: unexpected return pc for runtime.sigpanic called from 0x0
stack: frame={sp:0x14000070f10, fp:0x14000070f50} stack=[0x14000070000,0x14000071000)
0x0000014000070e10:  0x0000014000070ef0  0x00000140000021a0 
0x0000014000070e20:  0x0000000000000000  0x0000014000070ee8 
0x0000014000070e30:  0x0000000102b2dae8 <runtime.panicmem+0x0000000000000048>  0x0000000020007452 
0x0000014000070e40:  0x0000014000070f04  0xffffffffffffffff 
0x0000014000070e50:  0xffffffffffffffff  0x0000000000000009 
0x0000014000070e60:  0x0000000102b8d210 <libc_ioctl_trampoline+0x0000000000000000>  0x0000014000070e98 
0x0000014000070e70:  0x0000000102b8cf40 <golang.org/x/sys/unix.ioctlPtr+0x00000000000000a0>  0x00000140000021a0 
0x0000014000070e80:  0x0000000000000000  0x0000000000000000 
0x0000014000070e90:  0x0000000000000000  0x0000014000070ed8 
0x0000014000070ea0:  0x0000000102b8d710 <github.com/containerd/console.unlockpt+0x0000000000000060>  0x00000140000021c0 
0x0000014000070eb0:  0x0000000000000000  0x0000000102bbaf40 
0x0000014000070ec0:  0x0000000102c412e0  0x0000000000000000 
0x0000014000070ed0:  0x0000000000000000  0x0000000000000000 
0x0000014000070ee0:  0x0000000000000000  0x0000014000070f08 
0x0000014000070ef0:  0x0000000102b44b38 <runtime.sigpanic+0x0000000000000218>  0x0000000102bbaf40 
0x0000014000070f00:  0x0000000102c412e0  0x0000000000000000 
0x0000014000070f10: <0x0000000000000000  0x0000000000000000 
0x0000014000070f20:  0x0000000000000000  0x0000000000000000 
0x0000014000070f30:  0x0000000000000000  0x0000000000000000 
0x0000014000070f40:  0x00000140000021a0  0x0000000000000000 
0x0000014000070f50: >0x0000000000000000  0x0000000000000000 
0x0000014000070f60:  0x0000000000000000  0x0000000000000000 
0x0000014000070f70:  0x0000000102b5cb54 <runtime.goexit+0x0000000000000004>  0x000001400006a000 
0x0000014000070f80:  0x0000000000000000  0x0000000000000000 
0x0000014000070f90:  0x0000000000000000  0x0100000000000000 
0x0000014000070fa0:  0x0000000000000000  0x0000000102c48c40 
0x0000014000070fb0:  0x0000000102b31c30 <runtime.main.func2+0x0000000000000000>  0x0000014000070f9e 
0x0000014000070fc0:  0x0000014000070fb0  0x0000000000000000 
0x0000014000070fd0:  0x0000000000000000  0x0000000000000000 
0x0000014000070fe0:  0x0000000000000000  0x0000000000000000 
0x0000014000070ff0:  0x0000000000000000  0x0000000000000000 
runtime.sigpanic()
        /opt/homebrew/opt/go/libexec/src/runtime/signal_unix.go:841 +0x218 fp=0x14000070f50 sp=0x14000070f10 pc=0x102b44b38

goroutine 2 [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        /opt/homebrew/opt/go/libexec/src/runtime/proc.go:381 +0xe4 fp=0x14000044fa0 sp=0x14000044f80 pc=0x102b31f24
runtime.goparkunlock(...)
        /opt/homebrew/opt/go/libexec/src/runtime/proc.go:387
runtime.forcegchelper()
        /opt/homebrew/opt/go/libexec/src/runtime/proc.go:305 +0xb8 fp=0x14000044fd0 sp=0x14000044fa0 pc=0x102b31d68
runtime.goexit()
        /opt/homebrew/opt/go/libexec/src/runtime/asm_arm64.s:1172 +0x4 fp=0x14000044fd0 sp=0x14000044fd0 pc=0x102b5cb54
created by runtime.init.6
        /opt/homebrew/opt/go/libexec/src/runtime/proc.go:293 +0x24

goroutine 3 [GC sweep wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        /opt/homebrew/opt/go/libexec/src/runtime/proc.go:381 +0xe4 fp=0x14000045760 sp=0x14000045740 pc=0x102b31f24
runtime.goparkunlock(...)
        /opt/homebrew/opt/go/libexec/src/runtime/proc.go:387
runtime.bgsweep(0x0?)
        /opt/homebrew/opt/go/libexec/src/runtime/mgcsweep.go:278 +0xa4 fp=0x140000457b0 sp=0x14000045760 pc=0x102b1fb54
runtime.gcenable.func1()
        /opt/homebrew/opt/go/libexec/src/runtime/mgc.go:178 +0x28 fp=0x140000457d0 sp=0x140000457b0 pc=0x102b14908
runtime.goexit()
        /opt/homebrew/opt/go/libexec/src/runtime/asm_arm64.s:1172 +0x4 fp=0x140000457d0 sp=0x140000457d0 pc=0x102b5cb54
created by runtime.gcenable
        /opt/homebrew/opt/go/libexec/src/runtime/mgc.go:178 +0x74

goroutine 4 [GC scavenge wait]:
runtime.gopark(0x1400005a000?, 0x102babf88?, 0x1?, 0x0?, 0x0?)
        /opt/homebrew/opt/go/libexec/src/runtime/proc.go:381 +0xe4 fp=0x14000045f50 sp=0x14000045f30 pc=0x102b31f24
runtime.goparkunlock(...)
        /opt/homebrew/opt/go/libexec/src/runtime/proc.go:387
runtime.(*scavengerState).park(0x102c487c0)
        /opt/homebrew/opt/go/libexec/src/runtime/mgcscavenge.go:400 +0x5c fp=0x14000045f80 sp=0x14000045f50 pc=0x102b1d9dc
runtime.bgscavenge(0x0?)
        /opt/homebrew/opt/go/libexec/src/runtime/mgcscavenge.go:628 +0x44 fp=0x14000045fb0 sp=0x14000045f80 pc=0x102b1df54
runtime.gcenable.func2()
        /opt/homebrew/opt/go/libexec/src/runtime/mgc.go:179 +0x28 fp=0x14000045fd0 sp=0x14000045fb0 pc=0x102b148a8
runtime.goexit()
        /opt/homebrew/opt/go/libexec/src/runtime/asm_arm64.s:1172 +0x4 fp=0x14000045fd0 sp=0x14000045fd0 pc=0x102b5cb54
created by runtime.gcenable
        /opt/homebrew/opt/go/libexec/src/runtime/mgc.go:179 +0xb8

goroutine 5 [finalizer wait]:
runtime.gopark(0x140000445a8?, 0x60000102b127f8?, 0x48?, 0x6a?, 0x1?)
        /opt/homebrew/opt/go/libexec/src/runtime/proc.go:381 +0xe4 fp=0x14000044580 sp=0x14000044560 pc=0x102b31f24
runtime.runfinq()
        /opt/homebrew/opt/go/libexec/src/runtime/mfinal.go:193 +0x10c fp=0x140000447d0 sp=0x14000044580 pc=0x102b1399c
runtime.goexit()
        /opt/homebrew/opt/go/libexec/src/runtime/asm_arm64.s:1172 +0x4 fp=0x140000447d0 sp=0x140000447d0 pc=0x102b5cb54
created by runtime.createfing
        /opt/homebrew/opt/go/libexec/src/runtime/mfinal.go:163 +0x84
exit status 2

Cut a release

It would be nice to have a release cut with #54 so that the users of
this package can remove pkg/errors from their vendoring.

inappropriate ioctl for device

anybody have same issue ?when i try this package in linux ,found it
fork/exec /opt/microsoft/powershell/7/pwsh: inappropriate ioctl for device

windows: Why `initStdios` ignores `GetConsoleMode` errors?

Hey there,
Frankly good designed library.

Specifically I am not aware how golang std works but if it gets its streams using GetStdHandle GetConsoleMode will fail if a stream was redirected.
https://stackoverflow.com/questions/33476316/win32-getconsolemode-error-code-6

GetConsoleMode takes A handle to the console input buffer or the console screen buffer.
https://docs.microsoft.com/en-us/windows/console/getconsolemode

The standard handles of a process may be redirected by a call to SetStdHandle, in which case GetStdHandle returns the redirected handle. If the standard handles have been redirected, you can specify the CONIN$ value in a call to the CreateFile function to get a handle to a console's input buffer. Similarly, you can specify the CONOUT$ value to get a handle to a console's active screen buffer.
https://docs.microsoft.com/en-us/windows/console/getstdhandle

If this is the case it could be handled by oppening CONIN CONOUT. (I am not sure though how SetConsoleMode will work on such handles).

But my point is if GetConsoleMode fails maybe it'd better to return error in newMaster?

func (m *master) initStdios() {
m.in = windows.Handle(os.Stdin.Fd())
if err := windows.GetConsoleMode(m.in, &m.inMode); err == nil {
// Validate that windows.ENABLE_VIRTUAL_TERMINAL_INPUT is supported, but do not set it.
if err = windows.SetConsoleMode(m.in, m.inMode|windows.ENABLE_VIRTUAL_TERMINAL_INPUT); err == nil {
vtInputSupported = true
}
// Unconditionally set the console mode back even on failure because SetConsoleMode
// remembers invalid bits on input handles.
windows.SetConsoleMode(m.in, m.inMode)
} else {
fmt.Printf("failed to get console mode for stdin: %v\n", err)
}
m.out = windows.Handle(os.Stdout.Fd())
if err := windows.GetConsoleMode(m.out, &m.outMode); err == nil {
if err := windows.SetConsoleMode(m.out, m.outMode|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING); err == nil {
m.outMode |= windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING
} else {
windows.SetConsoleMode(m.out, m.outMode)
}
} else {
fmt.Printf("failed to get console mode for stdout: %v\n", err)
}
m.err = windows.Handle(os.Stderr.Fd())
if err := windows.GetConsoleMode(m.err, &m.errMode); err == nil {
if err := windows.SetConsoleMode(m.err, m.errMode|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING); err == nil {
m.errMode |= windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING
} else {
windows.SetConsoleMode(m.err, m.errMode)
}
} else {
fmt.Printf("failed to get console mode for stderr: %v\n", err)
}
}

Thank you.

Windows: stderr output leaks into stdout

I found that on Windows, if a console is generated from stderr, output sent towards the console will go into stdout with extra warning like failed to get console mode for stdout: The handle is invalid.(resovled in 7b7885a).

Verified this with a simple test program in here which simply outputs three messages

// 1. generate console from stderr
c, err := console.ConsoleFromFile(os.Stderr)
if err != nil {
fmt.Println("failed to generate console from stderr", err)
os.Exit(1)
}

// 2. output to stderr, stdout and console
fmt.Fprintln(os.Stderr, "via os.Stderr")
fmt.Fprintln(os.Stdout, "via os.Stdout")
fmt.Fprintln(c, "via stderr console")

In Powershell, the output is like:

> $a=.\console.exe
via os.Stderr     
> $a
failed to get console mode for stdout: The handle is invalid.
via os.Stdout
via stderr console    

The via stderr console log goes wrongly into the variable $a (which should only contain the command's success output stream and stdout output).

As a comparison, below is the behavior of the test program on Zsh(Ubuntu 20.04)

> a=$(./console)
via os.Stderr
via stderr console
> echo $a
via os.Stdout

We can see tht the via stderr console doesn't goes into the stdout output as expected.

Copyright is missing

Dear containerd authors,

I would like to package this library for Debian, however I couldn't find a copyright anywhere. This should be mentioned in the LICENSE file as well, right now the copyright line there is just a template.

console/LICENSE

Line 189 in 45c0279

Copyright [yyyy] [name of copyright owner]

Thanks

ec.Console.Read() return -1 on EAGAIN

console/console_linux.go

Lines 182 to 200 in b5cb846

for {
read, err = ec.Console.Read(p[n:])
n += read
if err != nil {
var hangup bool
if perr, ok := err.(*os.PathError); ok {
hangup = (perr.Err == unix.EAGAIN || perr.Err == unix.EIO)
} else {
hangup = (err == unix.EAGAIN || err == unix.EIO)
}
// if the other end disappear, assume this is temporary and wait for the
// signal to continue again. Unless we didnt read anything and the
// console is already marked as closed then we should exit
if hangup && !(n == 0 && len(p) > 0 && ec.closed) {
ec.readc.Wait()
continue
}
}
break

Hi, I have been implementing a epoll based console in my project while referring to containerd's realisation, and thanks & it has been really helpful.
Yet there's one issue I've encountered during test, when Console is referring to a unix socket, and Read call will return n = -1, err = EAGAIN (refer to https://linux.die.net/man/3/read), and thus resulting in n = -1, which will resulting in panic bcuz index out of range in calling ec.Console.Read(p[n:]) in the next for loop. Should we check if read < 0 in that case? Thanks

Maybe more example ,please?

I'm still confusing about how to use it. I have tried the example. It didn't change the terminal size, just the output?

         current := console.Current()
	defer current.Reset()

	if err := current.SetRaw(); err != nil {
		fmt.Println(err)
	}
	ws, err := current.Size()
	if err != nil {
		fmt.Println(err)
	}
	ws.Height = ws.Height + 300
	ws.Width = ws.Width + 300
	current.Resize(ws)
	fmt.Println(123123)
	fmt.Println("'lorem ext ...asdfafjklas kljasfkjl '")

SetRaw hangs when using exec.Command in linux

I am running a binary using exec.Command which calls SetRaw which is hanging on tcset(m.f.Fd(), &rawState).

When I run my binary in my terminal (not using exec.Command) SetRaw does not hang and things work as expected.

Any thoughts on how to fix this so that I can use exec.Command?

hitting weird error on go get

go version
go version go1.15 darwin/amd64
$ go get -u -v github.com/containerd/console


github.com/containerd/console (download)
github.com/containerd/console
# github.com/containerd/console
go/src/github.com/containerd/console/console_unix.go:31:37: undefined: unix.O_RDWR
go/src/github.com/containerd/console/console_unix.go:31:49: undefined: unix.O_NOCTTY
go/src/github.com/containerd/console/console_unix.go:31:63: undefined: unix.O_CLOEXEC
go/src/github.com/containerd/console/console_unix.go:51:12: undefined: unix.Termios
go/src/github.com/containerd/console/console_unix.go:85:32: undefined: unix.Termios
go/src/github.com/containerd/console/tc_darwin.go:27:13: undefined: unix.TIOCGETA
go/src/github.com/containerd/console/tc_darwin.go:28:13: undefined: unix.TIOCSETA
go/src/github.com/containerd/console/tc_unix.go:25:27: undefined: unix.Termios
go/src/github.com/containerd/console/tc_unix.go:34:27: undefined: unix.Termios
go/src/github.com/containerd/console/tc_unix.go:81:18: undefined: unix.Termios
go/src/github.com/containerd/console/console_unix.go:31:63: too many errors

related to gofiber/cli#38

New release request

Can we get a new release so we can get recent changes into vendored packages?

Thanks!

Restore Solaris and Illumos support?

fa15abf in #62 removed Solaris and Illumos support with the justification "The solaris implementation is not used anywhere, and removed from most projects, so we may as well clean up the corresponding files here."

Downsteam projects that use containerd/consle, e.g. github.com/charmbracelet/bubbletea with 18k GitHub stars do rely on containerd/console's Solaris and Illumos support.

Is there any reason not to restore support for these OSes?

Refs charmbracelet/bubbletea#737
Refs twpayne/chezmoi#2983

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.