mirror of
https://github.com/sheumann/hush.git
synced 2025-01-15 18:30:43 +00:00
vi: don't wait 50 ms before reading ESC sequences
inetd,syslogd: use safe_read instead of open-coded EINTR handling syslogd: bail out if you see null read from Unix socket (should never happen, but if it does, spinning forever and eating 100% CPU is not a good idea)
This commit is contained in:
parent
f9566d8c29
commit
4f95e5aab8
19
editors/vi.c
19
editors/vi.c
@ -2152,7 +2152,7 @@ static char readit(void) // read (maybe cursor) key from stdin
|
|||||||
char c;
|
char c;
|
||||||
int n;
|
int n;
|
||||||
struct esc_cmds {
|
struct esc_cmds {
|
||||||
const char *seq;
|
const char seq[4];
|
||||||
char val;
|
char val;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2178,6 +2178,7 @@ static char readit(void) // read (maybe cursor) key from stdin
|
|||||||
{"OQ", VI_K_FUN2}, // Function Key F2
|
{"OQ", VI_K_FUN2}, // Function Key F2
|
||||||
{"OR", VI_K_FUN3}, // Function Key F3
|
{"OR", VI_K_FUN3}, // Function Key F3
|
||||||
{"OS", VI_K_FUN4}, // Function Key F4
|
{"OS", VI_K_FUN4}, // Function Key F4
|
||||||
|
// careful: these have no terminating NUL!
|
||||||
{"[15~", VI_K_FUN5}, // Function Key F5
|
{"[15~", VI_K_FUN5}, // Function Key F5
|
||||||
{"[17~", VI_K_FUN6}, // Function Key F6
|
{"[17~", VI_K_FUN6}, // Function Key F6
|
||||||
{"[18~", VI_K_FUN7}, // Function Key F7
|
{"[18~", VI_K_FUN7}, // Function Key F7
|
||||||
@ -2198,12 +2199,9 @@ static char readit(void) // read (maybe cursor) key from stdin
|
|||||||
n = readed_for_parse;
|
n = readed_for_parse;
|
||||||
// get input from User- are there already input chars in Q?
|
// get input from User- are there already input chars in Q?
|
||||||
if (n <= 0) {
|
if (n <= 0) {
|
||||||
ri0:
|
|
||||||
// the Q is empty, wait for a typed char
|
// the Q is empty, wait for a typed char
|
||||||
n = read(0, readbuffer, MAX_LINELEN - 1);
|
n = safe_read(0, readbuffer, MAX_LINELEN - 1);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
if (errno == EINTR)
|
|
||||||
goto ri0; // interrupted sys call
|
|
||||||
if (errno == EBADF || errno == EFAULT || errno == EINVAL
|
if (errno == EBADF || errno == EFAULT || errno == EINVAL
|
||||||
|| errno == EIO)
|
|| errno == EIO)
|
||||||
editing = 0;
|
editing = 0;
|
||||||
@ -2219,11 +2217,10 @@ static char readit(void) // read (maybe cursor) key from stdin
|
|||||||
struct pollfd pfd[1];
|
struct pollfd pfd[1];
|
||||||
pfd[0].fd = 0;
|
pfd[0].fd = 0;
|
||||||
pfd[0].events = POLLIN;
|
pfd[0].events = POLLIN;
|
||||||
// Wait 50 ms
|
|
||||||
// keep reading while there are input chars and room in buffer
|
// keep reading while there are input chars and room in buffer
|
||||||
while (safe_poll(pfd, 1, 50) > 0 && n <= (MAX_LINELEN - 5)) {
|
while (safe_poll(pfd, 1, 0) > 0 && n <= (MAX_LINELEN - 5)) {
|
||||||
// read the rest of the ESC string
|
// read the rest of the ESC string
|
||||||
int r = read(0, readbuffer + n, MAX_LINELEN - n);
|
int r = safe_read(0, readbuffer + n, MAX_LINELEN - n);
|
||||||
if (r > 0)
|
if (r > 0)
|
||||||
n += r;
|
n += r;
|
||||||
}
|
}
|
||||||
@ -2236,7 +2233,7 @@ static char readit(void) // read (maybe cursor) key from stdin
|
|||||||
const struct esc_cmds *eindex;
|
const struct esc_cmds *eindex;
|
||||||
|
|
||||||
for (eindex = esccmds; eindex < &esccmds[ESCCMDS_COUNT]; eindex++) {
|
for (eindex = esccmds; eindex < &esccmds[ESCCMDS_COUNT]; eindex++) {
|
||||||
int cnt = strlen(eindex->seq);
|
int cnt = strnlen(eindex->seq, 4);
|
||||||
|
|
||||||
if (n <= cnt)
|
if (n <= cnt)
|
||||||
continue;
|
continue;
|
||||||
@ -2397,7 +2394,7 @@ static int file_insert(const char * fn, char *p
|
|||||||
p = text_hole_make(p, size);
|
p = text_hole_make(p, size);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
goto fi0;
|
goto fi0;
|
||||||
cnt = read(fd, p, size);
|
cnt = safe_read(fd, p, size);
|
||||||
if (cnt < 0) {
|
if (cnt < 0) {
|
||||||
psbs("\"%s\" %s", fn, strerror(errno));
|
psbs("\"%s\" %s", fn, strerror(errno));
|
||||||
p = text_hole_delete(p, p + size - 1); // un-do buffer insert
|
p = text_hole_delete(p, p + size - 1); // un-do buffer insert
|
||||||
@ -3961,7 +3958,7 @@ static void crash_test()
|
|||||||
printf("\n\n%d: \'%c\' %s\n\n\n%s[Hit return to continue]%s",
|
printf("\n\n%d: \'%c\' %s\n\n\n%s[Hit return to continue]%s",
|
||||||
totalcmds, last_input_char, msg, SOs, SOn);
|
totalcmds, last_input_char, msg, SOs, SOn);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
while (read(0, d, 1) > 0) {
|
while (safe_read(0, d, 1) > 0) {
|
||||||
if (d[0] == '\n' || d[0] == '\r')
|
if (d[0] == '\n' || d[0] == '\r')
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1638,8 +1638,7 @@ discard_stream(int s, servtab_t *sep)
|
|||||||
|
|
||||||
inetd_setproctitle(sep->se_service, s);
|
inetd_setproctitle(sep->se_service, s);
|
||||||
while (1) {
|
while (1) {
|
||||||
errno = 0;
|
if (safe_read(s, buffer, sizeof(buffer)) <= 0)
|
||||||
if (read(s, buffer, sizeof(buffer)) <= 0 && errno != EINTR)
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -527,12 +527,10 @@ static void do_syslogd(void)
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
size_t sz;
|
size_t sz;
|
||||||
|
|
||||||
sz = read(sock_fd, G.recvbuf, MAX_READ - 1);
|
sz = safe_read(sock_fd, G.recvbuf, MAX_READ - 1);
|
||||||
if (sz <= 0) {
|
if (sz <= 0) {
|
||||||
if (sz == 0)
|
//if (sz == 0)
|
||||||
continue; /* EOF from unix socket??? */
|
// continue; /* EOF from unix socket??? */
|
||||||
if (errno == EINTR) /* alarm may have happened */
|
|
||||||
continue;
|
|
||||||
bb_perror_msg_and_die("read from /dev/log");
|
bb_perror_msg_and_die("read from /dev/log");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user