Skip to content

Commit a23a7a0

Browse files
authored
Merge pull request #225 from jpco/less-slow
Reduce use of, and simplify, slow syscall handling. Only use slow and slowlabel where they're needed, and remove the redundant 'interrupted' variable.
1 parent 52b3b48 commit a23a7a0

File tree

5 files changed

+15
-44
lines changed

5 files changed

+15
-44
lines changed

es.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,9 @@ extern void *ealloc(size_t n);
282282
extern void *erealloc(void *p, size_t n);
283283
extern void efree(void *p);
284284
extern void ewrite(int fd, const char *s, size_t n);
285-
extern long eread(int fd, char *buf, size_t n);
286285
extern Boolean isabsolute(char *path);
287286
extern Boolean streq2(const char *s, const char *t1, const char *t2);
288287

289-
290288
/* input.c */
291289

292290
extern char *prompt, *prompt2;
@@ -365,7 +363,7 @@ extern void setsigeffects(const Sigeffect effects[]);
365363
extern void getsigeffects(Sigeffect effects[]);
366364
extern List *mksiglist(void);
367365
extern void initsignals(Boolean interactive, Boolean allowdumps);
368-
extern Atomic slow, interrupted;
366+
extern Atomic slow;
369367
extern jmp_buf slowlabel;
370368
extern Boolean sigint_newline;
371369
extern void sigchk(void);

input.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,9 @@ static char *callreadline(char *prompt0) {
150150
}
151151
if (RL_ISSTATE(RL_STATE_INITIALIZED))
152152
rl_reset_screen_size();
153-
interrupted = FALSE;
154153
if (!setjmp(slowlabel)) {
155154
slow = TRUE;
156-
r = interrupted ? NULL : readline(prompt);
157-
if (interrupted)
158-
errno = EINTR;
155+
r = readline(prompt);
159156
} else {
160157
r = NULL;
161158
errno = EINTR;
@@ -196,7 +193,7 @@ static int fdfill(Input *in) {
196193
} else
197194
#endif
198195
do {
199-
nread = eread(in->fd, (char *) in->bufbegin, in->buflen);
196+
nread = read(in->fd, (char *) in->bufbegin, in->buflen);
200197
SIGCHK();
201198
} while (nread == -1 && errno == EINTR);
202199

prim-io.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ static List *bqinput(const char *sep, int fd) {
365365

366366
restart:
367367
/* avoid SIGCHK()ing in here so we don't abandon our child process */
368-
while ((n = eread(fd, in, sizeof in)) > 0)
368+
while ((n = read(fd, in, sizeof in)) > 0)
369369
splitstring(in, n, FALSE);
370370
if (n == -1) {
371371
if (errno == EINTR)
@@ -418,7 +418,7 @@ static int read1(int fd) {
418418
int nread;
419419
unsigned char buf;
420420
do {
421-
nread = eread(fd, (char *) &buf, 1);
421+
nread = read(fd, (char *) &buf, 1);
422422
SIGCHK();
423423
} while (nread == -1 && errno == EINTR);
424424
if (nread == -1)

signal.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@ typedef void (*Sighandler)(int);
77

88
Boolean sigint_newline = TRUE;
99

10-
jmp_buf slowlabel;
11-
Atomic slow = FALSE;
12-
Atomic interrupted = FALSE;
1310
static Atomic sigcount;
1411
static Atomic caught[NSIG];
1512
static Sigeffect sigeffect[NSIG];
1613
static Sighandler handler_in[NSIG];
1714

15+
/*
16+
* these variables are for the purpose of forcing a "return" from library or
17+
* system calls when a signal is received, since some of them don't do that
18+
* themselves.
19+
*/
20+
jmp_buf slowlabel;
21+
Atomic slow = FALSE;
22+
1823
#if HAVE_SIGACTION
1924
#ifndef SA_NOCLDSTOP
2025
#define SA_NOCLDSTOP 0
@@ -79,7 +84,6 @@ static void catcher(int sig) {
7984
caught[sig] = TRUE;
8085
++sigcount;
8186
}
82-
interrupted = TRUE;
8387
if (slow)
8488
longjmp(slowlabel, 1);
8589
}

util.c

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -98,35 +98,7 @@ extern void ewrite(int fd, const char *buf, size_t n) {
9898
volatile long i, remain;
9999
const char *volatile bufp = buf;
100100
for (i = 0, remain = n; remain > 0; bufp += i, remain -= i) {
101-
interrupted = FALSE;
102-
if (!setjmp(slowlabel)) {
103-
slow = TRUE;
104-
if (interrupted)
105-
break;
106-
else if ((i = write(fd, bufp, remain)) <= 0)
107-
break; /* abort silently on errors in write() */
108-
} else
109-
break;
110-
slow = FALSE;
101+
if ((i = write(fd, bufp, remain)) < 0 && errno != EINTR)
102+
break; /* abort silently on errors in write() */
111103
}
112-
slow = FALSE;
113-
}
114-
115-
extern long eread(int fd, char *buf, size_t n) {
116-
long r;
117-
interrupted = FALSE;
118-
if (!setjmp(slowlabel)) {
119-
slow = TRUE;
120-
if (!interrupted)
121-
r = read(fd, buf, n);
122-
else
123-
r = -2;
124-
} else
125-
r = -2;
126-
slow = FALSE;
127-
if (r == -2) {
128-
errno = EINTR;
129-
r = -1;
130-
}
131-
return r;
132104
}

0 commit comments

Comments
 (0)