mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 09:26:05 +00:00 
			
		
		
		
	Work out config file when needed not at startup.
This commit is contained in:
		
							
								
								
									
										18
									
								
								cfg.c
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								cfg.c
									
									
									
									
									
								
							@@ -28,6 +28,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "tmux.h"
 | 
					#include "tmux.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					char		 *cfg_file;
 | 
				
			||||||
struct cmd_q	 *cfg_cmd_q;
 | 
					struct cmd_q	 *cfg_cmd_q;
 | 
				
			||||||
int		  cfg_finished;
 | 
					int		  cfg_finished;
 | 
				
			||||||
int		  cfg_references;
 | 
					int		  cfg_references;
 | 
				
			||||||
@@ -37,10 +38,18 @@ struct client	 *cfg_client;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void	cfg_default_done(struct cmd_q *);
 | 
					void	cfg_default_done(struct cmd_q *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					set_cfg_file(const char *path)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						free(cfg_file);
 | 
				
			||||||
 | 
						cfg_file = xstrdup(path);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
start_cfg(void)
 | 
					start_cfg(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	char	*cause = NULL;
 | 
						char		*cause = NULL;
 | 
				
			||||||
 | 
						const char	*home;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cfg_cmd_q = cmdq_new(NULL);
 | 
						cfg_cmd_q = cmdq_new(NULL);
 | 
				
			||||||
	cfg_cmd_q->emptyfn = cfg_default_done;
 | 
						cfg_cmd_q->emptyfn = cfg_default_done;
 | 
				
			||||||
@@ -58,6 +67,13 @@ start_cfg(void)
 | 
				
			|||||||
	} else if (errno != ENOENT)
 | 
						} else if (errno != ENOENT)
 | 
				
			||||||
		cfg_add_cause("%s: %s", TMUX_CONF, strerror(errno));
 | 
							cfg_add_cause("%s: %s", TMUX_CONF, strerror(errno));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (cfg_file == NULL && (home = find_home()) != NULL) {
 | 
				
			||||||
 | 
							xasprintf(&cfg_file, "%s/.tmux.conf", home);
 | 
				
			||||||
 | 
							if (access(cfg_file, R_OK) != 0 && errno == ENOENT) {
 | 
				
			||||||
 | 
								free(cfg_file);
 | 
				
			||||||
 | 
								cfg_file = NULL;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if (cfg_file != NULL && load_cfg(cfg_file, cfg_cmd_q, &cause) == -1)
 | 
						if (cfg_file != NULL && load_cfg(cfg_file, cfg_cmd_q, &cause) == -1)
 | 
				
			||||||
		cfg_add_cause("%s: %s", cfg_file, cause);
 | 
							cfg_add_cause("%s: %s", cfg_file, cause);
 | 
				
			||||||
	free(cause);
 | 
						free(cause);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										28
									
								
								tmux.c
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								tmux.c
									
									
									
									
									
								
							@@ -41,7 +41,6 @@ struct options	 global_s_options;	/* session options */
 | 
				
			|||||||
struct options	 global_w_options;	/* window options */
 | 
					struct options	 global_w_options;	/* window options */
 | 
				
			||||||
struct environ	 global_environ;
 | 
					struct environ	 global_environ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char		*cfg_file;
 | 
					 | 
				
			||||||
char		*shell_cmd;
 | 
					char		*shell_cmd;
 | 
				
			||||||
int		 debug_level;
 | 
					int		 debug_level;
 | 
				
			||||||
time_t		 start_time;
 | 
					time_t		 start_time;
 | 
				
			||||||
@@ -171,8 +170,11 @@ setblocking(int fd, int state)
 | 
				
			|||||||
const char *
 | 
					const char *
 | 
				
			||||||
find_home(void)
 | 
					find_home(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct passwd	*pw;
 | 
						struct passwd		*pw;
 | 
				
			||||||
	const char	*home;
 | 
						static const char	*home;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (home != NULL)
 | 
				
			||||||
 | 
							return (home);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	home = getenv("HOME");
 | 
						home = getenv("HOME");
 | 
				
			||||||
	if (home == NULL || *home == '\0') {
 | 
						if (home == NULL || *home == '\0') {
 | 
				
			||||||
@@ -189,9 +191,8 @@ find_home(void)
 | 
				
			|||||||
int
 | 
					int
 | 
				
			||||||
main(int argc, char **argv)
 | 
					main(int argc, char **argv)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	char		*s, *path, *label, **var, tmp[PATH_MAX];
 | 
						char	*s, *path, *label, **var, tmp[PATH_MAX];
 | 
				
			||||||
	const char	*home;
 | 
						int	 opt, flags, keys;
 | 
				
			||||||
	int	 	 opt, flags, keys;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef DEBUG
 | 
					#ifdef DEBUG
 | 
				
			||||||
	malloc_options = (char *) "AFGJPX";
 | 
						malloc_options = (char *) "AFGJPX";
 | 
				
			||||||
@@ -221,8 +222,7 @@ main(int argc, char **argv)
 | 
				
			|||||||
				flags |= CLIENT_CONTROL;
 | 
									flags |= CLIENT_CONTROL;
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case 'f':
 | 
							case 'f':
 | 
				
			||||||
			free(cfg_file);
 | 
								set_cfg_file(optarg);
 | 
				
			||||||
			cfg_file = xstrdup(optarg);
 | 
					 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case 'l':
 | 
							case 'l':
 | 
				
			||||||
			flags |= CLIENT_LOGIN;
 | 
								flags |= CLIENT_LOGIN;
 | 
				
			||||||
@@ -306,18 +306,6 @@ main(int argc, char **argv)
 | 
				
			|||||||
		options_set_number(&global_w_options, "mode-keys", keys);
 | 
							options_set_number(&global_w_options, "mode-keys", keys);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Locate the configuration file. */
 | 
					 | 
				
			||||||
	if (cfg_file == NULL) {
 | 
					 | 
				
			||||||
		home = find_home();
 | 
					 | 
				
			||||||
		if (home != NULL) {
 | 
					 | 
				
			||||||
			xasprintf(&cfg_file, "%s/.tmux.conf", home);
 | 
					 | 
				
			||||||
			if (access(cfg_file, R_OK) != 0 && errno == ENOENT) {
 | 
					 | 
				
			||||||
				free(cfg_file);
 | 
					 | 
				
			||||||
				cfg_file = NULL;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Figure out the socket path. If specified on the command-line with -S
 | 
						 * Figure out the socket path. If specified on the command-line with -S
 | 
				
			||||||
	 * or -L, use it, otherwise try $TMUX or assume -L default.
 | 
						 * or -L, use it, otherwise try $TMUX or assume -L default.
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								tmux.h
									
									
									
									
									
								
							@@ -1407,7 +1407,6 @@ extern struct options global_options;
 | 
				
			|||||||
extern struct options global_s_options;
 | 
					extern struct options global_s_options;
 | 
				
			||||||
extern struct options global_w_options;
 | 
					extern struct options global_w_options;
 | 
				
			||||||
extern struct environ global_environ;
 | 
					extern struct environ global_environ;
 | 
				
			||||||
extern char	*cfg_file;
 | 
					 | 
				
			||||||
extern char	*shell_cmd;
 | 
					extern char	*shell_cmd;
 | 
				
			||||||
extern int	 debug_level;
 | 
					extern int	 debug_level;
 | 
				
			||||||
extern time_t	 start_time;
 | 
					extern time_t	 start_time;
 | 
				
			||||||
@@ -1425,6 +1424,7 @@ extern int cfg_references;
 | 
				
			|||||||
extern struct client *cfg_client;
 | 
					extern struct client *cfg_client;
 | 
				
			||||||
void		 start_cfg(void);
 | 
					void		 start_cfg(void);
 | 
				
			||||||
int		 load_cfg(const char *, struct cmd_q *, char **);
 | 
					int		 load_cfg(const char *, struct cmd_q *, char **);
 | 
				
			||||||
 | 
					void		 set_cfg_file(const char *);
 | 
				
			||||||
void		 cfg_add_cause(const char *, ...);
 | 
					void		 cfg_add_cause(const char *, ...);
 | 
				
			||||||
void		 cfg_print_causes(struct cmd_q *);
 | 
					void		 cfg_print_causes(struct cmd_q *);
 | 
				
			||||||
void		 cfg_show_causes(struct session *);
 | 
					void		 cfg_show_causes(struct session *);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user