1 ////////////////////////////////////////////////////////////////////////////////
4 static void dump (char c) {
7 fprintf(stderr, " %02x '%c' ", c, isprint(c)?c:'.');
8 if (++col % 10 == 0) fprintf(stderr, "\n");
13 static __attribute__((noreturn
)) void execsh (const char *str
) {
17 char *envshell
= getenv("SHELL");
19 K8T_DEFAULT(envshell
, opt_shell
);
20 setenv("TERM", opt_term
, 1);
21 args
= opt_cmd
? opt_cmd
: (char *[]){envshell
, "-i", NULL
};
25 args
= calloc(32768, sizeof(char *));
26 if (args
== NULL
) exit(EXIT_FAILURE
);
30 while (*str
&& isspace(*str
)) ++str
;
34 while (*str
&& !isspace(*str
)) {
40 args
[argc
] = calloc(str
-b
+1, 1);
41 memcpy(args
[argc
], b
, str
-b
);
44 FILE *fo = fopen("z.log", "a");
45 fprintf(fo, "%d: [%s]\n", argc, args[argc]);
51 if (argc
< 1) exit(EXIT_FAILURE
);
53 execvp(args
[0], args
);
58 static int k8t_ttyNew (K8Term
*term
) {
60 struct winsize w
= {term
->row
, term
->col
, 0, 0};
62 if (openpty(&m
, &s
, NULL
, NULL
, &w
) < 0) die("openpty failed: %s", strerror(errno
));
66 switch (term
->pid
= fork()) {
68 fprintf(stderr
, "fork failed");
71 setsid(); /* create a new process group */
72 dup2(s
, STDIN_FILENO
);
73 dup2(s
, STDOUT_FILENO
);
74 dup2(s
, STDERR_FILENO
);
75 if (ioctl(s
, TIOCSCTTY
, NULL
) < 0) die("ioctl TIOCSCTTY failed: %s", strerror(errno
));
78 execsh(term
->execcmd
);