Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

Commit e4ba920

Browse files
author
Julio Montes
committed
add support to change console size in newcontainer
to support oci-1.0-rc5 this change is needed since console size can be specified when the container is launched Signed-off-by: Julio Montes <[email protected]>
1 parent b697dbb commit e4ba920

File tree

6 files changed

+35
-7
lines changed

6 files changed

+35
-7
lines changed

src/exec.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,11 @@ int hyper_run_process(struct hyper_exec *exec)
621621
goto out;
622622
}
623623

624+
if (exec->ptyfd >= 0 && set_win_size(exec->ptyfd, exec->rows, exec->columns) < 0) {
625+
fprintf(stderr, "set win size failed");
626+
goto out;
627+
}
628+
624629
if (pipe2(pipe, O_CLOEXEC) < 0) {
625630
perror("create pipe between pod init execcmd failed");
626631
goto close_tty;

src/exec.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ struct hyper_exec {
3939
uint64_t seq;
4040
uint64_t errseq;
4141
char *workdir;
42+
int rows;
43+
int columns;
4244
};
4345

4446
struct hyper_pod;

src/init.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ static int hyper_handle_exit(struct hyper_pod *pod);
4949

5050
static int hyper_set_win_size(char *json, int length)
5151
{
52-
struct winsize size;
5352
struct hyper_exec *exec;
54-
int ret;
53+
int ret, columns, rows;
5554

5655
fprintf(stdout, "call hyper_win_size, json %s, len %d\n", json, length);
5756
JSON_Value *value = hyper_json_parse(json, length);
@@ -69,12 +68,10 @@ static int hyper_set_win_size(char *json, int length)
6968
goto out;
7069
}
7170

72-
size.ws_row = (int)json_object_get_number(json_object(value), "row");
73-
size.ws_col = (int)json_object_get_number(json_object(value), "column");
71+
rows = (int)json_object_get_number(json_object(value), "row");
72+
columns = (int)json_object_get_number(json_object(value), "column");
7473

75-
ret = ioctl(exec->ptyfd, TIOCSWINSZ, &size);
76-
if (ret < 0)
77-
perror("cannot ioctl to set pty device term size");
74+
ret = set_win_size(exec->ptyfd, rows, columns);
7875

7976
out:
8077
json_value_free(value);

src/parse.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,14 @@ static int hyper_parse_process(struct hyper_exec *exec, char *json, jsmntok_t *t
516516
exec->workdir = (json_token_str(json, &toks[++i]));
517517
fprintf(stdout, "container workdir %s\n", exec->workdir);
518518
i++;
519+
} else if (json_token_streq(json, t, "rows") && t->size == 1) {
520+
exec->rows = json_token_int(json, &toks[++i]);
521+
fprintf(stdout, "container rows %d\n", exec->rows);
522+
i++;
523+
} else if (json_token_streq(json, t, "columns") && t->size == 1) {
524+
exec->columns = json_token_int(json, &toks[++i]);
525+
fprintf(stdout, "container columns %d\n", exec->columns);
526+
i++;
519527
}
520528
}
521529

src/util.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,3 +819,18 @@ ssize_t nonblock_read(int fd, void *buf, size_t count)
819819

820820
return len > 0 ? len : ret;
821821
}
822+
823+
int set_win_size(int fd, int rows, int columns)
824+
{
825+
int ret;
826+
struct winsize size = {
827+
.ws_row = rows,
828+
.ws_col = columns,
829+
};
830+
831+
ret = ioctl(fd, TIOCSWINSZ, &size);
832+
if (ret < 0) {
833+
perror("cannot ioctl to set pty device term size");
834+
}
835+
return ret;
836+
}

src/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ struct passwd *hyper_getpwnam(const char *name);
4444
struct group *hyper_getgrnam(const char *name);
4545
int hyper_getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroups);
4646
ssize_t nonblock_read(int fd, void *buf, size_t count);
47+
int set_win_size(int fd, int rows, int columns);
4748
#endif

0 commit comments

Comments
 (0)