From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 4129 invoked from network); 13 Feb 2022 08:54:50 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 13 Feb 2022 08:54:50 -0000 Received: (qmail 20174 invoked by uid 550); 13 Feb 2022 08:54:47 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 20139 invoked from network); 13 Feb 2022 08:54:46 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=d4SsyjVfHsMZ8cysMIwSROF8HppUpl/kFUOVXqAobt0=; b=G81JSeqSb4+R3EL395KA/r5Ii+MMxByrQVa5RRee0ExCdk39K1pB4L7HsJsWZ3YcT1 aKq0pgJ/0q01XDpnu5jcqoUqSd/IlHx13R+PwcGDuQ8Ikj+PK6JfRvW5BT7XBucq/l31 owG8S7qbQJMUYQ+ftH/1kmGVFEkr1WjwZHVyt2XKlDew0psNWYeX20Cle5A+2VffhdVc ffCeLFPSlHg/ilCAQgVdYH5MhigT4nfyZ4dIsXU4ysZ48DhOEQJ5HNh5CaAVGgIpLlw1 XVxQncbNxppSKNdVwdL/LmbMz/bXhHGrKqkrDJVX06Q6nfrJYVyXPQZMauS8zZOnGotp FY9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=d4SsyjVfHsMZ8cysMIwSROF8HppUpl/kFUOVXqAobt0=; b=KarqAPB8KjoMTdhsbnfREmVAud1BOE0OAhBlkSaXTPRCLdJciHb0o3AAKM16LnwP32 HGwc2Q7u6lshS13+Thdtyelan44VRmjruNanv42BiPxd4VrdHu+SIXNouc5IEJCTpcFT 2OUlDX1wnSbJZsvHq0poEHCX2kzY4OeTiSPx0A2/hDRQ3TacTr1F9mWj9OjKX9SfNr4G BFZ+OPubUfhSVDJ/vh1JjnDdIKrAf08QQTHxgeib6yZXrW13iVEof3p+9cWY8F+wTb9j 12PaFUh79B855ZYari2p74LtgOjOK0BCZ9n9aubEbWO5lZjTMnQFTMMkKm4zVIC3Urh2 Bf6A== X-Gm-Message-State: AOAM531P4T/g9GMsbdMuGufHytdkQCpnfHeRyYnKh1uyoH4bdLuA0iYC jh69m6jv5JamG+27EIfZRqAFX5z6R2q8zOVMzg== X-Google-Smtp-Source: ABdhPJzrAlmJVh9IYKs2VsEv9Y5jCFT0iQSVYoNZpbsbZUemX+Ty/7vwvTy5Hw4KtV7gbymF2f4W6zuRIXJAXsR1GwU= X-Received: by 2002:a17:902:ef4e:: with SMTP id e14mr9032499plx.125.1644742474260; Sun, 13 Feb 2022 00:54:34 -0800 (PST) MIME-Version: 1.0 References: <20220211155441.GG7074@brightrain.aerifal.cx> <20220212103356.GB8426@voyager> <20220212150525.GH7074@brightrain.aerifal.cx> In-Reply-To: <20220212150525.GH7074@brightrain.aerifal.cx> From: Yuri Kanivetsky Date: Sun, 13 Feb 2022 10:54:23 +0200 Message-ID: To: Rich Felker Cc: Markus Wichmann , musl@lists.openwall.com Content-Type: text/plain; charset="UTF-8" Subject: Re: [musl] What determines the TERM variable value? I don't think it's configurable in a common sense: https://github.com/moby/moby/blob/v20.10.12/container/container.go#L752 But you can do: $ docker run --rm -it -e TERM=xterm-256color alpine / # echo $TERM xterm-256color So, to sum it up, a terminal emulator is a program (let's not bring up virtual consoles here) that emulates a terminal. It creates a pty (a master/slave pair), drawing in a window what it receives from the pty, and sending what user types to the pty. It also processes some escape sequences it receives from the pty, and transforms some user keystrokes into escape sequences before sending them to the pty. And that determines the TERM variable value (for it to work correctly you've got to have it set to a correct value). Then there are some programs like screen and tmux, that are not strictly terminal emulators, but in a way they are. They also create a pty, and translate escape sequences from the "language" they understand to the "language" understood by what's up the chain (according to TERM), and vice versa. And again you've got to keep TERM to a fixed range of values for it to work correctly. Then there're some programs like ssh that create a pty, but doesn't change TERM. And programs like docker that create a pty, but change TERM. https://github.com/moby/moby/commit/c85db1003b#diff-14bacfb63a209323729af295c64c9bb978c84e810d18e3e7b7ae66d9b3cd7acaR259 Most likely to be user friendly. To make it work automagically for users with an uncommon TERM value. I'd say it makes it more confusing this way, but well, probably not everybody would agree. So, basically with programs like ssh and docker, you generally want to keep TERM unchanged. Granted that the corresponding terminfo entry exists on a server/in a container. But why would a program like ssh or docker want to create a pty in the first place? If a pty on its own is just a data channel, then they could just pass data as is, letting a terminal emulator handle things. Isn't having TERM set enough for the programs down the chain to see that they're connected to a terminal? On Sat, Feb 12, 2022 at 5:05 PM Rich Felker wrote: > > On Sat, Feb 12, 2022 at 11:33:56AM +0100, Markus Wichmann wrote: > > On Sat, Feb 12, 2022 at 11:34:52AM +0200, Yuri Kanivetsky wrote: > > > So, a program is a terminal emulator if it translates escape sequences > > > in both directions? And if it, as a result, changes the TERM variable? > > > > > > > A program is a terminal emulator if it emulates a terminal, i.e. > > provides an interface for TUI applications to interact with a keyboard > > and screen (and optionally a mouse). The Linux VT provides such a thing > > directly, X11 applications like xterm do so via the X11 protocol. Screen > > and tmux are men in the middle, implementing screen and keyboard via > > another terminal emulator. But still, they are terminal emulators. > > > > The TERM variable is not somehow especially protected. Any process can > > change it at any time, and it will remain changed for that process and > > any child processes until one of those decides to change it again. To > > wit: > > > > > What seems strange to me is that docker changes the TERM variable: > > > > > > $ echo $TERM > > > screen-256color > > > > > > $ docker run --rm -it alpine > > > / # echo $TERM > > > xterm > > > > > > > Anyone can change the TERM variable, including docker. I think, they > > assume that xterm is a least common denominator among terminal > > emulators. Also, the xterm terminfo is most likely to be installed in > > whatever container you are running. > > If that's what's happening, Docker is just wrong to be doing this. > xterm is one of the most over-featured terminals out there, and the > terminfo for it reflects that. TERM=xterm is not likely to actually > work for most terminals if the application actually tries to make use > of any of the advanced features (though it might appear to work as > long as they stick to basics). > > The appropriate TERM setting for a minimal common denominator where > you don't know the actual terminal type is probably something like > vt102 or vt220. But really Docker just shouldn't munge it. > > > That said, docker is a highly flexible piece of software, so I would be > > surprised if this functionality was not configurable somehow. > > Yeah, it's probably configurable. > > Rich