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

Commit 0c05c99

Browse files
committed
remove tty from struct hyper_win_size
Signed-off-by: Lai Jiangshan <jiangshanlai@gmail.com>
1 parent 97099eb commit 0c05c99

File tree

3 files changed

+13
-45
lines changed

3 files changed

+13
-45
lines changed

src/hyper.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ struct portmapping_white_list {
7474
};
7575

7676
struct hyper_win_size {
77-
char *tty;
7877
int row;
7978
int column;
8079
uint64_t seq;

src/init.c

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,53 +44,30 @@ static int hyper_stop_pod(struct hyper_pod *pod);
4444

4545
static int hyper_set_win_size(char *json, int length)
4646
{
47-
struct hyper_win_size ws = {
48-
.tty = NULL,
49-
};
47+
struct hyper_win_size ws;
5048
struct winsize size;
5149
struct hyper_exec *exec;
52-
char path[128];
53-
int fd, ret;
50+
int ret;
5451

5552
fprintf(stdout, "call hyper_win_size, json %s, len %d\n", json, length);
5653
if (hyper_parse_winsize(&ws, json, length) < 0) {
5754
fprintf(stderr, "set term size failed\n");
5855
return -1;
5956
}
6057

61-
if (!ws.tty) {
62-
exec = hyper_find_exec_by_seq(&global_pod, ws.seq);
63-
if (exec == NULL) {
64-
fprintf(stdout, "can not find exec whose seq is %" PRIu64"\n", ws.seq);
65-
return 0;
66-
}
67-
68-
fprintf(stdout, "find exec %s, pid is %d, seq is %" PRIu64"\n",
69-
exec->id ? exec->id : "pod", exec->pid, ws.seq);
70-
fd = dup(exec->ptyfd);
71-
} else {
72-
if (sprintf(path, "/dev/%s", ws.tty) < 0) {
73-
fprintf(stderr, "get tty device failed\n");
74-
return -1;
75-
}
76-
fd = hyper_open_serial_dev(path);
77-
}
78-
79-
if (fd < 0) {
80-
perror("cannot open pty device to set term size");
81-
goto out;
58+
exec = hyper_find_exec_by_seq(&global_pod, ws.seq);
59+
if (exec == NULL) {
60+
fprintf(stdout, "can not find exec whose seq is %" PRIu64"\n", ws.seq);
61+
return 0;
8262
}
8363

8464
size.ws_row = ws.row;
8565
size.ws_col = ws.column;
8666

87-
ret = ioctl(fd, TIOCSWINSZ, &size);
67+
ret = ioctl(exec->ptyfd, TIOCSWINSZ, &size);
8868
if (ret < 0)
8969
perror("cannot ioctl to set pty device term size");
9070

91-
close(fd);
92-
out:
93-
free(ws.tty);
9471
return ret;
9572
}
9673

src/parse.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,39 +1292,31 @@ int hyper_parse_winsize(struct hyper_win_size *ws, char *json, int length)
12921292
continue;
12931293

12941294
if (i++ == n)
1295-
goto fail;
1295+
goto out;
12961296

1297-
if (json_token_streq(json, t, "tty")) {
1298-
if (toks[i].type != JSMN_STRING)
1299-
goto fail;
1300-
ws->tty = (json_token_str(json, &toks[i]));
1301-
} else if (json_token_streq(json, t, "seq")) {
1297+
if (json_token_streq(json, t, "seq")) {
13021298
if (toks[i].type != JSMN_PRIMITIVE)
1303-
goto fail;
1299+
goto out;
13041300
ws->seq = json_token_ll(json, &toks[i]);
13051301
} else if (json_token_streq(json, t, "row")) {
13061302
if (toks[i].type != JSMN_PRIMITIVE)
1307-
goto fail;
1303+
goto out;
13081304
ws->row = json_token_int(json, &toks[i]);
13091305
} else if (json_token_streq(json, t, "column")) {
13101306
if (toks[i].type != JSMN_PRIMITIVE)
1311-
goto fail;
1307+
goto out;
13121308
ws->column = json_token_int(json, &toks[i]);
13131309
} else {
13141310
fprintf(stderr, "get unknown section %s in winsize\n",
13151311
json_token_str(json, t));
1316-
goto fail;
1312+
goto out;
13171313
}
13181314
}
13191315

13201316
ret = 0;
13211317
out:
13221318
free(toks);
13231319
return ret;
1324-
fail:
1325-
free(ws->tty);
1326-
ws->tty = NULL;
1327-
goto out;
13281320
}
13291321

13301322
struct hyper_exec *hyper_parse_execcmd(char *json, int length)

0 commit comments

Comments
 (0)