2 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
12 #include "chan_user.h"
17 #include "kern_constants.h"
28 static void *xterm_init(char *str, int device, const struct chan_opts *opts)
30 struct xterm_chan *data;
32 data = malloc(sizeof(*data));
35 *data = ((struct xterm_chan) { .pid = -1,
38 .title = opts->xterm_title,
43 /* Only changed by xterm_setup, which is a setup */
44 static char *terminal_emulator = "xterm";
45 static char *title_switch = "-T";
46 static char *exec_switch = "-e";
48 static int __init xterm_setup(char *line, int *add)
51 terminal_emulator = line;
53 line = strchr(line, ',');
61 line = strchr(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 static int xterm_open(int input, int output, int primary, void *d,
88 struct xterm_chan *data = d;
89 int pid, fd, new, err;
90 char title[256], file[] = "/tmp/xterm-pipeXXXXXX";
91 char *argv[] = { terminal_emulator, title_switch, title, exec_switch,
92 "/usr/lib/uml/port-helper", "-uml-socket",
95 if (access(argv[4], X_OK) < 0)
96 argv[4] = "port-helper";
98 /* Check that DISPLAY is set, this doesn't guarantee the xterm
99 * will work but w/o it we can be pretty sure it won't. */
100 if (getenv("DISPLAY") == NULL) {
101 printk(UM_KERN_ERR "xterm_open: $DISPLAY not set.\n");
106 * This business of getting a descriptor to a temp file,
107 * deleting the file and closing the descriptor is just to get
108 * a known-unused name for the Unix socket that we really
114 printk(UM_KERN_ERR "xterm_open : mkstemp failed, errno = %d\n",
121 printk(UM_KERN_ERR "xterm_open : unlink failed, errno = %d\n",
127 fd = os_create_unix_socket(file, sizeof(file), 1);
129 printk(UM_KERN_ERR "xterm_open : create_unix_socket failed, "
130 "errno = %d\n", -fd);
134 sprintf(title, data->title, data->device);
135 pid = run_helper(NULL, NULL, argv);
138 printk(UM_KERN_ERR "xterm_open : run_helper failed, "
139 "errno = %d\n", -err);
143 err = os_set_fd_block(fd, 0);
145 printk(UM_KERN_ERR "xterm_open : failed to set descriptor "
146 "non-blocking, err = %d\n", -err);
150 new = xterm_fd(fd, &data->helper_pid);
153 printk(UM_KERN_ERR "xterm_open : os_rcv_fd failed, err = %d\n",
158 err = os_set_fd_block(new, 0);
160 printk(UM_KERN_ERR "xterm_open : failed to set xterm "
161 "descriptor non-blocking, err = %d\n", -err);
165 CATCH_EINTR(err = tcgetattr(new, &data->tt));
188 os_kill_process(pid, 1);
195 static void xterm_close(int fd, void *d)
197 struct xterm_chan *data = d;
200 os_kill_process(data->pid, 1);
203 if (data->helper_pid != -1)
204 os_kill_process(data->helper_pid, 0);
205 data->helper_pid = -1;
210 static void xterm_free(void *d)
215 const struct chan_ops xterm_ops = {
219 .close = xterm_close,
220 .read = generic_read,
221 .write = generic_write,
222 .console_write = generic_console_write,
223 .window_size = generic_window_size,