Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 9844779

Browse files
authored
Merge pull request #218 from gao-feng/errno
do not call any functions before check errno
2 parents fcc968a + b6eff45 commit 9844779

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

src/exec.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ static int pts_loop(struct hyper_event *de, uint64_t seq, int efd, struct hyper_
110110

111111
do {
112112
size = read(de->fd, buf->data + buf->get + 12, buf->size - buf->get - 12);
113-
fprintf(stdout, "%s: read %d data\n", __func__, size);
114113
if (size < 0) {
115114
if (errno == EINTR)
116115
continue;
@@ -122,6 +121,8 @@ static int pts_loop(struct hyper_event *de, uint64_t seq, int efd, struct hyper_
122121

123122
break;
124123
}
124+
fprintf(stdout, "%s: read %d data\n", __func__, size);
125+
125126
if (size == 0) { // eof
126127
pts_hup(de, efd, exec);
127128
return 0;
@@ -544,13 +545,14 @@ static void hyper_exec_process(struct hyper_exec *exec, struct stdio_config *io)
544545
}
545546

546547
if (execvp(exec->argv[0], exec->argv) < 0) {
548+
// perror possibly changes the errno.
549+
int err = errno;
547550
perror("exec failed");
548-
549551
/* the exit codes follow the `chroot` standard,
550552
see docker/docs/reference/run.md#exit-status */
551-
if (errno == ENOENT)
553+
if (err == ENOENT)
552554
_exit(127);
553-
else if (errno == EACCES)
555+
else if (err == EACCES)
554556
_exit(126);
555557
}
556558

src/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,14 +1245,14 @@ static int hyper_loop(void)
12451245

12461246
while (1) {
12471247
n = epoll_pwait(ctl.efd, events, MAXEVENTS, -1, &omask);
1248-
fprintf(stdout, "%s epoll_wait %d\n", __func__, n);
1249-
12501248
if (n < 0) {
12511249
if (errno == EINTR)
12521250
continue;
12531251
perror("hyper wait event failed");
12541252
return -1;
12551253
}
1254+
fprintf(stdout, "%s epoll_wait %d\n", __func__, n);
1255+
12561256
for (i = 0; i < n; i++) {
12571257
if (hyper_handle_event(ctl.efd, &events[i]) < 0)
12581258
return -1;

src/net.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ int hyper_send_data(int fd, uint8_t *data, uint32_t len)
4848

4949
while (length < len) {
5050
size = write(fd, data + length, len - length);
51-
5251
if (size <= 0) {
5352
if (errno == EINTR)
5453
continue;
@@ -99,7 +98,6 @@ int hyper_get_type(int fd, uint32_t *type)
9998

10099
while (len < 8) {
101100
size = read(fd, buf + len, 8 - len);
102-
103101
if (size <= 0) {
104102
if (errno == EINTR)
105103
continue;

src/util.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,12 @@ int hyper_open_channel(char *channel, int mode)
415415
{
416416
struct termios term;
417417
int fd = open(channel, O_RDWR | O_CLOEXEC | mode);
418-
fprintf(stdout, "open %s get %d\n", channel, fd);
419-
420418
if (fd < 0) {
421419
perror("fail to open channel device");
422420
return -1;
423421
}
424422

423+
fprintf(stdout, "open %s get %d\n", channel, fd);
425424
bzero(&term, sizeof(term));
426425

427426
cfmakeraw(&term);

0 commit comments

Comments
 (0)