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=-1.0 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 5856 invoked from network); 23 Jun 2020 01:40:37 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 23 Jun 2020 01:40:37 -0000 Received: (qmail 10529 invoked by alias); 23 Jun 2020 01:40:28 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: Sender: zsh-workers@zsh.org X-Seq: 46100 Received: (qmail 14517 invoked by uid 1010); 23 Jun 2020 01:40:28 -0000 X-Qmail-Scanner-Diagnostics: from mail-wm1-f45.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25850. spamassassin: 3.4.4. Clear:RC:0(209.85.128.45):SA:0(-2.0/5.0):. Processed in 1.517083 secs); 23 Jun 2020 01:40:28 -0000 X-Envelope-From: godmar@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.128.45 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=74f5NeA6jY7kWJi4GMRPKtSjzUVc8PxmApxIWXMZAXQ=; b=o8kD01wFj8u6dLlmAi4EfpAh4CbEEQYhlJ4gx4nDvZ/jWyAc+MWo+cPwl1rY01dAkI 2XjWl9AHzXKJvU1VNxaiKcVU9UK4SNcu2+JfpJnVOxxnyzmTVEkRJzxZvDVJa2y7tCdb Y6abgxWqm/Yk/g4pBtmBOwMPm9oiAwWPlA3wWjkqi02FtlrAhRNwIAaWpwoOgF9dQepS jCOfc4uf1+UIGGStFg2JPYZqWx5Ix9QtcK49jhj+Ri3lpW4j33gM1l8B1P7N5AM/aehV 2hSxsk9m5rlzmDj2R1KCRJ7EIaIVuxXHeqfeNJRrJkzFSisMhGvMpf8pM9gd4MK/uip7 aiWw== X-Gm-Message-State: AOAM532epbBjlxDYDSrJEEhZfGEEdug30Vlyt5pWnnZdK4mF3E453Rgy ZYY82kgJwmpmmU4DDnnDksiwuKfwxDzzDboIDW6P5tZPxag= X-Google-Smtp-Source: ABdhPJyUQJntEoLQcC4qo3u4vOSpeIOiPMbw6XxVjAUq4F2bDrtqgSZGLGuZeSjzXbiArzE3vvOpAgQz4pVUAWJN2oM= X-Received: by 2002:a7b:cd83:: with SMTP id y3mr21005052wmj.5.1592876391825; Mon, 22 Jun 2020 18:39:51 -0700 (PDT) MIME-Version: 1.0 From: Godmar Back Date: Mon, 22 Jun 2020 21:39:40 -0400 Message-ID: Subject: support for POSIX job control terminal management in zsh To: zsh-workers@zsh.org Content-Type: text/plain; charset="UTF-8" Hi, I noticed that zsh does not implement POSIX.1 when it comes to saving/restoring the terminal state of processes suspended with SIGTSTP. (The same applies to bash, btw, but not to ksh.) Shells like tcsh or ash/dash also do not implement it. POSIX.1 asks that: "When a foreground (not background) job stops, the shell must sample and remember the current terminal settings so that it can restore them later when it continues the stopped job in the foreground (via the tcgetattr( ) and tcsetattr( ) functions)." Consequently, a program such as the one attached below should not fail any assertions. However, it does not appear to work when run under zsh. I've had an illuminating discussion with Chet Ramey, the author of bash, regarding bash's behavior. He pointed out that applications historically could never rely on the shell provided job control in a manner that they could be oblivious to being suspended/resumed, and therefore always had to handle the saving/restoring of the terminal state upon suspend/restore themselves, rather than relying on the job control shell as POSIX asks. Still, at least one shell (ksh) does appear to implement it. Hence my question, out of curiosity, is: why does zsh not follow POSIX.1 semantics in this regard? Thanks. - Godmar // ts_test.c /* Test that terminal state is properly restored when a process is stopped and restored. */ #include #include #include #include #include #include #define CTRL_D 4 #define CTRL_E 5 int main() { int terminal_fd = open(ctermid(NULL), O_RDWR); assert (terminal_fd != -1); // Step 1. make a change to the terminal state: // change VEOF from Ctrl-D to Ctrl-E struct termios saved_tty_state; int rc = tcgetattr(terminal_fd, &saved_tty_state); assert (rc == 0); assert (saved_tty_state.c_cc[VEOF] == CTRL_D); // ^D saved_tty_state.c_cc[VEOF] = CTRL_E; // ^E rc = tcsetattr(terminal_fd, TCSANOW, &saved_tty_state); assert (rc == 0); // Step 2. Suspend and let user resume printf("This job should now stop, please run 'fg' to continue it\n"); raise(SIGTSTP); printf("Job now continuing...\n"); // Step 3. // Expect that job control shell saved the terminal state rc = tcgetattr(terminal_fd, &saved_tty_state); assert (rc == 0); if (saved_tty_state.c_cc[VEOF] != CTRL_E) { printf("I expected a POSIX job control shell to preserve my terminal settings\n"); printf("VEOF was not saved, it is %d...\n", saved_tty_state.c_cc[VEOF]); } assert (saved_tty_state.c_cc[VEOF] == CTRL_E); // ^E }