From: schwarze Date: Fri, 13 Aug 2021 10:56:54 +0000 (+0000) Subject: During line editing, let Ctrl-C discard the current input line and X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a93de8ed3aee4e99049f40b75a27773855bc1f29;p=openbsd During line editing, let Ctrl-C discard the current input line and provide a fresh prompt instead of exiting the program. This aligns behaviour with bc(1), ftp(1), sftp(1), and all the shells. OK naddy@ Both martijn@ and naddy@ point out that this program might profit from signal handling during more of its code, but that would require more code inspection, design work, and testing which i'm not planning to do right now. Consider standard behaviour during line editing as a first step. --- diff --git a/usr.bin/cdio/cdio.c b/usr.bin/cdio/cdio.c index 0f824662d92..642900a0b59 100644 --- a/usr.bin/cdio/cdio.c +++ b/usr.bin/cdio/cdio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cdio.c,v 1.80 2021/01/18 00:44:00 mortimer Exp $ */ +/* $OpenBSD: cdio.c,v 1.81 2021/08/13 10:56:54 schwarze Exp $ */ /* Copyright (c) 1995 Serge V. Vakulenko * All rights reserved. @@ -63,6 +63,7 @@ #include #include #include +#include #include #include #include @@ -158,6 +159,7 @@ int verbose = 1; int msf = 1; const char *cddb_host; char **track_names; +volatile sig_atomic_t signo; EditLine *el = NULL; /* line-editing structure */ History *hist = NULL; /* line-editing history */ @@ -179,6 +181,7 @@ int pstatus(char *arg); int play_next(char *arg); int play_prev(char *arg); int play_same(char *arg); +void sigint_handler(int); char *input(int *); char *prompt(void); void prtrack(struct cd_toc_entry *e, int lastflag, char *name); @@ -1499,18 +1502,36 @@ status(int *trk, int *min, int *sec, int *frame) return s.data->header.audio_status; } +void +sigint_handler(int signo_arg) +{ + signo = signo_arg; +} + char * input(int *cmd) { + struct sigaction sa; char *buf; int siz = 0; char *p; HistEvent hev; + memset(&sa, 0, sizeof(sa)); do { - if ((buf = (char *) el_gets(el, &siz)) == NULL || !siz) { - *cmd = CMD_QUIT; + signo = 0; + sa.sa_handler = sigint_handler; + if (sigaction(SIGINT, &sa, NULL) == -1) + err(1, "sigaction"); + buf = (char *)el_gets(el, &siz); + sa.sa_handler = SIG_DFL; + if (sigaction(SIGINT, &sa, NULL) == -1) + err(1, "sigaction"); + if (buf == NULL || siz <= 0) { fprintf(stderr, "\r\n"); + if (siz < 0 && errno == EINTR && signo == SIGINT) + continue; + *cmd = CMD_QUIT; return (0); } if (strlen(buf) > 1)