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.

This commit is contained in:
Nicholas Marriott 2008-06-02 21:08:36 +00:00
parent f6b86402c7
commit a26f58c7c3
27 changed files with 175 additions and 129 deletions

40
CHANGES
View File

@ -1,5 +1,43 @@
02 June 2008 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 * 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: 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 (including mutt, emacs). No status bar yet and no key remapping or other
customisation. 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 $

View File

@ -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 .SUFFIXES: .c .o .y .h
.PHONY: clean update-index.html upload-index.html .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-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-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-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 \ cmd-paste-buffer.c cmd-new-session.c cmd-start-server.c \
window-copy.c tty.c tty-keys.c tty-write.c screen-write.c screen-redraw.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 CC?= cc
INCDIRS+= -I. -I- -I/usr/local/include INCDIRS+= -I. -I- -I/usr/local/include

1
TODO
View File

@ -69,6 +69,7 @@
- tobiasu says it is borken on Linux with aterm + TERM=rxvt - 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 - poll(2) is broken on OS X/Darwin, a workaround for this would be nice
- different screen model? layers perhaps? hmm - 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 [18:20] *priteau* i found something in tmux that could be tweaked to be better

25
cfg.c
View File

@ -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> * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@ -73,7 +73,7 @@ load_cfg(const char *path, char **causep)
buf = NULL; buf = NULL;
len = 0; len = 0;
line = 1; line = 0;
while ((ch = getc(f)) != EOF) { while ((ch = getc(f)) != EOF) {
switch (ch) { switch (ch) {
case '#': case '#':
@ -98,17 +98,18 @@ load_cfg(const char *path, char **causep)
case EOF: case EOF:
case ' ': case ' ':
case '\t': case '\t':
if (len == 0) if (len != 0) {
break; buf[len] = '\0';
buf[len] = '\0';
argv = xrealloc(argv, argc + 1, sizeof (char *)); argv = xrealloc(
argv[argc++] = buf; argv, argc + 1, sizeof (char *));
argv[argc++] = buf;
buf = NULL;
len = 0; buf = NULL;
len = 0;
}
if (ch != '\n' && ch != EOF) if ((ch != '\n' && ch != EOF) || argc == 0)
break; break;
line++; line++;
@ -123,7 +124,7 @@ load_cfg(const char *path, char **causep)
ctx.print = cfg_print; ctx.print = cfg_print;
ctx.cmdclient = NULL; ctx.cmdclient = NULL;
ctx.flags = CMD_KEY; ctx.flags = 0;
cfg_cause = NULL; cfg_cause = NULL;
cmd_exec(cmd, &ctx); cmd_exec(cmd, &ctx);

View File

@ -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> * 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; int mode;
u_int retries; u_int retries;
struct buffer *b; struct buffer *b;
pid_t pid;
pid = 0;
retries = 0; retries = 0;
retry: retry:
if (stat(path, &sb) != 0) { if (stat(path, &sb) != 0) {
if (start_server && errno == ENOENT && retries < 10) { if (start_server && errno == ENOENT && retries < 10) {
if (server_start(path) != 0) if (pid == 0)
return (-1); pid = server_start(path);
usleep(10000); usleep(10000);
retries++; retries++;
goto retry; goto retry;
@ -112,7 +114,7 @@ retry:
fail: fail:
log_warn("server not found"); log_warn("server not found");
return (-1); return (1);
} }
int int

View File

@ -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> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -79,7 +79,7 @@ cmd_attach_session_parse(
return (0); return (0);
usage: 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); cmd_attach_session_free(data);
return (-1); return (-1);

View File

@ -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> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -82,7 +82,7 @@ cmd_bind_key_parse(
return (0); return (0);
usage: usage:
usage(cause, "%s %s", self->entry->name, self->entry->usage); xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
error: error:
cmd_bind_key_free(data); cmd_bind_key_free(data);

View File

@ -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> * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@ -57,7 +57,7 @@ cmd_clientonly_parse(
return (0); return (0);
usage: 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); self->entry->free(data);
return (-1); return (-1);
@ -129,7 +129,7 @@ cmd_sessiononly_parse(
return (0); return (0);
usage: 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); self->entry->free(data);
return (-1); return (-1);

View File

@ -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> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -24,27 +24,30 @@
#include "tmux.h" #include "tmux.h"
/* /*
* Cause client to exit with 0 if session exists, or 1 if it doesn't. This * Cause client to report an error and exit with 1 if session doesn't exist.
* is handled in the caller since this doesn't have flag CMD_NOSESSION, so
* all that is necessary is to exit.
*/ */
void cmd_has_session_exec(void *, struct cmd_ctx *); void cmd_has_session_exec(void *, struct cmd_ctx *);
const struct cmd_entry cmd_has_session_entry = { const struct cmd_entry cmd_has_session_entry = {
"has-session", "has", "has-session", "has",
"", CMD_SESSIONONLY_USAGE,
0, 0,
NULL, cmd_sessiononly_parse,
cmd_has_session_exec, cmd_has_session_exec,
NULL, cmd_sessiononly_send,
NULL, cmd_sessiononly_recv,
NULL cmd_sessiononly_free
}; };
void 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) if (ctx->cmdclient != NULL)
server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0); server_write_client(ctx->cmdclient, MSG_EXIT, NULL, 0);
} }

View File

@ -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> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -85,7 +85,7 @@ cmd_kill_window_parse(
return (0); return (0);
usage: usage:
usage(cause, "%s %s", self->entry->name, self->entry->usage); xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
error: error:
cmd_kill_window_free(data); cmd_kill_window_free(data);

View File

@ -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> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -106,7 +106,7 @@ cmd_link_window_parse(
return (0); return (0);
usage: usage:
usage(cause, "%s %s", self->entry->name, self->entry->usage); xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
error: error:
cmd_link_window_free(data); cmd_link_window_free(data);

View File

@ -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> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -89,7 +89,7 @@ cmd_new_session_parse(
return (0); return (0);
usage: 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); cmd_new_session_free(data);
return (-1); 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 *data = ptr;
struct cmd_new_session_data std = { NULL, NULL, NULL, 0 }; struct cmd_new_session_data std = { NULL, NULL, NULL, 0 };
struct client *c = ctx->cmdclient; struct client *c = ctx->cmdclient;
struct session *s;
char *cmd, *cause; char *cmd, *cause;
u_int sy; u_int sx, sy;
if (data == NULL) if (data == NULL)
data = &std; data = &std;
@ -110,9 +111,15 @@ cmd_new_session_exec(void *ptr, struct cmd_ctx *ctx)
if (ctx->flags & CMD_KEY) if (ctx->flags & CMD_KEY)
return; return;
if (!data->flag_detached && !(c->flags & CLIENT_TERMINAL)) { if (!data->flag_detached) {
ctx->error(ctx, "not a terminal"); if (c == NULL) {
return; 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) { if (data->name != NULL && session_find(data->name) != NULL) {
@ -120,7 +127,16 @@ cmd_new_session_exec(void *ptr, struct cmd_ctx *ctx)
return; 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) if (sy < status_lines)
sy = status_lines + 1; sy = status_lines + 1;
sy -= status_lines; sy -= status_lines;
@ -131,21 +147,19 @@ cmd_new_session_exec(void *ptr, struct cmd_ctx *ctx)
return; return;
} }
cmd = data->cmd;
if (cmd == NULL)
cmd = default_command;
c->session = session_create(data->name, cmd, c->sx, sy); if ((s = session_create(data->name, cmd, sx, sy)) == NULL)
if (c->session == NULL)
fatalx("session_create failed"); fatalx("session_create failed");
if (data->winname != NULL) { if (data->winname != NULL) {
xfree(c->session->curw->window->name); xfree(s->curw->window->name);
c->session->curw->window->name = xstrdup(data->winname); s->curw->window->name = xstrdup(data->winname);
} }
if (data->flag_detached) if (data->flag_detached) {
server_write_client(c, MSG_EXIT, NULL, 0); if (c != NULL)
else { server_write_client(c, MSG_EXIT, NULL, 0);
} else {
c->session = s;
server_write_client(c, MSG_READY, NULL, 0); server_write_client(c, MSG_READY, NULL, 0);
server_redraw_client(c); server_redraw_client(c);
} }

View File

@ -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> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -100,7 +100,7 @@ cmd_new_window_parse(
return (0); return (0);
usage: usage:
usage(cause, "%s %s", self->entry->name, self->entry->usage); xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
error: error:
cmd_new_window_free(data); cmd_new_window_free(data);

View File

@ -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> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -79,7 +79,7 @@ cmd_rename_session_parse(
return (0); return (0);
usage: 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); cmd_rename_session_free(data);
return (-1); return (-1);

View File

@ -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> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -89,7 +89,7 @@ cmd_rename_window_parse(
return (0); return (0);
usage: usage:
usage(cause, "%s %s", self->entry->name, self->entry->usage); xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
error: error:
cmd_rename_window_free(data); cmd_rename_window_free(data);

View File

@ -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> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -98,7 +98,7 @@ cmd_select_window_parse(
return (0); return (0);
usage: usage:
usage(cause, "%s %s", self->entry->name, self->entry->usage); xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
error: error:
cmd_select_window_free(data); cmd_select_window_free(data);

View File

@ -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> * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@ -95,7 +95,7 @@ cmd_send_keys_parse(
return (0); return (0);
usage: 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); cmd_send_keys_free(data);
return (-1); return (-1);

View File

@ -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> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -79,7 +79,7 @@ cmd_set_option_parse(
return (0); return (0);
usage: 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); cmd_set_option_free(data);
return (-1); return (-1);

View File

@ -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> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -101,7 +101,7 @@ cmd_swap_window_parse(
return (0); return (0);
usage: usage:
usage(cause, "%s %s", self->entry->name, self->entry->usage); xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
error: error:
cmd_swap_window_free(data); cmd_swap_window_free(data);

View File

@ -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> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -80,7 +80,7 @@ cmd_switch_client_parse(
return (0); return (0);
usage: 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); cmd_switch_client_free(data);
return (-1); return (-1);

View File

@ -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> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -75,7 +75,7 @@ cmd_unbind_key_parse(
return (0); return (0);
usage: usage:
usage(cause, "%s %s", self->entry->name, self->entry->usage); xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
error: error:
xfree(data); xfree(data);

View File

@ -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> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -85,7 +85,7 @@ cmd_unlink_window_parse(
return (0); return (0);
usage: usage:
usage(cause, "%s %s", self->entry->name, self->entry->usage); xasprintf(cause, "usage: %s %s", self->entry->name, self->entry->usage);
error: error:
cmd_unlink_window_free(data); cmd_unlink_window_free(data);

5
cmd.c
View File

@ -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> * 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_keys_entry,
&cmd_send_prefix_entry, &cmd_send_prefix_entry,
&cmd_set_option_entry, &cmd_set_option_entry,
&cmd_start_server_entry,
&cmd_swap_window_entry, &cmd_swap_window_entry,
&cmd_switch_client_entry, &cmd_switch_client_entry,
&cmd_unbind_key_entry, &cmd_unbind_key_entry,
@ -128,7 +129,7 @@ ambiguous:
return (NULL); return (NULL);
usage: usage:
usage(cause, "%s %s", entry->name, entry->usage); xasprintf(cause, "usage: %s %s", entry->name, entry->usage);
return (NULL); return (NULL);
} }

View File

@ -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> * 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 *); void server_lost_window(struct window *);
/* Fork new server. */ /* Fork new server. */
int pid_t
server_start(const char *path) server_start(const char *path)
{ {
struct sockaddr_un sa; struct sockaddr_un sa;
size_t size; size_t size;
mode_t mask; mode_t mask;
int n, fd, mode; int n, fd, mode;
pid_t pid;
char *cause; char *cause;
switch (fork()) { switch (pid = fork()) {
case -1: case -1:
fatal("fork"); fatal("fork");
case 0: case 0:
break; break;
default: default:
return (0); return (pid);
} }
#ifdef DEBUG #ifdef DEBUG
xmalloc_clear(); xmalloc_clear();
#endif #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"); logfile("server");
#ifndef NO_SETPROCTITLE #ifndef NO_SETPROCTITLE
setproctitle("server (%s)", path); setproctitle("server (%s)", path);
@ -110,17 +121,10 @@ server_start(const char *path)
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
fatal("fcntl failed"); 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) if (daemon(1, 1) != 0)
fatal("daemon failed"); fatal("daemon failed");
log_debug("server daemonised, pid now %ld", (long) getpid()); log_debug("server daemonised, pid now %ld", (long) getpid());
n = server_main(path, fd); n = server_main(path, fd);
#ifdef DEBUG #ifdef DEBUG
xmalloc_report(getpid(), "server"); xmalloc_report(getpid(), "server");
@ -137,12 +141,6 @@ server_main(const char *srv_path, int srv_fd)
u_int i; u_int i;
siginit(); siginit();
ARRAY_INIT(&windows);
ARRAY_INIT(&clients);
ARRAY_INIT(&sessions);
key_bindings_init();
pfds = NULL; pfds = NULL;
while (!sigterm) { while (!sigterm) {

View File

@ -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> * 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); session_select(s, 0);
log_debug("session %s created", s->name);
return (s); return (s);
} }
@ -126,6 +128,8 @@ session_destroy(struct session *s)
{ {
u_int i; u_int i;
log_debug("session %s destroyed", s->name);
if (session_index(s, &i) != 0) if (session_index(s, &i) != 0)
fatalx("session not found"); fatalx("session not found");
ARRAY_SET(&sessions, i, NULL); ARRAY_SET(&sessions, i, NULL);

37
tmux.c
View File

@ -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> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -53,25 +53,15 @@ u_int history_limit;
u_int status_lines; u_int status_lines;
void sighandler(int); void sighandler(int);
__dead void usage(void);
void __dead void
usage(char **ptr, const char *fmt, ...) usage(void)
{ {
char *msg; fprintf(stderr,
va_list ap; "usage: %s [-v] [-f file] [-S socket-path] command [flags]",
__progname);
#define USAGE "usage: %s [-v] [-f file] [-S socket-path]" exit(1);
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
} }
void void
@ -202,13 +192,13 @@ main(int argc, char **argv)
printf("%s " BUILD "\n", __progname); printf("%s " BUILD "\n", __progname);
exit(0); exit(0);
default: default:
goto usage; usage();
} }
} }
argc -= optind; argc -= optind;
argv += optind; argv += optind;
if (argc == 0) if (argc == 0)
goto usage; usage();
log_open(stderr, LOG_USER, debug_level); log_open(stderr, LOG_USER, debug_level);
siginit(); siginit();
@ -275,8 +265,6 @@ main(int argc, char **argv)
xasprintf(&default_command, "exec %s", shell); xasprintf(&default_command, "exec %s", shell);
if ((cmd = cmd_parse(argc, argv, &cause)) == NULL) { if ((cmd = cmd_parse(argc, argv, &cause)) == NULL) {
if (cause == NULL)
goto usage;
log_warnx("%s", cause); log_warnx("%s", cause);
exit(1); exit(1);
} }
@ -354,9 +342,4 @@ out:
xmalloc_report(getpid(), "client"); xmalloc_report(getpid(), "client");
#endif #endif
return (n); return (n);
usage:
usage(&cause, NULL);
fprintf(stderr, "%s\n", cause);
exit(1);
} }

6
tmux.h
View File

@ -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> * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -693,7 +693,6 @@ extern int prefix_key;
extern u_char status_colour; extern u_char status_colour;
extern u_int history_limit; extern u_int history_limit;
extern u_int status_lines; extern u_int status_lines;
void usage(char **, const char *, ...);
void logfile(const char *); void logfile(const char *);
void siginit(void); void siginit(void);
void sigreset(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_keys_entry;
extern const struct cmd_entry cmd_send_prefix_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_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_swap_window_entry;
extern const struct cmd_entry cmd_switch_client_entry; extern const struct cmd_entry cmd_switch_client_entry;
extern const struct cmd_entry cmd_unbind_key_entry; extern const struct cmd_entry cmd_unbind_key_entry;
@ -809,7 +809,7 @@ const char *key_string_lookup_key(int);
/* server.c */ /* server.c */
extern struct clients clients; extern struct clients clients;
int server_start(const char *); pid_t server_start(const char *);
/* server-msg.c */ /* server-msg.c */
int server_msg_dispatch(struct client *); int server_msg_dispatch(struct client *);