mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Retry connection with small timeout instead of sleep(10) for server start.
This commit is contained in:
		
							
								
								
									
										1
									
								
								TODO
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								TODO
									
									
									
									
									
								
							@@ -12,7 +12,6 @@
 | 
				
			|||||||
- mouse handling and some other bits elinks needs
 | 
					- mouse handling and some other bits elinks needs
 | 
				
			||||||
- scrollback
 | 
					- scrollback
 | 
				
			||||||
- server doesn't handle SIGTERM anymore...
 | 
					- server doesn't handle SIGTERM anymore...
 | 
				
			||||||
- sleep(1) to wait for server frankly sucks
 | 
					 | 
				
			||||||
- toolbar, copy/paste
 | 
					- toolbar, copy/paste
 | 
				
			||||||
- cleanup/redesign IPC
 | 
					- cleanup/redesign IPC
 | 
				
			||||||
- the whole input/screen/local thing sucks a bit, reorganise/redesign it
 | 
					- the whole input/screen/local thing sucks a bit, reorganise/redesign it
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										40
									
								
								client.c
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								client.c
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
				
			|||||||
/* $Id: client.c,v 1.6 2007-09-27 09:52:03 nicm Exp $ */
 | 
					/* $Id: client.c,v 1.7 2007-09-27 20:53:13 nicm Exp $ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
					 * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
 | 
				
			||||||
@@ -49,23 +49,6 @@ client_init(char *path, struct client_ctx *cctx, int start_server)
 | 
				
			|||||||
		    "%s/%s-%lu", _PATH_TMP, __progname, (u_long) getuid());
 | 
							    "%s/%s-%lu", _PATH_TMP, __progname, (u_long) getuid());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	retries = 0;
 | 
					 | 
				
			||||||
retry:
 | 
					 | 
				
			||||||
	if (stat(path, &sb) != 0) {
 | 
					 | 
				
			||||||
		if (!start_server || errno != ENOENT) {
 | 
					 | 
				
			||||||
			log_warn("%s", path);
 | 
					 | 
				
			||||||
			return (-1);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if (server_start(path) != 0)
 | 
					 | 
				
			||||||
			return (-1);
 | 
					 | 
				
			||||||
		sleep(1); /* XXX */
 | 
					 | 
				
			||||||
		goto retry;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	if (!S_ISSOCK(sb.st_mode)) {
 | 
					 | 
				
			||||||
		log_warnx("%s: %s", path, strerror(ENOTSOCK));
 | 
					 | 
				
			||||||
		return (-1);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (start_server) {
 | 
						if (start_server) {
 | 
				
			||||||
		if (!isatty(STDIN_FILENO)) {
 | 
							if (!isatty(STDIN_FILENO)) {
 | 
				
			||||||
			log_warnx("stdin is not a tty");
 | 
								log_warnx("stdin is not a tty");
 | 
				
			||||||
@@ -82,6 +65,24 @@ retry:
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						retries = 0;
 | 
				
			||||||
 | 
					retry:
 | 
				
			||||||
 | 
						if (stat(path, &sb) != 0) {
 | 
				
			||||||
 | 
							if (start_server && errno == ENOENT && retries < 10) {
 | 
				
			||||||
 | 
								if (server_start(path) != 0)
 | 
				
			||||||
 | 
									return (-1);
 | 
				
			||||||
 | 
								usleep(10000);
 | 
				
			||||||
 | 
								retries++;
 | 
				
			||||||
 | 
								goto retry;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							log_warn("%s: stat", path);
 | 
				
			||||||
 | 
							return (-1);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if (!S_ISSOCK(sb.st_mode)) {
 | 
				
			||||||
 | 
							log_warnx("%s: %s", path, strerror(ENOTSOCK));
 | 
				
			||||||
 | 
							return (-1);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memset(&sa, 0, sizeof sa);
 | 
						memset(&sa, 0, sizeof sa);
 | 
				
			||||||
	sa.sun_family = AF_UNIX;
 | 
						sa.sun_family = AF_UNIX;
 | 
				
			||||||
	sz = strlcpy(sa.sun_path, path, sizeof sa.sun_path);
 | 
						sz = strlcpy(sa.sun_path, path, sizeof sa.sun_path);
 | 
				
			||||||
@@ -96,11 +97,12 @@ retry:
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	if (connect(
 | 
						if (connect(
 | 
				
			||||||
	    cctx->srv_fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) == -1) {
 | 
						    cctx->srv_fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) == -1) {
 | 
				
			||||||
		if (start_server && errno == ECONNREFUSED && retries < 5) {
 | 
							if (start_server && errno == ECONNREFUSED && retries < 10) {
 | 
				
			||||||
			if (unlink(path) != 0) {
 | 
								if (unlink(path) != 0) {
 | 
				
			||||||
				log_warn("%s: unlink", path);
 | 
									log_warn("%s: unlink", path);
 | 
				
			||||||
				return (-1);
 | 
									return (-1);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
								usleep(10000);
 | 
				
			||||||
			retries++;
 | 
								retries++;
 | 
				
			||||||
			goto retry;
 | 
								goto retry;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user