summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2012-11-19 10:38:06 +0000
committerNicholas Marriott <nicm@openbsd.org>2012-11-19 10:38:06 +0000
commit827b311c8172f3543f9c38dc1d7740bba1d9aeaa (patch)
treedd900064b22c06b7f2d608d475288ae5000b0569
parentc68efec6c0f1a6ecf4950e4ddada4430fdea4156 (diff)
Use a utility function for common code to show errors in config file,
from Thomas Adam.
-rw-r--r--cfg.c22
-rw-r--r--cmd-new-session.c16
-rw-r--r--server.c21
-rw-r--r--tmux.h1
4 files changed, 31 insertions, 29 deletions
diff --git a/cfg.c b/cfg.c
index ead99818..ae7d9a30 100644
--- a/cfg.c
+++ b/cfg.c
@@ -173,3 +173,25 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
return (retval);
}
+
+void
+show_cfg_causes(struct session *s)
+{
+ struct window_pane *wp;
+ char *cause;
+ u_int i;
+
+ if (s == NULL || ARRAY_EMPTY(&cfg_causes))
+ return;
+
+ wp = s->curw->window->active;
+
+ window_pane_set_mode(wp, &window_copy_mode);
+ window_copy_init_for_output(wp);
+ for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
+ cause = ARRAY_ITEM(&cfg_causes, i);
+ window_copy_add(wp, "%s", cause);
+ free(cause);
+ }
+ ARRAY_FREE(&cfg_causes);
+}
diff --git a/cmd-new-session.c b/cmd-new-session.c
index cd1bc2b1..0fcea353 100644
--- a/cmd-new-session.c
+++ b/cmd-new-session.c
@@ -58,14 +58,13 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
struct args *args = self->args;
struct session *s, *old_s, *groupwith;
struct window *w;
- struct window_pane *wp;
struct environ env;
struct termios tio, *tiop;
struct passwd *pw;
const char *newname, *target, *update, *cwd, *errstr;
char *cmd, *cause;
int detached, idx;
- u_int sx, sy, i;
+ u_int sx, sy;
newname = args_get(args, 's');
if (newname != NULL) {
@@ -257,17 +256,8 @@ cmd_new_session_exec(struct cmd *self, struct cmd_ctx *ctx)
* If there are still configuration file errors to display, put the new
* session's current window into more mode and display them now.
*/
- if (cfg_finished && !ARRAY_EMPTY(&cfg_causes)) {
- wp = s->curw->window->active;
- window_pane_set_mode(wp, &window_copy_mode);
- window_copy_init_for_output(wp);
- for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
- cause = ARRAY_ITEM(&cfg_causes, i);
- window_copy_add(wp, "%s", cause);
- free(cause);
- }
- ARRAY_FREE(&cfg_causes);
- }
+ if (cfg_finished)
+ show_cfg_causes(s);
return (detached ? CMD_RETURN_NORMAL : CMD_RETURN_ATTACH);
}
diff --git a/server.c b/server.c
index 740f71d9..bad22270 100644
--- a/server.c
+++ b/server.c
@@ -106,11 +106,8 @@ server_create_socket(void)
int
server_start(int lockfd, char *lockfile)
{
- struct window_pane *wp;
- int pair[2];
- char *cause;
- struct timeval tv;
- u_int i;
+ int pair[2];
+ struct timeval tv;
/* The first client is special and gets a socketpair; create it. */
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pair) != 0)
@@ -178,17 +175,9 @@ server_start(int lockfd, char *lockfile)
* If there is a session already, put the current window and pane into
* more mode.
*/
- if (!RB_EMPTY(&sessions) && !ARRAY_EMPTY(&cfg_causes)) {
- wp = RB_MIN(sessions, &sessions)->curw->window->active;
- window_pane_set_mode(wp, &window_copy_mode);
- window_copy_init_for_output(wp);
- for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
- cause = ARRAY_ITEM(&cfg_causes, i);
- window_copy_add(wp, "%s", cause);
- free(cause);
- }
- ARRAY_FREE(&cfg_causes);
- }
+ if (!RB_EMPTY(&sessions) && !ARRAY_EMPTY(&cfg_causes))
+ show_cfg_causes(RB_MIN(sessions, &sessions));
+
cfg_finished = 1;
server_add_accept(0);
diff --git a/tmux.h b/tmux.h
index 4a5326cf..2a36c2da 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1520,6 +1520,7 @@ extern int cfg_finished;
extern struct causelist cfg_causes;
void printflike2 cfg_add_cause(struct causelist *, const char *, ...);
int load_cfg(const char *, struct cmd_ctx *, struct causelist *);
+void show_cfg_causes(struct session *);
/* format.c */
int format_cmp(struct format_entry *, struct format_entry *);