Package: libreadline7
Version: 7.0-5
Severity: normal

Dear Maintainer,

I'm writing a readline program which handles CTRL-C (SIGINT). I call
rl_set_signals() and verify with strace that readline installs a
signal handler for SIGINT. But, pressing CTRL-C still terminates my
program. Here is a reproducible example:

  #include <stdio.h>
  #include <stdlib.h>
  
  #include <readline/readline.h>
  
  int main(int argc, char** argv) {
    printf("pressing ctrl-c should not exit this program.\n");
  
    rl_catch_signals = 1;
    rl_set_signals();
  
    rl_bind_key('\t', rl_insert);
  
    char *buf;
    while((buf = readline(">> ")) != NULL) {
      printf("[%s]\n", buf);
      free(buf);
    }
    return 0;
  }

I modified readline 8.0 source as follows. I managed to make CTRL-C
do nothing, but the expected behaviour (readline aborts the current
line and starts a new one) still doesn't occur.

*** orig/readline-8.0/signals.c 2018-03-28 16:23:45.000000000 -0400
--- new/readline-8.0/signals.c  2019-03-26 17:50:45.201930497 -0400
***************
*** 215,224 ****
--- 215,225 ----
        _rl_reset_completion_state ();
        rl_free_line_state ();
  #if defined (READLINE_CALLBACKS)
        rl_callback_sigcleanup ();
  #endif
+       break;
  
        /* FALLTHROUGH */
  
  #if defined (SIGTSTP)
      case SIGTSTP:


It's possible that this is expected behaviour, but I assume that pressing
CTRL-C should not terminate a readline program. This assumption is backed
up by existing materials on readline, e.g.
https://lists.gnu.org/archive/html/bug-readline/2016-04/msg00071.html

I suspect this may be a regression since the behaviour was different in
the past. Tested on readline 7 and 8 to similar effect. P.S. Programs like
bash or gdb still trap CTRL-C properly.

-- System Information:
Debian Release: buster/sid
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: amd64 (x86_64)

Kernel: Linux 4.19.0-1-amd64 (SMP w/8 CPU cores)
Locale: LANG=en_US.utf8, LC_CTYPE=en_US.utf8 (charmap=UTF-8), 
LANGUAGE=en_US.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages libreadline7 depends on:
ii  libc6            2.28-2
ii  libtinfo6        6.1+20181013-2
ii  readline-common  7.0-3

libreadline7 recommends no packages.

libreadline7 suggests no packages.

-- no debconf information

Reply via email to