2 * Copyright (C) 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
14 #include <sys/socket.h>
15 #include "kern_util.h"
16 #include "chan_user.h"
32 /* Not static because it's called directly by the tt mode gdb code */
33 void *xterm_init(char *str, int device, const struct chan_opts *opts)
35 struct xterm_chan *data;
37 data = malloc(sizeof(*data));
38 if(data == NULL) return(NULL);
39 *data = ((struct xterm_chan) { .pid = -1,
42 .title = opts->xterm_title,
44 .stack = opts->tramp_stack,
45 .direct_rcv = !opts->in_kernel } );
49 /* Only changed by xterm_setup, which is a setup */
50 static char *terminal_emulator = "xterm";
51 static char *title_switch = "-T";
52 static char *exec_switch = "-e";
54 static int __init xterm_setup(char *line, int *add)
57 terminal_emulator = line;
59 line = strchr(line, ',');
60 if(line == NULL) return(0);
62 if(*line) title_switch = line;
64 line = strchr(line, ',');
65 if(line == NULL) return(0);
67 if(*line) exec_switch = line;
72 __uml_setup("xterm=", xterm_setup,
73 "xterm=<terminal emulator>,<title switch>,<exec switch>\n"
74 " Specifies an alternate terminal emulator to use for the debugger,\n"
75 " consoles, and serial lines when they are attached to the xterm channel.\n"
76 " The values are the terminal emulator binary, the switch it uses to set\n"
77 " its title, and the switch it uses to execute a subprocess,\n"
78 " respectively. The title switch must have the form '<switch> title',\n"
79 " not '<switch>=title'. Similarly, the exec switch must have the form\n"
80 " '<switch> command arg1 arg2 ...'.\n"
81 " The default values are 'xterm=xterm,-T,-e'. Values for gnome-terminal\n"
82 " are 'xterm=gnome-terminal,-t,-x'.\n\n"
85 /* XXX This badly needs some cleaning up in the error paths
86 * Not static because it's called directly by the tt mode gdb code
88 int xterm_open(int input, int output, int primary, void *d,
91 struct xterm_chan *data = d;
93 int pid, fd, new, err;
94 char title[256], file[] = "/tmp/xterm-pipeXXXXXX";
95 char *argv[] = { terminal_emulator, title_switch, title, exec_switch,
96 "/usr/lib/uml/port-helper", "-uml-socket",
99 if(os_access(argv[4], OS_ACC_X_OK) < 0)
100 argv[4] = "port-helper";
102 /* Check that DISPLAY is set, this doesn't guarantee the xterm
103 * will work but w/o it we can be pretty sure it won't. */
104 if (!getenv("DISPLAY")) {
105 printk("xterm_open: $DISPLAY not set.\n");
112 printk("xterm_open : mkstemp failed, errno = %d\n", errno);
118 printk("xterm_open : unlink failed, errno = %d\n", errno);
123 fd = os_create_unix_socket(file, sizeof(file), 1);
125 printk("xterm_open : create_unix_socket failed, errno = %d\n",
130 sprintf(title, data->title, data->device);
132 pid = run_helper(NULL, NULL, argv, &stack);
134 printk("xterm_open : run_helper failed, errno = %d\n", -pid);
138 if (data->direct_rcv) {
139 new = os_rcv_fd(fd, &data->helper_pid);
141 err = os_set_fd_block(fd, 0);
143 printk("xterm_open : failed to set descriptor "
144 "non-blocking, err = %d\n", -err);
147 new = xterm_fd(fd, &data->helper_pid);
150 printk("xterm_open : os_rcv_fd failed, err = %d\n", -new);
154 CATCH_EINTR(err = tcgetattr(new, &data->tt));
175 /* Not static because it's called directly by the tt mode gdb code */
176 void xterm_close(int fd, void *d)
178 struct xterm_chan *data = d;
181 os_kill_process(data->pid, 1);
183 if(data->helper_pid != -1)
184 os_kill_process(data->helper_pid, 0);
185 data->helper_pid = -1;
189 static void xterm_free(void *d)
194 const struct chan_ops xterm_ops = {
198 .close = xterm_close,
199 .read = generic_read,
200 .write = generic_write,
201 .console_write = generic_console_write,
202 .window_size = generic_window_size,
208 * Overrides for Emacs so that we follow Linus's tabbing style.
209 * Emacs will notice this stuff at the end of the file and automatically
210 * adjust the settings for this buffer only. This must remain at the end
212 * ---------------------------------------------------------------------------
214 * c-file-style: "linux"