2 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
13 #include "chan_user.h"
14 #include "kern_constants.h"
16 #include "um_malloc.h"
29 static void *xterm_init(char *str, int device, const struct chan_opts *opts)
31 struct xterm_chan *data;
33 data = kmalloc(sizeof(*data), UM_GFP_KERNEL);
36 *data = ((struct xterm_chan) { .pid = -1,
39 .title = opts->xterm_title,
44 /* Only changed by xterm_setup, which is a setup */
45 static char *terminal_emulator = "xterm";
46 static char *title_switch = "-T";
47 static char *exec_switch = "-e";
49 static int __init xterm_setup(char *line, int *add)
52 terminal_emulator = line;
54 line = strchr(line, ',');
62 line = strchr(line, ',');
73 __uml_setup("xterm=", xterm_setup,
74 "xterm=<terminal emulator>,<title switch>,<exec switch>\n"
75 " Specifies an alternate terminal emulator to use for the debugger,\n"
76 " consoles, and serial lines when they are attached to the xterm channel.\n"
77 " The values are the terminal emulator binary, the switch it uses to set\n"
78 " its title, and the switch it uses to execute a subprocess,\n"
79 " respectively. The title switch must have the form '<switch> title',\n"
80 " not '<switch>=title'. Similarly, the exec switch must have the form\n"
81 " '<switch> command arg1 arg2 ...'.\n"
82 " The default values are 'xterm=xterm,-T,-e'. Values for gnome-terminal\n"
83 " are 'xterm=gnome-terminal,-t,-x'.\n\n"
86 static int xterm_open(int input, int output, int primary, void *d,
89 struct xterm_chan *data = d;
90 int pid, fd, new, err;
91 char title[256], file[] = "/tmp/xterm-pipeXXXXXX";
92 char *argv[] = { terminal_emulator, title_switch, title, exec_switch,
93 "/usr/lib/uml/port-helper", "-uml-socket",
96 if (access(argv[4], X_OK) < 0)
97 argv[4] = "port-helper";
100 * Check that DISPLAY is set, this doesn't guarantee the xterm
101 * will work but w/o it we can be pretty sure it won't.
103 if (getenv("DISPLAY") == NULL) {
104 printk(UM_KERN_ERR "xterm_open: $DISPLAY not set.\n");
109 * This business of getting a descriptor to a temp file,
110 * deleting the file and closing the descriptor is just to get
111 * a known-unused name for the Unix socket that we really
117 printk(UM_KERN_ERR "xterm_open : mkstemp failed, errno = %d\n",
124 printk(UM_KERN_ERR "xterm_open : unlink failed, errno = %d\n",
130 fd = os_create_unix_socket(file, sizeof(file), 1);
132 printk(UM_KERN_ERR "xterm_open : create_unix_socket failed, "
133 "errno = %d\n", -fd);
137 sprintf(title, data->title, data->device);
138 pid = run_helper(NULL, NULL, argv);
141 printk(UM_KERN_ERR "xterm_open : run_helper failed, "
142 "errno = %d\n", -err);
146 err = os_set_fd_block(fd, 0);
148 printk(UM_KERN_ERR "xterm_open : failed to set descriptor "
149 "non-blocking, err = %d\n", -err);
153 new = xterm_fd(fd, &data->helper_pid);
156 printk(UM_KERN_ERR "xterm_open : os_rcv_fd failed, err = %d\n",
161 err = os_set_fd_block(new, 0);
163 printk(UM_KERN_ERR "xterm_open : failed to set xterm "
164 "descriptor non-blocking, err = %d\n", -err);
168 CATCH_EINTR(err = tcgetattr(new, &data->tt));
191 os_kill_process(pid, 1);
198 static void xterm_close(int fd, void *d)
200 struct xterm_chan *data = d;
203 os_kill_process(data->pid, 1);
206 if (data->helper_pid != -1)
207 os_kill_process(data->helper_pid, 0);
208 data->helper_pid = -1;
213 const struct chan_ops xterm_ops = {
217 .close = xterm_close,
218 .read = generic_read,
219 .write = generic_write,
220 .console_write = generic_console_write,
221 .window_size = generic_window_size,
222 .free = generic_free,