commit 4cacb626a0210c5a8b26ebe90caa1e3f27e80789
parent e3e81879b1fa27a7b55ed5b856b9caf22011765c
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Fri, 24 May 2019 10:39:33 +0200
files: allow to interrupt the opening of a FIFO with Ctrl+C
With-help-from: Brand Huntsman <alpha@qzx.com>
Diffstat:
2 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/src/files.c b/src/files.c
@@ -889,6 +889,10 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
#endif
}
+/* An empty handler for a keyboard interrupt (SIGINT). */
+RETSIGTYPE noop(int signal)
+{}
+
/* Open the file with the given name. If the file does not exist, display
* "New File" if newfie is TRUE, and say "File not found" otherwise.
* Return -2 if we say "New File", -1 if the file isn't opened, and the
@@ -896,6 +900,7 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
int open_file(const char *filename, bool newfie, bool quiet, FILE **f)
{
struct stat fileinfo, fileinfo2;
+ struct sigaction oldaction, newaction;
int fd;
char *full_filename = get_full_path(filename);
@@ -931,9 +936,21 @@ int open_file(const char *filename, bool newfie, bool quiet, FILE **f)
if (S_ISFIFO(fileinfo.st_mode))
statusbar(_("Reading from FIFO..."));
+#ifndef NANO_TINY
+ newaction.sa_handler = noop;
+ newaction.sa_flags = 0;
+ sigaction(SIGINT, &newaction, &oldaction);
+ enable_signals();
+#endif
+
/* Try opening the file. */
fd = open(full_filename, O_RDONLY);
+#ifndef NANO_TINY
+ disable_signals();
+ sigaction(SIGINT, &oldaction, NULL);
+#endif
+
if (fd == -1)
statusline(ALERT, _("Error reading %s: %s"), filename, strerror(errno));
else {
diff --git a/src/proto.h b/src/proto.h
@@ -425,6 +425,7 @@ void block_sigwinch(bool blockit);
RETSIGTYPE handle_sigwinch(int signal);
void regenerate_screen(void);
void do_toggle(int flag);
+void disable_signals(void);
void enable_signals(void);
#endif
void disable_flow_control(void);