fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / arch / um / drivers / xterm.c
index f417b3b..850221d 100644 (file)
@@ -14,7 +14,6 @@
 #include <sys/socket.h>
 #include "kern_util.h"
 #include "chan_user.h"
-#include "helper.h"
 #include "user_util.h"
 #include "user.h"
 #include "os.h"
@@ -31,7 +30,8 @@ struct xterm_chan {
        int direct_rcv;
 };
 
-void *xterm_init(char *str, int device, struct chan_opts *opts)
+/* Not static because it's called directly by the tt mode gdb code */
+void *xterm_init(char *str, int device, const struct chan_opts *opts)
 {
        struct xterm_chan *data;
 
@@ -83,8 +83,11 @@ __uml_setup("xterm=", xterm_setup,
 "    are 'xterm=gnome-terminal,-t,-x'.\n\n"
 );
 
-/* XXX This badly needs some cleaning up in the error paths */
-int xterm_open(int input, int output, int primary, void *d, char **dev_out)
+/* XXX This badly needs some cleaning up in the error paths
+ * Not static because it's called directly by the tt mode gdb code
+ */
+int xterm_open(int input, int output, int primary, void *d,
+                     char **dev_out)
 {
        struct xterm_chan *data = d;
        unsigned long stack;
@@ -97,15 +100,24 @@ int xterm_open(int input, int output, int primary, void *d, char **dev_out)
        if(os_access(argv[4], OS_ACC_X_OK) < 0)
                argv[4] = "port-helper";
 
+       /* Check that DISPLAY is set, this doesn't guarantee the xterm
+        * will work but w/o it we can be pretty sure it won't. */
+       if (!getenv("DISPLAY")) {
+               printk("xterm_open: $DISPLAY not set.\n");
+               return -ENODEV;
+       }
+
        fd = mkstemp(file);
        if(fd < 0){
+               err = -errno;
                printk("xterm_open : mkstemp failed, errno = %d\n", errno);
-               return(-errno);
+               return err;
        }
 
        if(unlink(file)){
+               err = -errno;
                printk("xterm_open : unlink failed, errno = %d\n", errno);
-               return(-errno);
+               return err;
        }
        os_close_file(fd);
 
@@ -124,11 +136,9 @@ int xterm_open(int input, int output, int primary, void *d, char **dev_out)
                return(pid);
        }
 
-       if(data->stack == 0) free_stack(stack, 0);
-
-       if(data->direct_rcv)
+       if (data->direct_rcv) {
                new = os_rcv_fd(fd, &data->helper_pid);
-       else {
+       else {
                err = os_set_fd_block(fd, 0);
                if(err < 0){
                        printk("xterm_open : failed to set descriptor "
@@ -163,6 +173,7 @@ int xterm_open(int input, int output, int primary, void *d, char **dev_out)
        return(new);
 }
 
+/* Not static because it's called directly by the tt mode gdb code */
 void xterm_close(int fd, void *d)
 {
        struct xterm_chan *data = d;
@@ -176,26 +187,19 @@ void xterm_close(int fd, void *d)
        os_close_file(fd);
 }
 
-void xterm_free(void *d)
+static void xterm_free(void *d)
 {
        free(d);
 }
 
-int xterm_console_write(int fd, const char *buf, int n, void *d)
-{
-       struct xterm_chan *data = d;
-
-       return(generic_console_write(fd, buf, n, &data->tt));
-}
-
-struct chan_ops xterm_ops = {
+const struct chan_ops xterm_ops = {
        .type           = "xterm",
        .init           = xterm_init,
        .open           = xterm_open,
        .close          = xterm_close,
        .read           = generic_read,
        .write          = generic_write,
-       .console_write  = xterm_console_write,
+       .console_write  = generic_console_write,
        .window_size    = generic_window_size,
        .free           = xterm_free,
        .winch          = 1,