From c7394ac4e0f7e6e034fbb4b050de6f713bb9f6e0 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Sun, 23 Aug 2009 17:29:51 +0000 Subject: [PATCH] When using source-file, run the commands in the context of the source-file command rather than with no context. This makes things like attach work from a file. --- cfg.c | 15 ++++++++++----- cmd-source-file.c | 2 +- server.c | 4 ++-- tmux.h | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/cfg.c b/cfg.c index ec2d906d..d50eaae7 100644 --- a/cfg.c +++ b/cfg.c @@ -51,7 +51,7 @@ cfg_error(unused struct cmd_ctx *ctx, const char *fmt, ...) } int -load_cfg(const char *path, char **cause) +load_cfg(const char *path, struct cmd_ctx *ctxin, char **cause) { FILE *f; u_int n; @@ -87,15 +87,20 @@ load_cfg(const char *path, char **cause) continue; cfg_cause = NULL; - ctx.msgdata = NULL; - ctx.curclient = NULL; + if (ctxin == NULL) { + ctx.msgdata = NULL; + ctx.curclient = NULL; + ctx.cmdclient = NULL; + } else { + ctx.msgdata = ctxin->msgdata; + ctx.curclient = ctxin->curclient; + ctx.cmdclient = ctxin->cmdclient; + } ctx.error = cfg_error; ctx.print = cfg_print; ctx.info = cfg_print; - ctx.cmdclient = NULL; - cfg_cause = NULL; cmd_list_exec(cmdlist, &ctx); cmd_list_free(cmdlist); diff --git a/cmd-source-file.c b/cmd-source-file.c index b42c5785..247b06ec 100644 --- a/cmd-source-file.c +++ b/cmd-source-file.c @@ -90,7 +90,7 @@ cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx) struct cmd_source_file_data *data = self->data; char *cause; - if (load_cfg(data->path, &cause) != 0) { + if (load_cfg(data->path, ctx, &cause) != 0) { ctx->error(ctx, "%s", cause); xfree(cause); return (-1); diff --git a/server.c b/server.c index 707b4e49..3f15ca41 100644 --- a/server.c +++ b/server.c @@ -188,9 +188,9 @@ server_start(char *path) &cause, "%s: %s", strerror(errno), SYSTEM_CFG); goto error; } - } else if (load_cfg(SYSTEM_CFG, &cause) != 0) + } else if (load_cfg(SYSTEM_CFG, NULL, &cause) != 0) goto error; - if (cfg_file != NULL && load_cfg(cfg_file, &cause) != 0) + if (cfg_file != NULL && load_cfg(cfg_file, NULL, &cause) != 0) goto error; exit(server_main(srv_fd)); diff --git a/tmux.h b/tmux.h index 4cc659d6..a2d01ea0 100644 --- a/tmux.h +++ b/tmux.h @@ -1109,7 +1109,7 @@ void sigreset(void); void sighandler(int); /* cfg.c */ -int load_cfg(const char *, char **x); +int load_cfg(const char *, struct cmd_ctx *, char **); /* mode-key.c */ extern const struct mode_key_table mode_key_tables[];