mirror of
https://github.com/clearlinux/hyperstart.git
synced 2026-08-18 20:05:48 +00:00
do not call any functions before check errno
perror changes the errno, result in the errno checking of execvp incorrect. Signed-off-by: Gao feng <omarapazanadi@gmail.com>
This commit is contained in:
+6
-4
@@ -110,7 +110,6 @@ static int pts_loop(struct hyper_event *de, uint64_t seq, int efd, struct hyper_
|
||||
|
||||
do {
|
||||
size = read(de->fd, buf->data + buf->get + 12, buf->size - buf->get - 12);
|
||||
fprintf(stdout, "%s: read %d data\n", __func__, size);
|
||||
if (size < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
@@ -122,6 +121,8 @@ static int pts_loop(struct hyper_event *de, uint64_t seq, int efd, struct hyper_
|
||||
|
||||
break;
|
||||
}
|
||||
fprintf(stdout, "%s: read %d data\n", __func__, size);
|
||||
|
||||
if (size == 0) { // eof
|
||||
pts_hup(de, efd, exec);
|
||||
return 0;
|
||||
@@ -544,13 +545,14 @@ static void hyper_exec_process(struct hyper_exec *exec, struct stdio_config *io)
|
||||
}
|
||||
|
||||
if (execvp(exec->argv[0], exec->argv) < 0) {
|
||||
// perror possibly changes the errno.
|
||||
int err = errno;
|
||||
perror("exec failed");
|
||||
|
||||
/* the exit codes follow the `chroot` standard,
|
||||
see docker/docs/reference/run.md#exit-status */
|
||||
if (errno == ENOENT)
|
||||
if (err == ENOENT)
|
||||
_exit(127);
|
||||
else if (errno == EACCES)
|
||||
else if (err == EACCES)
|
||||
_exit(126);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1244,14 +1244,14 @@ static int hyper_loop(void)
|
||||
|
||||
while (1) {
|
||||
n = epoll_pwait(ctl.efd, events, MAXEVENTS, -1, &omask);
|
||||
fprintf(stdout, "%s epoll_wait %d\n", __func__, n);
|
||||
|
||||
if (n < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
perror("hyper wait event failed");
|
||||
return -1;
|
||||
}
|
||||
fprintf(stdout, "%s epoll_wait %d\n", __func__, n);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
if (hyper_handle_event(ctl.efd, &events[i]) < 0)
|
||||
return -1;
|
||||
|
||||
@@ -48,7 +48,6 @@ int hyper_send_data(int fd, uint8_t *data, uint32_t len)
|
||||
|
||||
while (length < len) {
|
||||
size = write(fd, data + length, len - length);
|
||||
|
||||
if (size <= 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
@@ -99,7 +98,6 @@ int hyper_get_type(int fd, uint32_t *type)
|
||||
|
||||
while (len < 8) {
|
||||
size = read(fd, buf + len, 8 - len);
|
||||
|
||||
if (size <= 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
|
||||
+1
-2
@@ -415,13 +415,12 @@ int hyper_open_channel(char *channel, int mode)
|
||||
{
|
||||
struct termios term;
|
||||
int fd = open(channel, O_RDWR | O_CLOEXEC | mode);
|
||||
fprintf(stdout, "open %s get %d\n", channel, fd);
|
||||
|
||||
if (fd < 0) {
|
||||
perror("fail to open channel device");
|
||||
return -1;
|
||||
}
|
||||
|
||||
fprintf(stdout, "open %s get %d\n", channel, fd);
|
||||
bzero(&term, sizeof(term));
|
||||
|
||||
cfmakeraw(&term);
|
||||
|
||||
Reference in New Issue
Block a user