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"
18 #include "user_util.h"
34 /* Not static because it's called directly by the tt mode gdb code */
35 void *xterm_init(char *str, int device, struct chan_opts *opts)
37 struct xterm_chan *data;
39 data = malloc(sizeof(*data));
40 if(data == NULL) return(NULL);
41 *data = ((struct xterm_chan) { .pid = -1,
44 .title = opts->xterm_title,
46 .stack = opts->tramp_stack,
47 .direct_rcv = !opts->in_kernel } );
51 /* Only changed by xterm_setup, which is a setup */
52 static char *terminal_emulator = "xterm";
53 static char *title_switch = "-T";
54 static char *exec_switch = "-e";
56 static int __init xterm_setup(char *line, int *add)
59 terminal_emulator = line;
61 line = strchr(line, ',');
62 if(line == NULL) return(0);
64 if(*line) title_switch = line;
66 line = strchr(line, ',');
67 if(line == NULL) return(0);
69 if(*line) exec_switch = line;
74 __uml_setup("xterm=", xterm_setup,
75 "xterm=<terminal emulator>,<title switch>,<exec switch>\n"
76 " Specifies an alternate terminal emulator to use for the debugger,\n"
77 " consoles, and serial lines when they are attached to the xterm channel.\n"
78 " The values are the terminal emulator binary, the switch it uses to set\n"
79 " its title, and the switch it uses to execute a subprocess,\n"
80 " respectively. The title switch must have the form '<switch> title',\n"
81 " not '<switch>=title'. Similarly, the exec switch must have the form\n"
82 " '<switch> command arg1 arg2 ...'.\n"
83 " The default values are 'xterm=xterm,-T,-e'. Values for gnome-terminal\n"
84 " are 'xterm=gnome-terminal,-t,-x'.\n\n"
87 /* XXX This badly needs some cleaning up in the error paths
88 * Not static because it's called directly by the tt mode gdb code
90 int xterm_open(int input, int output, int primary, void *d,
93 struct xterm_chan *data = d;
95 int pid, fd, new, err;
96 char title[256], file[] = "/tmp/xterm-pipeXXXXXX";
97 char *argv[] = { terminal_emulator, title_switch, title, exec_switch,
98 "/usr/lib/uml/port-helper", "-uml-socket",
101 if(os_access(argv[4], OS_ACC_X_OK) < 0)
102 argv[4] = "port-helper";
104 /* Check that DISPLAY is set, this doesn't guarantee the xterm
105 * will work but w/o it we can be pretty sure it won't. */
106 if (!getenv("DISPLAY")) {
107 printk("xterm_open: $DISPLAY not set.\n");
114 printk("xterm_open : mkstemp failed, errno = %d\n", errno);
120 printk("xterm_open : unlink failed, errno = %d\n", errno);
125 fd = os_create_unix_socket(file, sizeof(file), 1);
127 printk("xterm_open : create_unix_socket failed, errno = %d\n",
132 sprintf(title, data->title, data->device);
134 pid = run_helper(NULL, NULL, argv, &stack);
136 printk("xterm_open : run_helper failed, errno = %d\n", -pid);
140 if(data->stack == 0) free_stack(stack, 0);
142 if (data->direct_rcv) {
143 new = os_rcv_fd(fd, &data->helper_pid);
145 err = os_set_fd_block(fd, 0);
147 printk("xterm_open : failed to set descriptor "
148 "non-blocking, err = %d\n", -err);
151 new = xterm_fd(fd, &data->helper_pid);
154 printk("xterm_open : os_rcv_fd failed, err = %d\n", -new);
158 CATCH_EINTR(err = tcgetattr(new, &data->tt));
179 /* Not static because it's called directly by the tt mode gdb code */
180 void xterm_close(int fd, void *d)
182 struct xterm_chan *data = d;
185 os_kill_process(data->pid, 1);
187 if(data->helper_pid != -1)
188 os_kill_process(data->helper_pid, 0);
189 data->helper_pid = -1;
193 static void xterm_free(void *d)
198 static int xterm_console_write(int fd, const char *buf, int n, void *d)
200 struct xterm_chan *data = d;
202 return(generic_console_write(fd, buf, n, &data->tt));
205 struct chan_ops xterm_ops = {
209 .close = xterm_close,
210 .read = generic_read,
211 .write = generic_write,
212 .console_write = xterm_console_write,
213 .window_size = generic_window_size,
219 * Overrides for Emacs so that we follow Linus's tabbing style.
220 * Emacs will notice this stuff at the end of the file and automatically
221 * adjust the settings for this buffer only. This must remain at the end
223 * ---------------------------------------------------------------------------
225 * c-file-style: "linux"