aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES4
-rw-r--r--Makefile4
-rw-r--r--client-msg.c16
-rw-r--r--client.c6
-rw-r--r--cmd-attach-session.c59
-rw-r--r--cmd.c3
-rw-r--r--server-msg.c14
-rw-r--r--server.c16
-rw-r--r--tmux.c20
-rw-r--r--tmux.h4
-rw-r--r--xmalloc-debug.c4
11 files changed, 121 insertions, 29 deletions
diff --git a/CHANGES b/CHANGES
index 507c7858..dc3cd777 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,7 @@
04 October 2007
+* (nicm) attach-session (can't believe I forgot it until now!) and list-windows
+ commands.
* (nicm) rename-window and select-window commands.
* (nicm) set-option command (alias set): "tmux set-option prefix ^A".
* (nicm) Key binding and unbinding is back.
@@ -110,5 +112,5 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
-$Id: CHANGES,v 1.30 2007-10-04 10:54:20 nicm Exp $
+$Id: CHANGES,v 1.31 2007-10-04 11:52:02 nicm Exp $
diff --git a/Makefile b/Makefile
index 95f5e7d8..4323ca85 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.21 2007-10-04 11:23:17 nicm Exp $
+# $Id: Makefile,v 1.22 2007-10-04 11:52:02 nicm Exp $
.SUFFIXES: .c .o .y .h
.PHONY: clean
@@ -22,7 +22,7 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
cmd-list-sessions.c cmd-new-window.c cmd-next-window.c cmd-bind-key.c \
cmd-unbind-key.c cmd-previous-window.c cmd-last-window.c cmd-list-keys.c \
cmd-set-option.c cmd-rename-window.c cmd-select-window.c \
- cmd-list-windows.c
+ cmd-list-windows.c cmd-attach-session.c
YACC= yacc -d
diff --git a/client-msg.c b/client-msg.c
index 6bcd8173..bea15246 100644
--- a/client-msg.c
+++ b/client-msg.c
@@ -1,4 +1,4 @@
-/* $Id: client-msg.c,v 1.6 2007-10-03 21:31:07 nicm Exp $ */
+/* $Id: client-msg.c,v 1.7 2007-10-04 11:52:02 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -27,6 +27,7 @@
int client_msg_fn_data(struct hdr *, struct client_ctx *, char **);
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_okay(struct hdr *, struct client_ctx *, char **);
int client_msg_fn_pause(struct hdr *, struct client_ctx *, char **);
@@ -39,6 +40,7 @@ struct client_msg client_msg_table[] = {
{ MSG_DATA, client_msg_fn_data },
{ MSG_DETACH, client_msg_fn_detach },
{ MSG_ERROR, client_msg_fn_error },
+ { MSG_EXIT, client_msg_fn_exit },
{ MSG_PAUSE, client_msg_fn_pause },
};
#define NCLIENTMSG (sizeof client_msg_table / sizeof client_msg_table[0])
@@ -103,6 +105,18 @@ client_msg_fn_error(struct hdr *hdr, struct client_ctx *cctx, char **error)
}
int
+client_msg_fn_exit(
+ struct hdr *hdr, unused struct client_ctx *cctx, char **error)
+{
+ if (hdr->size != 0)
+ fatalx("bad MSG_EXIT size");
+
+ *error = xstrdup("");
+
+ return (-1);
+}
+
+int
client_msg_fn_detach(
struct hdr *hdr, unused struct client_ctx *cctx, char **error)
{
diff --git a/client.c b/client.c
index 0c60d540..835c77fe 100644
--- a/client.c
+++ b/client.c
@@ -1,4 +1,4 @@
-/* $Id: client.c,v 1.11 2007-10-03 21:31:07 nicm Exp $ */
+/* $Id: client.c,v 1.12 2007-10-04 11:52:02 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -174,6 +174,10 @@ client_main(struct client_ctx *cctx)
local_done();
if (error != NULL) {
+ if (*error == '\0') {
+ printf("[exited]\n", error);
+ return (0);
+ }
printf("[error: %s]\n", error);
return (1);
}
diff --git a/cmd-attach-session.c b/cmd-attach-session.c
new file mode 100644
index 00000000..2f25d0a7
--- /dev/null
+++ b/cmd-attach-session.c
@@ -0,0 +1,59 @@
+/* $Id: cmd-attach-session.c,v 1.1 2007-10-04 11:52:03 nicm Exp $ */
+
+/*
+ * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include <getopt.h>
+
+#include "tmux.h"
+
+/*
+ * Attach existing session to the current terminal.
+ */
+
+void cmd_attach_session_exec(void *, struct cmd_ctx *);
+
+const struct cmd_entry cmd_attach_session_entry = {
+ CMD_ATTACHSESSION, "attach-session", "attach", 0,
+ NULL,
+ NULL,
+ cmd_attach_session_exec,
+ NULL,
+ NULL,
+ NULL
+};
+
+void
+cmd_attach_session_exec(unused void *ptr, struct cmd_ctx *ctx)
+{
+ struct client *c = ctx->client;
+ struct session *s = ctx->session;
+
+ if (ctx->flags & CMD_KEY)
+ return;
+
+ if (!(c->flags & CLIENT_TERMINAL)) {
+ ctx->error(ctx, "not a terminal");
+ return;
+ }
+
+ c->session = s;
+
+ server_write_client(c, MSG_READY, NULL, 0);
+ server_redraw_client(c);
+}
diff --git a/cmd.c b/cmd.c
index 63aea9ca..aaf56935 100644
--- a/cmd.c
+++ b/cmd.c
@@ -1,4 +1,4 @@
-/* $Id: cmd.c,v 1.11 2007-10-04 11:23:17 nicm Exp $ */
+/* $Id: cmd.c,v 1.12 2007-10-04 11:52:03 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -24,6 +24,7 @@
#include "tmux.h"
const struct cmd_entry *cmd_table[] = {
+ &cmd_attach_session_entry,
&cmd_bind_key_entry,
&cmd_detach_session_entry,
&cmd_last_window_entry,
diff --git a/server-msg.c b/server-msg.c
index 3352970a..ac67002d 100644
--- a/server-msg.c
+++ b/server-msg.c
@@ -1,4 +1,4 @@
-/* $Id: server-msg.c,v 1.22 2007-10-04 00:02:10 nicm Exp $ */
+/* $Id: server-msg.c,v 1.23 2007-10-04 11:52:03 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -118,6 +118,12 @@ server_msg_fn_command(struct hdr *hdr, struct client *c)
log_debug("got command %u %s from client %d",
cmd->entry->type, cmd->entry->name, c->fd);
+ ctx.error = server_msg_fn_command_error;
+ ctx.print = server_msg_fn_command_print;
+
+ ctx.client = c;
+ ctx.flags = 0;
+
if (cmd->entry->flags & CMD_NOSESSION)
ctx.session = NULL;
else {
@@ -129,12 +135,6 @@ server_msg_fn_command(struct hdr *hdr, struct client *c)
}
}
- ctx.error = server_msg_fn_command_error;
- ctx.print = server_msg_fn_command_print;
-
- ctx.client = c;
- ctx.flags = 0;
-
cmd_exec(cmd, &ctx);
cmd_free(cmd);
diff --git a/server.c b/server.c
index c6684ec4..fb033f87 100644
--- a/server.c
+++ b/server.c
@@ -1,4 +1,4 @@
-/* $Id: server.c,v 1.22 2007-10-04 00:02:10 nicm Exp $ */
+/* $Id: server.c,v 1.23 2007-10-04 11:52:03 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -62,7 +62,7 @@ server_start(char *path)
size_t sz;
pid_t pid;
mode_t mask;
- int fd, mode;
+ int n, fd, mode;
switch (pid = fork()) {
case -1:
@@ -74,6 +74,8 @@ server_start(char *path)
return (0);
}
+ xmalloc_clear();
+
logfile("server");
setproctitle("server (%s)", path);
log_debug("server started, pid %ld", (long) getpid());
@@ -103,15 +105,15 @@ server_start(char *path)
if (fcntl(fd, F_SETFL, mode|O_NONBLOCK) == -1)
fatal("fcntl failed");
- /*
- * Detach into the background. This means the PID changes which will
- * have to be fixed in some way at some point... XXX
- */
if (daemon(1, 1) != 0)
fatal("daemon failed");
log_debug("server daemonised, pid now %ld", (long) getpid());
- exit(server_main(path, fd));
+ n = server_main(path, fd);
+#ifdef DEBUG
+ xmalloc_report(getpid(), "server");
+#endif
+ exit(n);
}
/* Main server loop. */
diff --git a/tmux.c b/tmux.c
index e4d3f57a..3a38c3af 100644
--- a/tmux.c
+++ b/tmux.c
@@ -1,4 +1,4 @@
-/* $Id: tmux.c,v 1.28 2007-10-04 11:23:17 nicm Exp $ */
+/* $Id: tmux.c,v 1.29 2007-10-04 11:52:03 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -167,7 +167,7 @@ main(int argc, char **argv)
struct hdr hdr;
const char *shell;
char *path, *cause, name[MAXNAMELEN];
- int opt;
+ int n, opt;
*name = '\0';
path = NULL;
@@ -245,7 +245,8 @@ main(int argc, char **argv)
switch (hdr.type) {
case MSG_EXIT:
- exit(0);
+ n = 0;
+ goto out;
case MSG_PRINT:
if (hdr.size > INT_MAX - 1)
fatalx("bad MSG_PRINT size");
@@ -259,14 +260,21 @@ main(int argc, char **argv)
log_warnx("%.*s",
(int) hdr.size, BUFFER_OUT(cctx.srv_in));
buffer_remove(cctx.srv_in, hdr.size);
- exit(1);
+ n = 1;
+ goto out;
case MSG_READY:
- exit(client_main(&cctx));
+ n = client_main(&cctx);
+ goto out;
default:
fatalx("unexpected command");
}
}
- /* NOTREACHED */
+
+out:
+#ifdef DEBUG
+ xmalloc_report(getpid(), "client");
+#endif
+ return (n);
usage:
usage(&cause, NULL);
diff --git a/tmux.h b/tmux.h
index 706da178..88018747 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1,4 +1,4 @@
-/* $Id: tmux.h,v 1.46 2007-10-04 11:23:17 nicm Exp $ */
+/* $Id: tmux.h,v 1.47 2007-10-04 11:52:03 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -457,6 +457,7 @@ struct client_ctx {
/* Key/command line command. */
enum cmd_type {
+ CMD_ATTACHSESSION,
CMD_BINDKEY,
CMD_DETACHSESSION,
CMD_LASTWINDOW,
@@ -533,6 +534,7 @@ struct cmd *cmd_recv(struct buffer *);
void cmd_free(struct cmd *);
void cmd_send_string(struct buffer *, const char *);
char *cmd_recv_string(struct buffer *);
+extern const struct cmd_entry cmd_attach_session_entry;
extern const struct cmd_entry cmd_bind_key_entry;
extern const struct cmd_entry cmd_detach_session_entry;
extern const struct cmd_entry cmd_last_window_entry;
diff --git a/xmalloc-debug.c b/xmalloc-debug.c
index 051d96b7..4215e6e2 100644
--- a/xmalloc-debug.c
+++ b/xmalloc-debug.c
@@ -1,4 +1,4 @@
-/* $Id: xmalloc-debug.c,v 1.1 2007-07-25 23:13:18 nicm Exp $ */
+/* $Id: xmalloc-debug.c,v 1.2 2007-10-04 11:52:03 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -51,7 +51,7 @@ u_int xmalloc_mallocs;
u_int xmalloc_reallocs;
/* Print function. */
-#define XMALLOC_PRINT log_debug3
+#define XMALLOC_PRINT log_debug
/* Bytes of unallocated blocks and number of allocated blocks to show. */
#define XMALLOC_BYTES 8