Hi, I found the issue based on this post: https://stackoverflow.com/questions/10274730/how-to-get-around-no-backspace-when-icanon-in-non-canonical
This was missing: raw.c_cc[VTIME] = 0; raw.c_cc[VMIN] = 1; Thank all -----Original Message----- From: screen-users-bounces+mpresseau=rheinmetall...@gnu.org <screen-users-bounces+mpresseau=rheinmetall...@gnu.org> On Behalf Of Presseau, Michael Sent: April 28, 2025 8:34 AM To: noloa...@gmail.com Cc: screen-users@gnu.org Subject: RE: scanf failling with ICANON mode when in daemon mode (screen -dmS) Hi Jeffrey, Thank for your answer but there is no change in behavior when TCSANOW is add. -----Original Message----- From: Jeffrey Walton <noloa...@gmail.com> Sent: April 25, 2025 5:29 PM To: Presseau, Michael <mpress...@rheinmetall.ca> Cc: screen-users@gnu.org Subject: Re: scanf failling with ICANON mode when in daemon mode (screen -dmS) On Fri, Apr 25, 2025 at 5:11 PM Presseau, Michael <mpress...@rheinmetall.ca> wrote: > > Hi, > > > > I have done my own application console with scanf(). When I run in the screen > (screen -mS test ./test), it work as expected with each characters printed. > But when I run it in screen as daemon, it's failing in loop: > > $ screen -dmS test ./test > > $ screen -r test > > > > stdin_thread scanf failed! ret: -1 > > stdin_thread scanf failed! ret: -1 > > > > Do you have any clue on how I can make this work in deamon mode? > > > > Here is my sample code: > > ``` > > #include <stdio.h> > > #include <errno.h> > > #include <termios.h> > > #include <unistd.h> > > > > void enableRawMode() > > { > > #ifdef __linux__ > > struct termios raw; > > > > // Get current terminal attributes > > tcgetattr(STDIN_FILENO, &raw); > > > > // Modify terminal attributes for raw mode > > raw.c_lflag &= ~(ECHO | ICANON); > > > > // Set modified attributes > > tcsetattr(STDIN_FILENO, TCSAFLUSH, &raw); > > #endif > > } > > > > int main() { > > enableRawMode(); > > > > char c; > > while (1) { > > int ret = scanf("%c", &c); > > if ( ret > 0) { > > printf("%c", c); > > } else { > > printf("stdin_thread > scanf failed! ret: %d\n", ret); > > } > > } > > return 0; > > } > > ``` Maybe you need a call to: if (tcsetattr(fd, TCSANOW, &tty) != 0) { log_error("term_config: tcsetattr: %s\n", strerror(errno)); return errno; } to ensure the changes to the terminal are applied immediately. Jeff