diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2007-11-27 20:01:30 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2007-11-27 20:01:30 +0000 |
commit | 5cd1d459c5351774dbcda51911278d781384bf0f (patch) | |
tree | 8da5e09bbf78870f9ce02c80577b47c188150b17 | |
parent | 2fabfb30b0275a0adc7b5bc0a260ab830d1f41ed (diff) | |
download | rtmux-5cd1d459c5351774dbcda51911278d781384bf0f.tar.gz rtmux-5cd1d459c5351774dbcda51911278d781384bf0f.tar.bz2 rtmux-5cd1d459c5351774dbcda51911278d781384bf0f.zip |
Three-stage exit process so that [] message printing works on detach etc.
-rw-r--r-- | client-msg.c | 16 | ||||
-rw-r--r-- | server-msg.c | 24 | ||||
-rw-r--r-- | server.c | 4 | ||||
-rw-r--r-- | tmux.h | 4 | ||||
-rw-r--r-- | tty.c | 12 |
5 files changed, 52 insertions, 8 deletions
diff --git a/client-msg.c b/client-msg.c index 4e299bc6..b90488a1 100644 --- a/client-msg.c +++ b/client-msg.c @@ -1,4 +1,4 @@ -/* $Id: client-msg.c,v 1.11 2007-11-27 19:23:33 nicm Exp $ */ +/* $Id: client-msg.c,v 1.12 2007-11-27 20:01:30 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -28,6 +28,7 @@ int client_msg_fn_detach(struct hdr *, struct client_ctx *, char **); int client_msg_fn_error(struct hdr *, struct client_ctx *, char **); int client_msg_fn_exit(struct hdr *, struct client_ctx *, char **); +int client_msg_fn_exited(struct hdr *, struct client_ctx *, char **); int client_msg_fn_okay(struct hdr *, struct client_ctx *, char **); int client_msg_fn_pause(struct hdr *, struct client_ctx *, char **); @@ -40,6 +41,7 @@ struct client_msg client_msg_table[] = { { MSG_DETACH, client_msg_fn_detach }, { MSG_ERROR, client_msg_fn_error }, { MSG_EXIT, client_msg_fn_exit }, + { MSG_EXITED, client_msg_fn_exited } }; #define NCLIENTMSG (sizeof client_msg_table / sizeof client_msg_table[0]) @@ -88,6 +90,18 @@ client_msg_fn_exit( if (hdr->size != 0) fatalx("bad MSG_EXIT size"); + client_write_server(cctx, MSG_EXITING, NULL, 0); + + return (0); +} + +int +client_msg_fn_exited( + struct hdr *hdr, unused struct client_ctx *cctx, unused char **error) +{ + if (hdr->size != 0) + fatalx("bad MSG_EXITED size"); + cctx->flags |= CCTX_EXIT; return (-1); diff --git a/server-msg.c b/server-msg.c index afa947bb..a9f77bc2 100644 --- a/server-msg.c +++ b/server-msg.c @@ -1,5 +1,5 @@ -/* $Id: server-msg.c,v 1.38 2007-11-27 19:23:34 nicm Exp $ */ +/* $Id: server-msg.c,v 1.39 2007-11-27 20:01:30 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -29,6 +29,7 @@ int server_msg_fn_command(struct hdr *, struct client *); int server_msg_fn_identify(struct hdr *, struct client *); int server_msg_fn_resize(struct hdr *, struct client *); +int server_msg_fn_exiting(struct hdr *, struct client *); void printflike2 server_msg_fn_command_error( struct cmd_ctx *, const char *, ...); @@ -44,6 +45,7 @@ const struct server_msg server_msg_table[] = { { MSG_IDENTIFY, server_msg_fn_identify }, { MSG_COMMAND, server_msg_fn_command }, { MSG_RESIZE, server_msg_fn_resize }, + { MSG_EXITING, server_msg_fn_exiting } }; #define NSERVERMSG (sizeof server_msg_table / sizeof server_msg_table[0]) @@ -238,3 +240,23 @@ server_msg_fn_resize(struct hdr *hdr, struct client *c) return (0); } + +int +server_msg_fn_exiting(struct hdr *hdr, struct client *c) +{ + if (hdr->size != 0) + fatalx("bad MSG_EXITING size"); + + log_debug("exiting msg from client"); + + c->session = NULL; + + if (c->tty.fd != -1) + tty_free(&c->tty); + + recalculate_sizes(); + + server_write_client(c, MSG_EXITED, NULL, 0); + + return (0); +} @@ -1,4 +1,4 @@ -/* $Id: server.c,v 1.40 2007-11-27 19:23:34 nicm Exp $ */ +/* $Id: server.c,v 1.41 2007-11-27 20:01:30 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -291,7 +291,7 @@ server_handle_clients(struct pollfd **pfd) } (*pfd)++; - if (c != NULL && c->tty.fd != -1) { + if (c != NULL && c->tty.fd != -1 && c->session != NULL) { if (buffer_poll(*pfd, c->tty.in, c->tty.out) != 0) server_lost_client(c); else @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.102 2007-11-27 19:32:15 nicm Exp $ */ +/* $Id: tmux.h,v 1.103 2007-11-27 20:01:30 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -289,6 +289,8 @@ enum hdrtype { MSG_ERROR, MSG_PRINT, MSG_EXIT, + MSG_EXITING, + MSG_EXITED, MSG_IDENTIFY, MSG_READY, MSG_DETACH, @@ -1,4 +1,4 @@ -/* $Id: tty.c,v 1.3 2007-11-27 19:43:50 nicm Exp $ */ +/* $Id: tty.c,v 1.4 2007-11-27 20:01:30 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -140,6 +140,8 @@ tty_close(struct tty *tty) tty_keys_free(tty); close(tty->fd); + tty->fd = -1; + buffer_destroy(tty->in); buffer_destroy(tty->out); } @@ -150,10 +152,14 @@ tty_free(struct tty *tty) if (tty->fd != -1) tty_close(tty); - if (tty->path != NULL) + if (tty->path != NULL) { xfree(tty->path); - if (tty->term != NULL) + tty->path = NULL; + } + if (tty->term != NULL) { xfree(tty->term); + tty->term = NULL; + } } void |