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 14663 invoked from network); 13 Feb 2022 09:57:52 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 13 Feb 2022 09:57:52 -0000 Received: (qmail 19775 invoked by uid 550); 13 Feb 2022 09:57: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 19740 invoked from network); 13 Feb 2022 09:57:46 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1644746255; bh=0738E/o4X7QzDBlPJSjLrcEHAxbkKuUqxOr++OssJro=; h=X-UI-Sender-Class:Date:From:To:Cc:Subject:References:In-Reply-To; b=fxWQo7hta6RmkgjYCIzGI+DOHlCYrCVZnR+MM9Z45Ir7gHTUWFFB8EkZ608j+cjCr KTxnGOroZ0r/yaIq8qmys3PgS5c1zCFe/sNjLW2z9YmWANmUx+iglaH/AdBTnyN7tL nvhsnMAn0xx0Y+G5k0H2eRaxogDvc/lc9g2+GFGs= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Date: Sun, 13 Feb 2022 10:57:33 +0100 From: Markus Wichmann To: musl@lists.openwall.com Cc: Yuri Kanivetsky Message-ID: <20220213095733.GC8426@voyager> References: <20220211155441.GG7074@brightrain.aerifal.cx> <20220212103356.GB8426@voyager> <20220212150525.GH7074@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-Provags-ID: V03:K1:GIF1hRIMrQDecqblONQV6zGdPM6B/D9cPAaKvPifQO6sXVe00uG GKuxO0ErYCDneKoqWHlT9gevvoDwU96FgGfNuNLfxIRZsdZ1EWnghJBw+CUaAGxsalvZVzl 1O/vt7wqIred+yAIvBuHQcyurXo5uJ8M5SVpzrX63931Oy0sgOnyDo5DOHJd2qHGTsvirPE 3otmvZ0isMVTugsl37n3A== X-UI-Out-Filterresults: notjunk:1;V03:K0:peTTqh8fBSg=:c3Hvu9Ja68Wvpssk9hjS2j qIH6gabw9qSmjWANcV+m5Cwpo1Tlro+u5b343veQXipGLtlGtTHwQzxamiBteEvsIDDo+Urjf JVNudsFNe5+EfXJCOHgIQ51RH3v3a/CXB2f3Sl8rZUVAMwLPgWHvh+XcNN/q1X5TsIVEhjFy9 7DlDeLfYAFjsuHqb0kTQCI1k576Ei3TlBNnfp658LLbDCIIuaMWo9cisfO+TnpnpKhcHDCu6G zE8KgQ8Xijf7r5R/koRLtdwqs/gx1H1B20zVAheujmpYZ66LGCAOlCKRguGx1lMEPP0Y6fXus ovwfCRBkXqkYfxbgGfKZiM007CUUmDM5xqXGV7hg5D1mFWPhtURuaHyEsoUdGgF+Lc5SPZNGf J6xfaRxgdQGuH/KqIVkZ9rFuyknreqORQsLx3HMfQvpqGV7lCwkkOVPNdI9GN6mkBEvXsVWfG 57J/mt5STItDoogKD/2pVVjP5I7M99VASQE6jBfGYj8HI74RKQljYr8DWVGsNpGH26s23IpF7 ZZoQzcVlX2jlHLR+JjuiWXJeqF01+ClcBUpu2ht+LrOYKIOMY27hAGKCI1eUv4RAxUge+g59t SnxCN4d2AYQSqWe/Hh/BhmCM2BIRzJCuKXSush8bznvfziWKz8Nt4Q3NjsV4HhQhh87rjFTtI vnsRiNEpF0pdzNnpxPv1yHtYU797lg10wEvmI8iE2KzbhOthIzx0j41SUP00xQQLPslEBMfUd ytMteruIjbqaIZM7iKJjUbamlzNCYfrXUErMMTeVZ898UQTjJL4uk6mUSn5IAkp0XY21D+2lQ 6zP+wI6KAjyJOmNYDX7rz4KkC7AGL04V8Kf6aOtsLEkHxn8iLcgF2TCauhb+6mG6jTtW5NgMh /L5tWNJwvTmW379ZZBIzkq9l4sTo0oce9C1pPhKf/hplkjjIuVjkFVrslknvH//o+zISHrrvs NltOc0KFmJfNw3pg6r8dYZidzxWdmQy1MatTOUCcGRKNrhC+xemVdK8GNpCnG/vWA5xFKrPEy D412XChqsaN1G/N1Mv6AEwMZtpLGbzN4pQetpxExx3WGitxeCfeb+bWECvgC+j7iZN8FI9qAP 8eT3Lgmlw6siXQ= Content-Transfer-Encoding: quoted-printable Subject: Re: [musl] What determines the TERM variable value? On Sun, Feb 13, 2022 at 10:54:23AM +0200, Yuri Kanivetsky wrote: > I don't think it's configurable in a common sense: > > https://github.com/moby/moby/blob/v20.10.12/container/container.go#L752 > Oh bloody hell. All this complexity, and this is the part they choose to make fixed? > But you can do: > > $ docker run --rm -it -e TERM=3Dxterm-256color alpine > / # echo $TERM > xterm-256color > Yes, as I said, anyone can change TERM. > 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). > Slightly off. It does create a PTY, and then translates what it receives from it to things that are displayed on screen, speaking a certain language. It also translates all user inputs into sequences to send back to the terminal application. And the file that describes these sequences in both directions is the terminfo database. TERM is used to locate the terminfo database. As long as you set TERM to something you have the database for, and the sequences described in the database match (for the most part) the ones the terminal uses, things will work out. Bear in mind that most terminals are very similar to each other and use VT102-style escape sequences. They differ in the fine details. You can use infocmp not only to print your own terminal's info, but also to compare it with other terminals. Doing that on screen and xterm, there are a lot of differences, but a lot of it is just xterm defining keys that you don't have anyway (F13-F63 you probably only have if your keyboard is used to control a nuclear power station, for example). > Then there are some programs like screen and tmux, that are not > strictly terminal emulators, but in a way they are. They do translate user inputs into sequences and program outputs into screen displays. It's just that they do so while being TUI applications themselves. The point I was making with the Linux VTs is that the concept is not tethered to any given GUI, or any GUI, for that matter. > https://github.com/moby/moby/commit/c85db1003b#diff-14bacfb63a209323729a= f295c64c9bb978c84e810d18e3e7b7ae66d9b3cd7acaR259 > I tend to argue against comments a lot. Most of the time they do not add, and often take away from the important stuff. But if, like here, you do something questionable, and you don't have a comment, and you don't have a commit message saying the reason, I really do want something. > 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. > Yes. And if not, arrange for it to be installed. It isn't hard. For administrators, installing a new terminfo file is low-risk, since it can only ever possibly screw over the user that requested it, and all others would have to opt into using it. > 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? > You also want certain kernel interfaces to work. In case of SSH, there is an encrypted TCP tunnel between the application and the client terminal. So everything the user types must be encrypted and sent up, and everything the application sends must be encrypted and sent down. So what should the standard file descriptors in the process on the server be? They can't be the socket directly, then nothing would be translated. And if they were pipes, they would not get treated as terminals. Many terminal applications make a distinction whether isatty() works on the standard file descriptors. And that is true for PTYs, as well as VTs and serial lines, but not for pipes or sockets. That TERM is set does not say anything about what FD 0 is connected to. Ciao, Markus