-/* $OpenBSD: ed.h,v 1.22 2016/03/27 00:43:38 mmcc Exp $ */
+/* $OpenBSD: ed.h,v 1.23 2024/07/16 05:01:10 deraadt Exp $ */
/* $NetBSD: ed.h,v 1.23 1995/03/21 09:04:40 cgd Exp $ */
/* ed.h: type and constant definitions for the ed editor. */
#define SPL0() \
do { \
if (--mutex == 0) { \
- if (sighup) \
- handle_hup(SIGHUP); \
if (sigint) \
handle_int(SIGINT); \
} \
int get_line_node_addr(line_t *);
char *get_sbuf_line(line_t *);
int get_tty_line(void);
-void handle_hup(int);
+void handle_hup(void);
void handle_int(int);
int has_trailing_escape(char *, char *);
void init_buffers(void);
-/* $OpenBSD: io.c,v 1.25 2022/11/18 14:52:03 millert Exp $ */
+/* $OpenBSD: io.c,v 1.26 2024/07/16 05:01:10 deraadt Exp $ */
/* $NetBSD: io.c,v 1.2 1995/03/21 09:04:43 cgd Exp $ */
/* io.c: This file contains the i/o routines for the ed line editor */
#include <regex.h>
#include <signal.h>
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int i = 0;
int c;
- for (;;)
+ for (;;) {
+ if (sighup)
+ handle_hup();
switch (c = getchar()) {
default:
oi = 0;
ibufp = ibuf;
return i;
case EOF:
+ if (sighup)
+ handle_hup();
if (ferror(stdin)) {
perror("stdin");
seterrmsg("cannot read stdin");
return i;
}
}
+ }
}
-/* $OpenBSD: main.c,v 1.68 2022/11/18 14:52:03 millert Exp $ */
+/* $OpenBSD: main.c,v 1.69 2024/07/16 05:01:10 deraadt Exp $ */
/* $NetBSD: main.c,v 1.3 1995/03/21 09:04:44 cgd Exp $ */
/* main.c: This file contains the main control and user-interface routines
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/wait.h>
+#include <unistd.h>
#include <ctype.h>
#include <err.h>
signal(SIGWINCH, handle_winch);
}
signal(SIGHUP, signal_hup);
+ siginterrupt(SIGHUP, 1);
signal(SIGQUIT, SIG_IGN);
signal(SIGINT, signal_int);
if (sigsetjmp(env, 1)) {
void
signal_hup(int signo)
{
- int save_errno = errno;
-
- if (mutex)
- sighup = 1;
- else
- handle_hup(signo);
- errno = save_errno;
+ sighup = 1;
}
void
signal_int(int signo)
{
- int save_errno = errno;
-
if (mutex)
sigint = 1;
else
- handle_int(signo);
- errno = save_errno;
+ handle_int(signo); /* XXX quite unsafe */
}
void
-handle_hup(int signo)
+handle_hup(void)
{
char hup[PATH_MAX];
- if (!sigactive)
- quit(1); /* XXX signal race */
+ signal(SIGHUP, SIG_IGN);
sighup = 0;
- /* XXX signal race */
if (addr_last && write_file("ed.hup", "w", 1, addr_last) < 0 &&
home != NULL && home[0] == '/') {
if (strlcpy(hup, home, sizeof(hup)) < sizeof(hup) &&
strlcat(hup, "/ed.hup", sizeof(hup)) < sizeof(hup))
write_file(hup, "w", 1, addr_last);
}
- _exit(2);
+ exit(2);
}