mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Move initial conf load into cfg.c.
This commit is contained in:
		
							
								
								
									
										31
									
								
								cfg.c
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								cfg.c
									
									
									
									
									
								
							@@ -23,6 +23,7 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#include <util.h>
 | 
			
		||||
 | 
			
		||||
#include "tmux.h"
 | 
			
		||||
@@ -34,6 +35,36 @@ char			**cfg_causes;
 | 
			
		||||
u_int		  cfg_ncauses;
 | 
			
		||||
struct client	 *cfg_client;
 | 
			
		||||
 | 
			
		||||
void	cfg_default_done(struct cmd_q *);
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
start_cfg(void)
 | 
			
		||||
{
 | 
			
		||||
	char	*cause = NULL;
 | 
			
		||||
 | 
			
		||||
	cfg_cmd_q = cmdq_new(NULL);
 | 
			
		||||
	cfg_cmd_q->emptyfn = cfg_default_done;
 | 
			
		||||
 | 
			
		||||
	cfg_finished = 0;
 | 
			
		||||
	cfg_references = 1;
 | 
			
		||||
 | 
			
		||||
	cfg_client = TAILQ_FIRST(&clients);
 | 
			
		||||
	if (cfg_client != NULL)
 | 
			
		||||
		cfg_client->references++;
 | 
			
		||||
 | 
			
		||||
	if (access(TMUX_CONF, R_OK) == 0) {
 | 
			
		||||
		if (load_cfg(TMUX_CONF, cfg_cmd_q, &cause) == -1)
 | 
			
		||||
			cfg_add_cause("%s: %s", TMUX_CONF, cause);
 | 
			
		||||
	} else if (errno != ENOENT)
 | 
			
		||||
		cfg_add_cause("%s: %s", TMUX_CONF, strerror(errno));
 | 
			
		||||
 | 
			
		||||
	if (cfg_file != NULL && load_cfg(cfg_file, cfg_cmd_q, &cause) == -1)
 | 
			
		||||
		cfg_add_cause("%s: %s", cfg_file, cause);
 | 
			
		||||
	free(cause);
 | 
			
		||||
 | 
			
		||||
	cmdq_continue(cfg_cmd_q);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
load_cfg(const char *path, struct cmd_q *cmdq, char **cause)
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										19
									
								
								server.c
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								server.c
									
									
									
									
									
								
							@@ -161,7 +161,6 @@ int
 | 
			
		||||
server_start(struct event_base *base, int lockfd, char *lockfile)
 | 
			
		||||
{
 | 
			
		||||
	int	pair[2];
 | 
			
		||||
	char	*cause;
 | 
			
		||||
 | 
			
		||||
	/* The first client is special and gets a socketpair; create it. */
 | 
			
		||||
	if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, pair) != 0)
 | 
			
		||||
@@ -217,24 +216,8 @@ server_start(struct event_base *base, int lockfd, char *lockfile)
 | 
			
		||||
	free(lockfile);
 | 
			
		||||
	close(lockfd);
 | 
			
		||||
 | 
			
		||||
	cfg_cmd_q = cmdq_new(NULL);
 | 
			
		||||
	cfg_cmd_q->emptyfn = cfg_default_done;
 | 
			
		||||
	cfg_finished = 0;
 | 
			
		||||
	cfg_references = 1;
 | 
			
		||||
	cfg_client = TAILQ_FIRST(&clients);
 | 
			
		||||
	if (cfg_client != NULL)
 | 
			
		||||
		cfg_client->references++;
 | 
			
		||||
	start_cfg();
 | 
			
		||||
 | 
			
		||||
	if (access(TMUX_CONF, R_OK) == 0) {
 | 
			
		||||
		if (load_cfg(TMUX_CONF, cfg_cmd_q, &cause) == -1)
 | 
			
		||||
			cfg_add_cause("%s: %s", TMUX_CONF, cause);
 | 
			
		||||
	} else if (errno != ENOENT)
 | 
			
		||||
		cfg_add_cause("%s: %s", TMUX_CONF, strerror(errno));
 | 
			
		||||
	if (cfg_file != NULL) {
 | 
			
		||||
		if (load_cfg(cfg_file, cfg_cmd_q, &cause) == -1)
 | 
			
		||||
			cfg_add_cause("%s: %s", cfg_file, cause);
 | 
			
		||||
	}
 | 
			
		||||
	cmdq_continue(cfg_cmd_q);
 | 
			
		||||
	status_prompt_load_history();
 | 
			
		||||
 | 
			
		||||
	server_add_accept(0);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										3
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								tmux.h
									
									
									
									
									
								
							@@ -1420,12 +1420,11 @@ void		 setblocking(int, int);
 | 
			
		||||
const char	*find_home(void);
 | 
			
		||||
 | 
			
		||||
/* cfg.c */
 | 
			
		||||
extern struct cmd_q *cfg_cmd_q;
 | 
			
		||||
extern int cfg_finished;
 | 
			
		||||
extern int cfg_references;
 | 
			
		||||
extern struct client *cfg_client;
 | 
			
		||||
void		 start_cfg(void);
 | 
			
		||||
int		 load_cfg(const char *, struct cmd_q *, char **);
 | 
			
		||||
void		 cfg_default_done(struct cmd_q *);
 | 
			
		||||
void		 cfg_add_cause(const char *, ...);
 | 
			
		||||
void		 cfg_print_causes(struct cmd_q *);
 | 
			
		||||
void		 cfg_show_causes(struct session *);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user