mirror of
https://github.com/clearlinux/hyperstart.git
synced 2026-08-24 08:07:21 +00:00
+2
-2
@@ -188,7 +188,7 @@ int hyper_event_read(struct hyper_event *de, int efd)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hyper_event_write(struct hyper_event *de)
|
||||
int hyper_event_write(struct hyper_event *de, int efd)
|
||||
{
|
||||
struct hyper_buf *buf = &de->wbuf;
|
||||
uint32_t len = 0;
|
||||
@@ -246,7 +246,7 @@ int hyper_handle_event(int efd, struct epoll_event *event)
|
||||
if (event->events & EPOLLOUT) {
|
||||
fprintf(stdout, "%s event EPOLLOUT, de %p, fd %d, %p\n",
|
||||
__func__, de, de->fd, de->ops);
|
||||
if (de->ops->write && de->ops->write(de) < 0)
|
||||
if (de->ops->write && de->ops->write(de, efd) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ struct hyper_event;
|
||||
|
||||
struct hyper_event_ops {
|
||||
int (*read)(struct hyper_event *e, int efd);
|
||||
int (*write)(struct hyper_event *e);
|
||||
int (*write)(struct hyper_event *e, int efd);
|
||||
int (*handle)(struct hyper_event *e, uint32_t len);
|
||||
void (*hup)(struct hyper_event *e, int efd);
|
||||
int rbuf_size;
|
||||
@@ -40,5 +40,5 @@ int hyper_handle_event(int efd, struct epoll_event *event);
|
||||
void hyper_reset_event(struct hyper_event *de);
|
||||
void hyper_event_hup(struct hyper_event *de, int efd);
|
||||
int hyper_event_read(struct hyper_event *dei, int efd);
|
||||
int hyper_event_write(struct hyper_event *de);
|
||||
int hyper_event_write(struct hyper_event *de, int efd);
|
||||
#endif
|
||||
|
||||
+16
-3
@@ -75,8 +75,6 @@ static void pts_hup(struct hyper_event *de, int efd, struct hyper_exec *exec)
|
||||
|
||||
hyper_event_hup(de, efd);
|
||||
|
||||
hyper_send_exec_eof(exec, 0);
|
||||
|
||||
hyper_release_exec(exec, pod);
|
||||
}
|
||||
|
||||
@@ -138,9 +136,22 @@ static int pts_loop(struct hyper_event *de, uint64_t seq, int efd, struct hyper_
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int write_to_stdin(struct hyper_event *de, int efd)
|
||||
{
|
||||
struct hyper_exec *exec = container_of(de, struct hyper_exec, stdinev);
|
||||
fprintf(stdout, "%s, seq %" PRIu64"\n", __func__, exec->seq);
|
||||
|
||||
int ret = hyper_event_write(de, efd);
|
||||
|
||||
if (ret >= 0 && de->wbuf.get == 0 && exec->close_stdin_request)
|
||||
pts_hup(de, efd, exec);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
struct hyper_event_ops in_ops = {
|
||||
.hup = stdin_hup,
|
||||
.write = hyper_event_write,
|
||||
.write = write_to_stdin,
|
||||
.wbuf_size = 512,
|
||||
};
|
||||
|
||||
@@ -654,6 +665,8 @@ int hyper_release_exec(struct hyper_exec *exec,
|
||||
|
||||
list_del_init(&exec->list);
|
||||
|
||||
hyper_send_exec_eof(exec, 0);
|
||||
|
||||
hyper_send_exec_code(exec, 0);
|
||||
|
||||
fprintf(stdout, "%s exit code %" PRIu8"\n", __func__, exec->code);
|
||||
|
||||
@@ -22,6 +22,7 @@ struct hyper_exec {
|
||||
int stdinfd;
|
||||
int stdoutfd;
|
||||
int stderrfd;
|
||||
uint8_t close_stdin_request;
|
||||
uint8_t code;
|
||||
uint8_t exit;
|
||||
uint8_t ref;
|
||||
|
||||
+11
-1
@@ -1054,7 +1054,7 @@ static int hyper_ttyfd_handle(struct hyper_event *de, uint32_t len)
|
||||
dprintf(stdout, "find exec %s pid %d, seq is %" PRIu64 "\n",
|
||||
exec->id ? exec->id : "pod", exec->pid, exec->seq);
|
||||
// if exec is exited, the event fd of exec is invalid. don't accept any input.
|
||||
if (exec->exit) {
|
||||
if (exec->exit || exec->close_stdin_request) {
|
||||
fprintf(stdout, "exec seq %" PRIu64 " exited, don't accept any input\n", exec->seq);
|
||||
return 0;
|
||||
}
|
||||
@@ -1070,6 +1070,16 @@ static int hyper_ttyfd_handle(struct hyper_event *de, uint32_t len)
|
||||
if (size > (len - 12))
|
||||
size = (len - 12);
|
||||
|
||||
/* size == 0 means we had received eof */
|
||||
if (size == 0 && !exec->tty) {
|
||||
exec->close_stdin_request = 1;
|
||||
/* we can't hup the stdinev here, force hup on next write */
|
||||
if (hyper_modify_event(ctl.efd, &exec->stdinev, EPOLLOUT) < 0) {
|
||||
fprintf(stderr, "modify exec pts event to in & out failed\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (size > 0) {
|
||||
memcpy(wbuf->data + wbuf->get, rbuf->data + 12, size);
|
||||
wbuf->get += size;
|
||||
|
||||
Reference in New Issue
Block a user