mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Allow the config file parser and source-file to return "don't exit" to
the client to let attach work from configuration files.
This commit is contained in:
		
							
								
								
									
										10
									
								
								cfg.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								cfg.c
									
									
									
									
									
								
							@@ -80,6 +80,7 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
 | 
				
			|||||||
	size_t		 len;
 | 
						size_t		 len;
 | 
				
			||||||
	struct cmd_list	*cmdlist;
 | 
						struct cmd_list	*cmdlist;
 | 
				
			||||||
	struct cmd_ctx	 ctx;
 | 
						struct cmd_ctx	 ctx;
 | 
				
			||||||
 | 
						int		 retval;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ((f = fopen(path, "rb")) == NULL) {
 | 
						if ((f = fopen(path, "rb")) == NULL) {
 | 
				
			||||||
		cfg_add_cause(causes, "%s: %s", path, strerror(errno));
 | 
							cfg_add_cause(causes, "%s: %s", path, strerror(errno));
 | 
				
			||||||
@@ -88,6 +89,7 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
 | 
				
			|||||||
	n = 0;
 | 
						n = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	line = NULL;
 | 
						line = NULL;
 | 
				
			||||||
 | 
						retval = 0;
 | 
				
			||||||
	while ((buf = fgetln(f, &len))) {
 | 
						while ((buf = fgetln(f, &len))) {
 | 
				
			||||||
		if (buf[len - 1] == '\n')
 | 
							if (buf[len - 1] == '\n')
 | 
				
			||||||
			buf[len - 1] = '\0';
 | 
								buf[len - 1] = '\0';
 | 
				
			||||||
@@ -125,19 +127,17 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
 | 
				
			|||||||
		ctx.info = cfg_print;
 | 
							ctx.info = cfg_print;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		cfg_cause = NULL;
 | 
							cfg_cause = NULL;
 | 
				
			||||||
		cmd_list_exec(cmdlist, &ctx);
 | 
							if (cmd_list_exec(cmdlist, &ctx) == 1)
 | 
				
			||||||
 | 
								retval = 1;
 | 
				
			||||||
		cmd_list_free(cmdlist);
 | 
							cmd_list_free(cmdlist);
 | 
				
			||||||
		if (cfg_cause != NULL) {
 | 
							if (cfg_cause != NULL) {
 | 
				
			||||||
			cfg_add_cause(causes, "%s: %d: %s", path, n, cfg_cause);
 | 
								cfg_add_cause(causes, "%s: %d: %s", path, n, cfg_cause);
 | 
				
			||||||
			xfree(cfg_cause);
 | 
								xfree(cfg_cause);
 | 
				
			||||||
			continue;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (line != NULL)
 | 
						if (line != NULL)
 | 
				
			||||||
		xfree(line);
 | 
							xfree(line);
 | 
				
			||||||
	fclose(f);
 | 
						fclose(f);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (ARRAY_LENGTH(causes) != 0)
 | 
						return (retval);
 | 
				
			||||||
		return (-1);
 | 
					 | 
				
			||||||
	return (0);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -91,19 +91,35 @@ cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx)
 | 
				
			|||||||
	struct cmd_source_file_data	*data = self->data;
 | 
						struct cmd_source_file_data	*data = self->data;
 | 
				
			||||||
	struct causelist		 causes;
 | 
						struct causelist		 causes;
 | 
				
			||||||
	char				*cause;
 | 
						char				*cause;
 | 
				
			||||||
 | 
						struct window_pane		*wp;
 | 
				
			||||||
 | 
						int				 retval;
 | 
				
			||||||
	u_int				 i;
 | 
						u_int				 i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ARRAY_INIT(&causes);
 | 
						ARRAY_INIT(&causes);
 | 
				
			||||||
	if (load_cfg(data->path, ctx, &causes) != 0) {
 | 
					
 | 
				
			||||||
 | 
						retval = load_cfg(data->path, ctx, &causes);
 | 
				
			||||||
 | 
						if (ARRAY_EMPTY(&causes))
 | 
				
			||||||
 | 
							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);
 | 
				
			||||||
 | 
								xfree(cause);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
		for (i = 0; i < ARRAY_LENGTH(&causes); i++) {
 | 
							for (i = 0; i < ARRAY_LENGTH(&causes); i++) {
 | 
				
			||||||
			cause = ARRAY_ITEM(&causes, i);
 | 
								cause = ARRAY_ITEM(&causes, i);
 | 
				
			||||||
			ctx->print(ctx, "%s", cause);
 | 
								ctx->print(ctx, "%s", cause);
 | 
				
			||||||
			xfree(cause);
 | 
								xfree(cause);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		ARRAY_FREE(&causes);
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						ARRAY_FREE(&causes);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return (0);
 | 
						return (retval);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user