[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Savannah-hackers] Re: lsh-1.4 still having the same problem
From: |
Niels Möller |
Subject: |
[Savannah-hackers] Re: lsh-1.4 still having the same problem |
Date: |
18 Jun 2002 09:49:33 +0200 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 |
I wrote:
> The idea is to make sure that an EOF character (^D) is always
> written to the pty before it is closed, no matter what the reason
> for the close is.
Here's a patch that tries to do that.
/Niels
Index: src/io.c
===================================================================
RCS file: /cvsroot/lsh/lsh/src/io.c,v
retrieving revision 1.166
diff -u -a -r1.166 io.c
--- src/io.c 2 Jun 2002 15:45:45 -0000 1.166
+++ src/io.c 18 Jun 2002 07:44:17 -0000
@@ -1324,6 +1324,7 @@
self->fd = fd;
self->label = label;
+ self->type = 0;
self->e = make_exception_handler(do_exc_io_handler, e, HANDLER_CONTEXT);
@@ -1339,6 +1340,14 @@
return self;
}
+void
+io_set_type(struct lsh_fd *fd, enum io_type type)
+{
+ trace("io_set_type: fd %i, type %i\n",
+ fd->fd, type);
+ fd->type = type;
+}
+
unsigned
io_nfiles(void)
{
@@ -1784,21 +1793,17 @@
trace("io.c: close_fd_nicely called on fd %i: %z\n",
fd->fd, fd->label);
-
- fd->read = NULL;
+ /* Stop reading */
+ fd->read = NULL;
lsh_oop_cancel_read_fd(fd);
-
- if (fd->write_buffer)
- {
- /* Mark the write_buffer as closed */
- fd->write_buffer->closed = 1;
- if (!fd->write_buffer->empty)
- return;
- }
- /* There's no data buffered for write. */
- close_fd(fd);
+ if (fd->write_buffer)
+ /* Close after currently buffered data is written out. */
+ close_fd_write(fd);
+ else
+ /* There's no data buffered for write. */
+ close_fd(fd);
}
/* Stop reading, but if the fd has a write callback, keep it open. */
@@ -1822,6 +1827,19 @@
{
/* Mark the write_buffer as closed */
fd->write_buffer->closed = 1;
+
+ if (fd->type == IO_PTY)
+ {
+ debug("Writing ^D to pty.\n");
+ /* Is there any better way to signal EOF on a pty? This is
+ * what emacs does. */
+ A_WRITE(&fd->write_buffer->super,
+ ssh_format("%lc", /* C-d */ 4));
+
+ /* No need to repeat this. */
+ fd->type = 0;
+ }
+
if (fd->write_buffer->empty)
{
if (!fd->read)
Index: src/io.h
===================================================================
RCS file: /cvsroot/lsh/lsh/src/io.h,v
retrieving revision 1.89
diff -u -a -r1.89 io.h
--- src/io.h 29 May 2002 22:54:31 -0000 1.89
+++ src/io.h 18 Jun 2002 07:44:17 -0000
@@ -39,6 +39,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
+enum io_type { IO_PTY = 1 };
#define GABA_DECLARE
#include "io.h.x"
@@ -73,7 +74,9 @@
(vars
(next object lsh_fd)
(fd . int)
-
+ ; PTY:s need special treatment, as sutdown doesn't work.
+ (type . "enum io_type")
+
; For debugging purposes
(label . "const char *")
@@ -287,6 +290,8 @@
struct lsh_fd *
make_lsh_fd(int fd, const char *label,
struct exception_handler *e);
+void
+io_set_type(struct lsh_fd *fd, enum io_type type);
struct exception_handler *
make_exc_finish_read_handler(struct lsh_fd *fd,
Index: src/server_session.c
===================================================================
RCS file: /cvsroot/lsh/lsh/src/server_session.c,v
retrieving revision 1.84
diff -u -a -r1.84 server_session.c
--- src/server_session.c 29 May 2002 22:50:51 -0000 1.84
+++ src/server_session.c 18 Jun 2002 07:44:18 -0000
@@ -67,8 +67,9 @@
; Resource to kill when the channel is closed.
(process object lsh_process)
- ; pty
+ ; An allocated but not yet used pty
(pty object pty_info)
+
; value of the TERM environment variable
(term string)
@@ -132,15 +133,7 @@
CAST(server_session, session, channel);
trace("server_session.c: do_eof\n");
-
- if (session->pty)
- /* Is there any better way to signal EOF on a pty? This is what
- * emacs does. */
- /* FIXME: This should be handled specially by close_fd_write, so
- * that we can ignore EPIPE errors. */
- A_WRITE(&session->in->write_buffer->super,
- ssh_format("%lc", /* C-d */ 4));
-
+
close_fd_write(session->in);
}
@@ -166,6 +159,9 @@
* is taken care of automatically. */
self->process = NULL;
+
+ self->pty = NULL;
+ self->term = NULL;
self->in = NULL;
self->out = NULL;
@@ -458,7 +454,10 @@
= io_write(make_lsh_fd(info->in[1], "child stdin",
io_exception_handler),
SSH_MAX_PACKET, NULL);
-
+
+ if (session->pty)
+ io_set_type(session->in, IO_PTY);
+
/* Flow control */
session->in->write_buffer->report = &session->super.super;