summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2008-06-02 21:08:36 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2008-06-02 21:08:36 +0000
commita26f58c7c394f81c523da597f85f69d3fc8bc8ad (patch)
tree869e58ba4df84531d550002ccb2a856ed5db2577
parentf6b86402c7fd1f4af0e4d163f22e4b9f71b2e538 (diff)
Last bits of basic configuration file. By default in ~/.tmux.conf or specified with -f. Just a list of tmux commands executed when the server is started and before and any session/window is created.
-rw-r--r--CHANGES40
-rw-r--r--Makefile7
-rw-r--r--TODO1
-rw-r--r--cfg.c25
-rw-r--r--client.c10
-rw-r--r--cmd-attach-session.c4
-rw-r--r--cmd-bind-key.c4
-rw-r--r--cmd-generic.c6
-rw-r--r--cmd-has-session.c23
-rw-r--r--cmd-kill-window.c4
-rw-r--r--cmd-link-window.c4
-rw-r--r--cmd-new-session.c48
-rw-r--r--cmd-new-window.c4
-rw-r--r--cmd-rename-session.c4
-rw-r--r--cmd-rename-window.c4
-rw-r--r--cmd-select-window.c4
-rw-r--r--cmd-send-keys.c4
-rw-r--r--cmd-set-option.c4
-rw-r--r--cmd-swap-window.c4
-rw-r--r--cmd-switch-client.c4
-rw-r--r--cmd-unbind-key.c4
-rw-r--r--cmd-unlink-window.c4
-rw-r--r--cmd.c5
-rw-r--r--server.c34
-rw-r--r--session.c6
-rw-r--r--tmux.c37
-rw-r--r--tmux.h6
27 files changed, 175 insertions, 129 deletions
diff --git a/CHANGES b/CHANGES
index 93b3dafc..3e665e91 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,43 @@
02 June 2008
+* New command, start-server (alias "start"), to start the tmux server and do
+ nothing else. This is good if you have a configuration file which creates
+ windows or sessions (like me): in that case, starting the server the first
+ time tmux new is run is bad since it creates a new session and window (as
+ it is supposed to - starting the server is a side-effect).
+
+ Instead, I have a little script which does the equivalent of:
+
+ tmux has -s0 2>/dev/null || tmux start
+ tmux attach -d -s0
+
+ And I use it to start the server if necessary and attach to my primary
+ session.
+* Basic configuration file in ~/.tmux.conf or specified with -f. This is file
+ contains a set of tmux commands that are run the first time the server is
+ started. The configuration commands are executed before any others, so
+ if you have a configuration file that contains:
+
+ new -d
+ neww -s0
+
+ And you do the following without an existing server running:
+
+ tmux new
+
+ You will end up with two sessions, session 0 with two windows (created by
+ the configuration file) and your client attached to session 1 with one
+ window (created by the command-line command). I'm not completely happy with
+ this, it seems a little non-obvious, but I haven't yet decided what to do
+ about it.
+
+ There is no environment variable handling or other special stuff yet.
+
+ In the future, it might be nice to be able to have per-session configuration
+ settings, probably by having conditionals in the file (so you could, for
+ example, have commands to define a particular window layout that would only
+ be invoked if you called tmux new -smysession and mysession did not already
+ exist).
* BIG CHANGE: -s and -c to specify session name and client name are now passed
after the command rather than before it. So, for example:
@@ -330,4 +368,4 @@
(including mutt, emacs). No status bar yet and no key remapping or other
customisation.
-$Id: CHANGES,v 1.97 2008-06-02 18:08:16 nicm Exp $
+$Id: CHANGES,v 1.98 2008-06-02 21:08:36 nicm Exp $
diff --git a/Makefile b/Makefile
index c32e7201..40d2545f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.54 2008-06-02 18:08:16 nicm Exp $
+# $Id: Makefile,v 1.55 2008-06-02 21:08:36 nicm Exp $
.SUFFIXES: .c .o .y .h
.PHONY: clean update-index.html upload-index.html
@@ -27,8 +27,9 @@ SRCS= tmux.c server.c server-msg.c server-fn.c buffer.c buffer-poll.c status.c \
cmd-link-window.c cmd-unlink-window.c cmd-next-window.c cmd-send-keys.c \
cmd-swap-window.c cmd-rename-session.c cmd-kill-session.c \
cmd-switch-client.c cmd-has-session.c cmd-scroll-mode.c cmd-copy-mode.c \
- cmd-paste-buffer.c cmd-new-session.c window-scroll.c window-more.c \
- window-copy.c tty.c tty-keys.c tty-write.c screen-write.c screen-redraw.c
+ cmd-paste-buffer.c cmd-new-session.c cmd-start-server.c \
+ window-scroll.c window-more.c window-copy.c \
+ tty.c tty-keys.c tty-write.c screen-write.c screen-redraw.c
CC?= cc
INCDIRS+= -I. -I- -I/usr/local/include
diff --git a/TODO b/TODO
index 4fcdc6fc..627da0f0 100644
--- a/TODO
+++ b/TODO
@@ -69,6 +69,7 @@
- tobiasu says it is borken on Linux with aterm + TERM=rxvt
- poll(2) is broken on OS X/Darwin, a workaround for this would be nice
- different screen model? layers perhaps? hmm
+- cfg file improvements: * comments to EOL
---
[18:20] *priteau* i found something in tmux that could be tweaked to be better
diff --git a/cfg.c b/cfg.c
index 88a5f0cd..540ca336 100644
--- a/cfg.c
+++ b/cfg.c
@@ -1,4 +1,4 @@
-/* $Id: cfg.c,v 1.3 2008-06-02 18:55:53 nicm Exp $ */
+/* $Id: cfg.c,v 1.4 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -73,7 +73,7 @@ load_cfg(const char *path, char **causep)
buf = NULL;
len = 0;
- line = 1;
+ line = 0;
while ((ch = getc(f)) != EOF) {
switch (ch) {
case '#':
@@ -98,17 +98,18 @@ load_cfg(const char *path, char **causep)
case EOF:
case ' ':
case '\t':
- if (len == 0)
- break;
- buf[len] = '\0';
-
- argv = xrealloc(argv, argc + 1, sizeof (char *));
- argv[argc++] = buf;
+ if (len != 0) {
+ buf[len] = '\0';
- buf = NULL;
- len = 0;
+ argv = xrealloc(
+ argv, argc + 1, sizeof (char *));
+ argv[argc++] = buf;
+
+ buf = NULL;
+ len = 0;
+ }
- if (ch != '\n' && ch != EOF)
+ if ((ch != '\n' && ch != EOF) || argc == 0)
break;
line++;
@@ -123,7 +124,7 @@ load_cfg(const char *path, char **causep)
ctx.print = cfg_print;
ctx.cmdclient = NULL;
- ctx.flags = CMD_KEY;
+ ctx.flags = 0;
cfg_cause = NULL;
cmd_exec(cmd, &ctx);
diff --git a/client.c b/client.c
index 42056faa..59e69875 100644
--- a/client.c
+++ b/client.c
@@ -1,4 +1,4 @@
-/* $Id: client.c,v 1.27 2008-06-01 21:24:33 nicm Exp $ */
+/* $Id: client.c,v 1.28 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -45,13 +45,15 @@ client_init(const char *path, struct client_ctx *cctx, int start_server)
int mode;
u_int retries;
struct buffer *b;
+ pid_t pid;
+ pid = 0;
retries = 0;
retry:
if (stat(path, &sb) != 0) {
if (start_server && errno == ENOENT && retries < 10) {
- if (server_start(path) != 0)
- return (-1);
+ if (pid == 0)
+ pid = server_start(path);
usleep(10000);
retries++;
goto retry;
@@ -112,7 +114,7 @@ retry:
fail:
log_warn("server not found");
- return (-1);
+ return (1);
}
int
diff --git a/cmd-attach-session.c b/cmd-attach-session.c
index e9c336df..f11a93f1 100644
--- a/cmd-attach-session.c
+++ b/cmd-attach-session.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-attach-session.c,v 1.12 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-attach-session.c,v 1.13 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -79,7 +79,7 @@ cmd_attach_session_parse(
return (0);
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
cmd_attach_session_free(data);
return (-1);
diff --git a/cmd-bind-key.c b/cmd-bind-key.c
index cff6c445..3ad55797 100644
--- a/cmd-bind-key.c
+++ b/cmd-bind-key.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-bind-key.c,v 1.9 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-bind-key.c,v 1.10 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -82,7 +82,7 @@ cmd_bind_key_parse(
return (0);
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
error:
cmd_bind_key_free(data);
diff --git a/cmd-generic.c b/cmd-generic.c
index 49d0f9a4..a27f5924 100644
--- a/cmd-generic.c
+++ b/cmd-generic.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-generic.c,v 1.1 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-generic.c,v 1.2 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -57,7 +57,7 @@ cmd_clientonly_parse(
return (0);
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
self->entry->free(data);
return (-1);
@@ -129,7 +129,7 @@ cmd_sessiononly_parse(
return (0);
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
self->entry->free(data);
return (-1);
diff --git a/cmd-has-session.c b/cmd-has-session.c
index b7d14a48..ff724d4a 100644
--- a/cmd-has-session.c
+++ b/cmd-has-session.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-has-session.c,v 1.4 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-has-session.c,v 1.5 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -24,27 +24,30 @@
#include "tmux.h"
/*
- * Cause client to exit with 0 if session exists, or 1 if it doesn't. This
- * is handled in the caller since this doesn't have flag CMD_NOSESSION, so
- * all that is necessary is to exit.
+ * Cause client to report an error and exit with 1 if session doesn't exist.
*/
void cmd_has_session_exec(void *, struct cmd_ctx *);
const struct cmd_entry cmd_has_session_entry = {
"has-session", "has",
- "",
+ CMD_SESSIONONLY_USAGE,
0,
- NULL,
+ cmd_sessiononly_parse,
cmd_has_session_exec,
- NULL,
- NULL,
- NULL
+ cmd_sessiononly_send,
+ cmd_sessiononly_recv,
+ cmd_sessiononly_free
};
void
-cmd_has_session_exec(unused void *ptr, struct cmd_ctx *ctx)
+cmd_has_session_exec(void *ptr, struct cmd_ctx *ctx)
{
+ struct session *s;
+
+ if ((s = cmd_sessiononly_get(ptr, ctx)) == NULL)
+ return;
+
if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
}
diff --git a/cmd-kill-window.c b/cmd-kill-window.c
index 5370fdc3..ad859302 100644
--- a/cmd-kill-window.c
+++ b/cmd-kill-window.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-kill-window.c,v 1.8 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-kill-window.c,v 1.9 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -85,7 +85,7 @@ cmd_kill_window_parse(
return (0);
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
error:
cmd_kill_window_free(data);
diff --git a/cmd-link-window.c b/cmd-link-window.c
index 72b2e03b..89e39732 100644
--- a/cmd-link-window.c
+++ b/cmd-link-window.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-link-window.c,v 1.11 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-link-window.c,v 1.12 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -106,7 +106,7 @@ cmd_link_window_parse(
return (0);
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
error:
cmd_link_window_free(data);
diff --git a/cmd-new-session.c b/cmd-new-session.c
index 02975173..b7fffee7 100644
--- a/cmd-new-session.c
+++ b/cmd-new-session.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-new-session.c,v 1.20 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-new-session.c,v 1.21 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -89,7 +89,7 @@ cmd_new_session_parse(
return (0);
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
cmd_new_session_free(data);
return (-1);
@@ -101,8 +101,9 @@ cmd_new_session_exec(void *ptr, struct cmd_ctx *ctx)
struct cmd_new_session_data *data = ptr;
struct cmd_new_session_data std = { NULL, NULL, NULL, 0 };
struct client *c = ctx->cmdclient;
+ struct session *s;
char *cmd, *cause;
- u_int sy;
+ u_int sx, sy;
if (data == NULL)
data = &std;
@@ -110,9 +111,15 @@ cmd_new_session_exec(void *ptr, struct cmd_ctx *ctx)
if (ctx->flags & CMD_KEY)
return;
- if (!data->flag_detached && !(c->flags & CLIENT_TERMINAL)) {
- ctx->error(ctx, "not a terminal");
- return;
+ if (!data->flag_detached) {
+ if (c == NULL) {
+ ctx->error(ctx, "no client to attach to");
+ return;
+ }
+ if (!(c->flags & CLIENT_TERMINAL)) {
+ ctx->error(ctx, "not a terminal");
+ return;
+ }
}
if (data->name != NULL && session_find(data->name) != NULL) {
@@ -120,7 +127,16 @@ cmd_new_session_exec(void *ptr, struct cmd_ctx *ctx)
return;
}
- sy = c->sy;
+ cmd = data->cmd;
+ if (cmd == NULL)
+ cmd = default_command;
+
+ sx = 80;
+ sy = 25;
+ if (!data->flag_detached) {
+ sx = c->sx;
+ sy = c->sy;
+ }
if (sy < status_lines)
sy = status_lines + 1;
sy -= status_lines;
@@ -131,21 +147,19 @@ cmd_new_session_exec(void *ptr, struct cmd_ctx *ctx)
return;
}
- cmd = data->cmd;
- if (cmd == NULL)
- cmd = default_command;
- c->session = session_create(data->name, cmd, c->sx, sy);
- if (c->session == NULL)
+ if ((s = session_create(data->name, cmd, sx, sy)) == NULL)
fatalx("session_create failed");
if (data->winname != NULL) {
- xfree(c->session->curw->window->name);
- c->session->curw->window->name = xstrdup(data->winname);
+ xfree(s->curw->window->name);
+ s->curw->window->name = xstrdup(data->winname);
}
- if (data->flag_detached)
- server_write_client(c, MSG_EXIT, NULL, 0);
- else {
+ if (data->flag_detached) {
+ if (c != NULL)
+ server_write_client(c, MSG_EXIT, NULL, 0);
+ } else {
+ c->session = s;
server_write_client(c, MSG_READY, NULL, 0);
server_redraw_client(c);
}
diff --git a/cmd-new-window.c b/cmd-new-window.c
index 3ee85c17..e930de56 100644
--- a/cmd-new-window.c
+++ b/cmd-new-window.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-new-window.c,v 1.15 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-new-window.c,v 1.16 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -100,7 +100,7 @@ cmd_new_window_parse(
return (0);
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
error:
cmd_new_window_free(data);
diff --git a/cmd-rename-session.c b/cmd-rename-session.c
index 8a057543..7007350b 100644
--- a/cmd-rename-session.c
+++ b/cmd-rename-session.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-rename-session.c,v 1.5 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-rename-session.c,v 1.6 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -79,7 +79,7 @@ cmd_rename_session_parse(
return (0);
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
cmd_rename_session_free(data);
return (-1);
diff --git a/cmd-rename-window.c b/cmd-rename-window.c
index c0d20acf..4ff5f873 100644
--- a/cmd-rename-window.c
+++ b/cmd-rename-window.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-rename-window.c,v 1.15 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-rename-window.c,v 1.16 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -89,7 +89,7 @@ cmd_rename_window_parse(
return (0);
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
error:
cmd_rename_window_free(data);
diff --git a/cmd-select-window.c b/cmd-select-window.c
index c3eee8b9..db1894af 100644
--- a/cmd-select-window.c
+++ b/cmd-select-window.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-select-window.c,v 1.12 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-select-window.c,v 1.13 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -98,7 +98,7 @@ cmd_select_window_parse(
return (0);
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
error:
cmd_select_window_free(data);
diff --git a/cmd-send-keys.c b/cmd-send-keys.c
index c4ffc366..842dfed1 100644
--- a/cmd-send-keys.c
+++ b/cmd-send-keys.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-send-keys.c,v 1.2 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-send-keys.c,v 1.3 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -95,7 +95,7 @@ cmd_send_keys_parse(
return (0);
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
cmd_send_keys_free(data);
return (-1);
diff --git a/cmd-set-option.c b/cmd-set-option.c
index b349b0eb..25d47d55 100644
--- a/cmd-set-option.c
+++ b/cmd-set-option.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-set-option.c,v 1.16 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-set-option.c,v 1.17 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -79,7 +79,7 @@ cmd_set_option_parse(
return (0);
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
cmd_set_option_free(data);
return (-1);
diff --git a/cmd-swap-window.c b/cmd-swap-window.c
index 4044ad84..7f3c9918 100644
--- a/cmd-swap-window.c
+++ b/cmd-swap-window.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-swap-window.c,v 1.5 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-swap-window.c,v 1.6 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -101,7 +101,7 @@ cmd_swap_window_parse(
return (0);
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
error:
cmd_swap_window_free(data);
diff --git a/cmd-switch-client.c b/cmd-switch-client.c
index 45373469..24fbf2ab 100644
--- a/cmd-switch-client.c
+++ b/cmd-switch-client.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-switch-client.c,v 1.3 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-switch-client.c,v 1.4 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -80,7 +80,7 @@ cmd_switch_client_parse(
return (0);
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
cmd_switch_client_free(data);
return (-1);
diff --git a/cmd-unbind-key.c b/cmd-unbind-key.c
index 68e61dec..9d7e6693 100644
--- a/cmd-unbind-key.c
+++ b/cmd-unbind-key.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-unbind-key.c,v 1.9 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-unbind-key.c,v 1.10 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -75,7 +75,7 @@ cmd_unbind_key_parse(
return (0);
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
error:
xfree(data);
diff --git a/cmd-unlink-window.c b/cmd-unlink-window.c
index 46f45035..e1c88f23 100644
--- a/cmd-unlink-window.c
+++ b/cmd-unlink-window.c
@@ -1,4 +1,4 @@
-/* $Id: cmd-unlink-window.c,v 1.6 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd-unlink-window.c,v 1.7 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -85,7 +85,7 @@ cmd_unlink_window_parse(
return (0);
usage:
- usage(cause, "%s %s", self->entry->name, self->entry->usage);
+ xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
error:
cmd_unlink_window_free(data);
diff --git a/cmd.c b/cmd.c
index 2232af16..159d76c0 100644
--- a/cmd.c
+++ b/cmd.c
@@ -1,4 +1,4 @@
-/* $Id: cmd.c,v 1.35 2008-06-02 18:08:16 nicm Exp $ */
+/* $Id: cmd.c,v 1.36 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -51,6 +51,7 @@ const struct cmd_entry *cmd_table[] = {
&cmd_send_keys_entry,
&cmd_send_prefix_entry,
&cmd_set_option_entry,
+ &cmd_start_server_entry,
&cmd_swap_window_entry,
&cmd_switch_client_entry,
&cmd_unbind_key_entry,
@@ -128,7 +129,7 @@ ambiguous:
return (NULL);
usage:
- usage(cause, "%s %s", entry->name, entry->usage);
+ xasprintf(cause, "usage: %s %s", entry->name, entry->usage);
return (NULL);
}
diff --git a/server.c b/server.c
index 8cfc607c..ed64b424 100644
--- a/server.c
+++ b/server.c
@@ -1,4 +1,4 @@
-/* $Id: server.c,v 1.46 2008-06-02 18:08:17 nicm Exp $ */
+/* $Id: server.c,v 1.47 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -55,28 +55,39 @@ void server_lost_client(struct client *);
void server_lost_window(struct window *);
/* Fork new server. */
-int
+pid_t
server_start(const char *path)
{
struct sockaddr_un sa;
size_t size;
mode_t mask;
int n, fd, mode;
+ pid_t pid;
char *cause;
- switch (fork()) {
+ switch (pid = fork()) {
case -1:
fatal("fork");
case 0:
break;
default:
- return (0);
+ return (pid);
}
#ifdef DEBUG
xmalloc_clear();
#endif
+ ARRAY_INIT(&windows);
+ ARRAY_INIT(&clients);
+ ARRAY_INIT(&sessions);
+ key_bindings_init();
+
+ if (cfg_file != NULL && load_cfg(cfg_file, &cause) != 0) {
+ log_warnx("%s", cause);
+ exit(1);
+ }
+
logfile("server");
#ifndef NO_SETPROCTITLE
setproctitle("server (%s)", path);
@@ -110,17 +121,10 @@ server_start(const char *path)
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
fatal("fcntl failed");
- /* Load configuration. */
- if (cfg_file != NULL && load_cfg(cfg_file, &cause) != 0) {
- log_warnx("%s", cause);
- xfree(cause);
- exit(1);
- }
-
if (daemon(1, 1) != 0)
fatal("daemon failed");
log_debug("server daemonised, pid now %ld", (long) getpid());
-
+
n = server_main(path, fd);
#ifdef DEBUG
xmalloc_report(getpid(), "server");
@@ -137,12 +141,6 @@ server_main(const char *srv_path, int srv_fd)
u_int i;
siginit();
-
- ARRAY_INIT(&windows);
- ARRAY_INIT(&clients);
- ARRAY_INIT(&sessions);
-
- key_bindings_init();
pfds = NULL;
while (!sigterm) {
diff --git a/session.c b/session.c
index 2ba32499..dc2ddce8 100644
--- a/session.c
+++ b/session.c
@@ -1,4 +1,4 @@
-/* $Id: session.c,v 1.30 2007-12-06 09:46:23 nicm Exp $ */
+/* $Id: session.c,v 1.31 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -117,6 +117,8 @@ session_create(const char *name, const char *cmd, u_int sx, u_int sy)
}
session_select(s, 0);
+ log_debug("session %s created", s->name);
+
return (s);
}
@@ -126,6 +128,8 @@ session_destroy(struct session *s)
{
u_int i;
+ log_debug("session %s destroyed", s->name);
+
if (session_index(s, &i) != 0)
fatalx("session not found");
ARRAY_SET(&sessions, i, NULL);
diff --git a/tmux.c b/tmux.c
index 89c7fca7..ca255b0c 100644
--- a/tmux.c
+++ b/tmux.c
@@ -1,4 +1,4 @@
-/* $Id: tmux.c,v 1.47 2008-06-02 18:08:17 nicm Exp $ */
+/* $Id: tmux.c,v 1.48 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -53,25 +53,15 @@ u_int history_limit;
u_int status_lines;
void sighandler(int);
+__dead void usage(void);
-void
-usage(char **ptr, const char *fmt, ...)
+__dead void
+usage(void)
{
- char *msg;
- va_list ap;
-
-#define USAGE "usage: %s [-v] [-f file] [-S socket-path]"
- if (fmt == NULL) {
- xasprintf(ptr, USAGE " command [flags]", __progname);
- } else {
- va_start(ap, fmt);
- xvasprintf(&msg, fmt, ap);
- va_end(ap);
-
- xasprintf(ptr, USAGE " %s", __progname, msg);
- xfree(msg);
- }
-#undef USAGE
+ fprintf(stderr,
+ "usage: %s [-v] [-f file] [-S socket-path] command [flags]",
+ __progname);
+ exit(1);
}
void
@@ -202,13 +192,13 @@ main(int argc, char **argv)
printf("%s " BUILD "\n", __progname);
exit(0);
default:
- goto usage;
+ usage();
}
}
argc -= optind;
argv += optind;
if (argc == 0)
- goto usage;
+ usage();
log_open(stderr, LOG_USER, debug_level);
siginit();
@@ -275,8 +265,6 @@ main(int argc, char **argv)
xasprintf(&default_command, "exec %s", shell);
if ((cmd = cmd_parse(argc, argv, &cause)) == NULL) {
- if (cause == NULL)
- goto usage;
log_warnx("%s", cause);
exit(1);
}
@@ -354,9 +342,4 @@ out:
xmalloc_report(getpid(), "client");
#endif
return (n);
-
-usage:
- usage(&cause, NULL);
- fprintf(stderr, "%s\n", cause);
- exit(1);
}
diff --git a/tmux.h b/tmux.h
index 830e059b..b9c71371 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1,4 +1,4 @@
-/* $Id: tmux.h,v 1.117 2008-06-02 18:08:17 nicm Exp $ */
+/* $Id: tmux.h,v 1.118 2008-06-02 21:08:36 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -693,7 +693,6 @@ extern int prefix_key;
extern u_char status_colour;
extern u_int history_limit;
extern u_int status_lines;
-void usage(char **, const char *, ...);
void logfile(const char *);
void siginit(void);
void sigreset(void);
@@ -759,6 +758,7 @@ extern const struct cmd_entry cmd_select_window_entry;
extern const struct cmd_entry cmd_send_keys_entry;
extern const struct cmd_entry cmd_send_prefix_entry;
extern const struct cmd_entry cmd_set_option_entry;
+extern const struct cmd_entry cmd_start_server_entry;
extern const struct cmd_entry cmd_swap_window_entry;
extern const struct cmd_entry cmd_switch_client_entry;
extern const struct cmd_entry cmd_unbind_key_entry;
@@ -809,7 +809,7 @@ const char *key_string_lookup_key(int);
/* server.c */
extern struct clients clients;
-int server_start(const char *);
+pid_t server_start(const char *);
/* server-msg.c */
int server_msg_dispatch(struct client *);