This breaks the case where I source a bad file from the command prompt,
for example:

echo 'set -g abc' >~/.tmux.conf
tmux new
q
C-b : source ~/.tmux.conf

I guess you just don't reset the state after displaying it.

I've applied your other diff to add show_cfg_causes.

Cheers


On Thu, Nov 15, 2012 at 11:41:47PM +0000, Thomas Adam wrote:
> At the moment it's possible to trample configuration file error reporting by
> having an error in fileB which is sourced from fileA at startup.  If there
> were any errors in fileA these would be lost because fileB somewhat treads
> on the state of fileA.
> 
> Because source-file uses the same configuration loading code as the server,
> the callers are assumed to have pre-allocated an array of errors to be
> filled out as commands are processed.  But each call to source-file will
> allocate a new array.  When we end up reporting on this to the user, by
> entering copy-mode, this doesn't happen for every allocated buffer, just one
> of them.  So not every error ends up being presented to the user.
> 
> Instead, make the current cfg_causes array global, have it initialised by
> tmux before it parses its main config file, and have source-file also
> reference cfg_causes.  This aggregates all the errors across files correctly
> and displays them in copy-mode.
> 
> Simplify cmd-source-file.c:cmd_source_file_exec() somewhat too; see comments
> therein.
> 
> Bug originally reported by Sam Livingstone-Gray.
> ---
>  cfg.c             |  1 -
>  cmd-source-file.c | 38 ++++++++++++++++----------------------
>  tmux.c            |  3 +++
>  3 files changed, 19 insertions(+), 23 deletions(-)
> 
> diff --git a/cfg.c b/cfg.c
> index 577f2d1..007dba5 100644
> --- a/cfg.c
> +++ b/cfg.c
> @@ -36,7 +36,6 @@ void printflike2 cfg_error(struct cmd_ctx *, const char *, 
> ...);
>  
>  char                *cfg_cause;
>  int                  cfg_finished;
> -struct causelist     cfg_causes = ARRAY_INITIALIZER;
>  
>  /* ARGSUSED */
>  void printflike2
> diff --git a/cmd-source-file.c b/cmd-source-file.c
> index 12ed3de..775a0cc 100644
> --- a/cmd-source-file.c
> +++ b/cmd-source-file.c
> @@ -42,35 +42,29 @@ enum cmd_retval
>  cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx)
>  {
>       struct args             *args = self->args;
> -     struct causelist         causes;
> -     char                    *cause;
> -     struct window_pane      *wp;
>       int                      retval;
>       u_int                    i;
> +     char                    *cause;
>  
> -     ARRAY_INIT(&causes);
> +     retval = load_cfg(args->argv[0], ctx, &cfg_causes);
>  
> -     retval = load_cfg(args->argv[0], ctx, &causes);
> -     if (ARRAY_EMPTY(&causes))
> +     /* If the context for the cmdclient came from tmux's configuration
> +      * file, then return the status of this command now, regardless of the
> +      * error condition.  Any errors from parsing a configuration file at
> +      * startup will be handled for us by the server.
> +      */
> +     if (ctx->cmdclient == NULL)
>               return (retval);
>  
> -     if (retval == 1 && !RB_EMPTY(&sessions) && ctx->cmdclient != NULL) {
> -             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(&causes); i++) {
> -                     cause = ARRAY_ITEM(&causes, i);
> -                     window_copy_add(wp, "%s", cause);
> -                     free(cause);
> -             }
> -     } else {
> -             for (i = 0; i < ARRAY_LENGTH(&causes); i++) {
> -                     cause = ARRAY_ITEM(&causes, i);
> -                     ctx->print(ctx, "%s", cause);
> -                     free(cause);
> -             }
> +     /* We were called from the command-line in which case print the errors
> +      * gathered here directly.
> +      */
> +     for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
> +             cause = ARRAY_ITEM(&cfg_causes, i);
> +             ctx->print(ctx, "%s", cause);
> +             free(cause);
>       }
> -     ARRAY_FREE(&causes);
> +     ARRAY_FREE(&cfg_causes);
>  
>       return (retval);
>  }
> diff --git a/tmux.c b/tmux.c
> index 5a773f6..e649be2 100644
> --- a/tmux.c
> +++ b/tmux.c
> @@ -39,6 +39,7 @@ struct options       global_w_options;      /* window 
> options */
>  struct environ        global_environ;
>  
>  struct event_base *ev_base;
> +struct causelist  cfg_causes;
>  
>  char         *cfg_file;
>  char         *shell_cmd;
> @@ -333,6 +334,8 @@ main(int argc, char **argv)
>       options_init(&global_w_options, NULL);
>       options_table_populate_tree(window_options_table, &global_w_options);
>  
> +     ARRAY_INIT(&cfg_causes);
> +
>       /* Enable UTF-8 if the first client is on UTF-8 terminal. */
>       if (flags & IDENTIFY_UTF8) {
>               options_set_number(&global_s_options, "status-utf8", 1);
> -- 
> 1.7.11.4
> 
> 
> ------------------------------------------------------------------------------
> Monitor your physical, virtual and cloud infrastructure from a single
> web console. Get in-depth insight into apps, servers, databases, vmware,
> SAP, cloud infrastructure, etc. Download 30-day Free Trial.
> Pricing starts from $795 for 25 servers or applications!
> http://p.sf.net/sfu/zoho_dev2dev_nov
> _______________________________________________
> tmux-users mailing list
> tmux-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/tmux-users

------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to