mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 09:26:05 +00:00 
			
		
		
		
	Merge branch 'obsd-master'
Sync from OpenBSD.
This commit is contained in:
		
							
								
								
									
										32
									
								
								cfg.c
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								cfg.c
									
									
									
									
									
								
							@@ -73,46 +73,50 @@ cfg_add_cause(struct causelist *causes, const char *fmt, ...)
 | 
				
			|||||||
 * Load configuration file. Returns -1 for an error with a list of messages in
 | 
					 * Load configuration file. Returns -1 for an error with a list of messages in
 | 
				
			||||||
 * causes. Note that causes must be initialised by the caller!
 | 
					 * causes. Note that causes must be initialised by the caller!
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
int
 | 
					enum cmd_retval
 | 
				
			||||||
load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
 | 
					load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	FILE		*f;
 | 
						FILE		*f;
 | 
				
			||||||
	u_int		 n;
 | 
						u_int		 n;
 | 
				
			||||||
	char		*buf, *line, *cause;
 | 
						char		*buf, *line, *cause;
 | 
				
			||||||
	size_t		 len;
 | 
						size_t		 len, newlen;
 | 
				
			||||||
	struct cmd_list	*cmdlist;
 | 
						struct cmd_list	*cmdlist;
 | 
				
			||||||
	struct cmd_ctx	 ctx;
 | 
						struct cmd_ctx	 ctx;
 | 
				
			||||||
	enum cmd_retval	 retval;
 | 
						enum cmd_retval	 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));
 | 
				
			||||||
		return (-1);
 | 
							return (CMD_RETURN_ERROR);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	n = 0;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cfg_references++;
 | 
						cfg_references++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						n = 0;
 | 
				
			||||||
	line = NULL;
 | 
						line = NULL;
 | 
				
			||||||
	retval = CMD_RETURN_NORMAL;
 | 
						retval = CMD_RETURN_NORMAL;
 | 
				
			||||||
	while ((buf = fgetln(f, &len))) {
 | 
						while ((buf = fgetln(f, &len))) {
 | 
				
			||||||
		if (buf[len - 1] == '\n')
 | 
							if (buf[len - 1] == '\n')
 | 
				
			||||||
			len--;
 | 
								len--;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (line != NULL)
 | 
							/* Current line is the continuation of the previous one. */
 | 
				
			||||||
			line = xrealloc(line, 1, strlen(line) + len + 1);
 | 
							if (line != NULL) {
 | 
				
			||||||
		else {
 | 
								newlen = strlen(line) + len + 1;
 | 
				
			||||||
			line = xmalloc(len + 1);
 | 
								line = xrealloc(line, 1, newlen);
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								newlen = len + 1;
 | 
				
			||||||
 | 
								line = xmalloc(newlen);
 | 
				
			||||||
			*line = '\0';
 | 
								*line = '\0';
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* Append buffer to line. strncat will terminate. */
 | 
							/* Append current line to the previous. */
 | 
				
			||||||
		strncat(line, buf, len);
 | 
							strlcat(line, buf, newlen);
 | 
				
			||||||
		n++;
 | 
							n++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/* Continuation: get next line? */
 | 
							/* Continuation: get next line? */
 | 
				
			||||||
		len = strlen(line);
 | 
							len = strlen(line);
 | 
				
			||||||
		if (len > 0 && line[len - 1] == '\\') {
 | 
							if (len > 0 && line[len - 1] == '\\') {
 | 
				
			||||||
			line[len - 1] = '\0';
 | 
								line[len - 1] = '\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			/* Ignore escaped backslash at EOL. */
 | 
								/* Ignore escaped backslash at EOL. */
 | 
				
			||||||
			if (len > 1 && line[len - 2] != '\\')
 | 
								if (len > 1 && line[len - 2] != '\\')
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
@@ -127,11 +131,10 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
 | 
				
			|||||||
			cfg_add_cause(causes, "%s: %u: %s", path, n, cause);
 | 
								cfg_add_cause(causes, "%s: %u: %s", path, n, cause);
 | 
				
			||||||
			free(cause);
 | 
								free(cause);
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
		} else
 | 
							}
 | 
				
			||||||
			free(buf);
 | 
							free(buf);
 | 
				
			||||||
		if (cmdlist == NULL)
 | 
							if (cmdlist == NULL)
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
		cfg_cause = NULL;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (ctxin == NULL) {
 | 
							if (ctxin == NULL) {
 | 
				
			||||||
			ctx.msgdata = NULL;
 | 
								ctx.msgdata = NULL;
 | 
				
			||||||
@@ -162,8 +165,7 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes)
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		cmd_list_free(cmdlist);
 | 
							cmd_list_free(cmdlist);
 | 
				
			||||||
		if (cfg_cause != NULL) {
 | 
							if (cfg_cause != NULL) {
 | 
				
			||||||
			cfg_add_cause(
 | 
								cfg_add_cause(causes, "%s: %d: %s", path, n, cfg_cause);
 | 
				
			||||||
			    causes, "%s: %d: %s", path, n, cfg_cause);
 | 
					 | 
				
			||||||
			free(cfg_cause);
 | 
								free(cfg_cause);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										53
									
								
								cmd-string.c
									
									
									
									
									
								
							
							
						
						
									
										53
									
								
								cmd-string.c
									
									
									
									
									
								
							@@ -31,11 +31,12 @@
 | 
				
			|||||||
 * Parse a command from a string.
 | 
					 * Parse a command from a string.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int	cmd_string_getc(const char *, size_t *);
 | 
					int	 cmd_string_getc(const char *, size_t *);
 | 
				
			||||||
void	cmd_string_ungetc(size_t *);
 | 
					void	 cmd_string_ungetc(size_t *);
 | 
				
			||||||
char   *cmd_string_string(const char *, size_t *, char, int);
 | 
					void	 cmd_string_copy(char **, char *, size_t *);
 | 
				
			||||||
char   *cmd_string_variable(const char *, size_t *);
 | 
					char	*cmd_string_string(const char *, size_t *, char, int);
 | 
				
			||||||
char   *cmd_string_expand_tilde(const char *, size_t *);
 | 
					char	*cmd_string_variable(const char *, size_t *);
 | 
				
			||||||
 | 
					char	*cmd_string_expand_tilde(const char *, size_t *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int
 | 
					int
 | 
				
			||||||
cmd_string_getc(const char *s, size_t *p)
 | 
					cmd_string_getc(const char *s, size_t *p)
 | 
				
			||||||
@@ -84,26 +85,17 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
 | 
				
			|||||||
		case '\'':
 | 
							case '\'':
 | 
				
			||||||
			if ((t = cmd_string_string(s, &p, '\'', 0)) == NULL)
 | 
								if ((t = cmd_string_string(s, &p, '\'', 0)) == NULL)
 | 
				
			||||||
				goto error;
 | 
									goto error;
 | 
				
			||||||
			buf = xrealloc(buf, 1, len + strlen(t) + 1);
 | 
								cmd_string_copy(&buf, t, &len);
 | 
				
			||||||
			strlcpy(buf + len, t, strlen(t) + 1);
 | 
					 | 
				
			||||||
			len += strlen(t);
 | 
					 | 
				
			||||||
			free(t);
 | 
					 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case '"':
 | 
							case '"':
 | 
				
			||||||
			if ((t = cmd_string_string(s, &p, '"', 1)) == NULL)
 | 
								if ((t = cmd_string_string(s, &p, '"', 1)) == NULL)
 | 
				
			||||||
				goto error;
 | 
									goto error;
 | 
				
			||||||
			buf = xrealloc(buf, 1, len + strlen(t) + 1);
 | 
								cmd_string_copy(&buf, t, &len);
 | 
				
			||||||
			strlcpy(buf + len, t, strlen(t) + 1);
 | 
					 | 
				
			||||||
			len += strlen(t);
 | 
					 | 
				
			||||||
			free(t);
 | 
					 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case '$':
 | 
							case '$':
 | 
				
			||||||
			if ((t = cmd_string_variable(s, &p)) == NULL)
 | 
								if ((t = cmd_string_variable(s, &p)) == NULL)
 | 
				
			||||||
				goto error;
 | 
									goto error;
 | 
				
			||||||
			buf = xrealloc(buf, 1, len + strlen(t) + 1);
 | 
								cmd_string_copy(&buf, t, &len);
 | 
				
			||||||
			strlcpy(buf + len, t, strlen(t) + 1);
 | 
					 | 
				
			||||||
			len += strlen(t);
 | 
					 | 
				
			||||||
			free(t);
 | 
					 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
		case '#':
 | 
							case '#':
 | 
				
			||||||
			/* Comment: discard rest of line. */
 | 
								/* Comment: discard rest of line. */
 | 
				
			||||||
@@ -147,12 +139,10 @@ cmd_string_parse(const char *s, struct cmd_list **cmdlist, char **cause)
 | 
				
			|||||||
			goto out;
 | 
								goto out;
 | 
				
			||||||
		case '~':
 | 
							case '~':
 | 
				
			||||||
			if (buf == NULL) {
 | 
								if (buf == NULL) {
 | 
				
			||||||
				if ((t = cmd_string_expand_tilde(s, &p)) == NULL)
 | 
									t = cmd_string_expand_tilde(s, &p);
 | 
				
			||||||
 | 
									if (t == NULL)
 | 
				
			||||||
					goto error;
 | 
										goto error;
 | 
				
			||||||
				buf = xrealloc(buf, 1, len + strlen(t) + 1);
 | 
									cmd_string_copy(&buf, t, &len);
 | 
				
			||||||
				strlcpy(buf + len, t, strlen(t) + 1);
 | 
					 | 
				
			||||||
				len += strlen(t);
 | 
					 | 
				
			||||||
				free(t);
 | 
					 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			/* FALLTHROUGH */
 | 
								/* FALLTHROUGH */
 | 
				
			||||||
@@ -181,6 +171,20 @@ out:
 | 
				
			|||||||
	return (rval);
 | 
						return (rval);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void
 | 
				
			||||||
 | 
					cmd_string_copy(char **dst, char *src, size_t *len)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						size_t srclen;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						srclen = strlen(src);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						*dst = xrealloc(*dst, 1, *len + srclen + 1);
 | 
				
			||||||
 | 
						strlcpy(*dst + *len, src, srclen + 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						*len += srclen;
 | 
				
			||||||
 | 
						free(src);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
char *
 | 
					char *
 | 
				
			||||||
cmd_string_string(const char *s, size_t *p, char endch, int esc)
 | 
					cmd_string_string(const char *s, size_t *p, char endch, int esc)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -220,10 +224,7 @@ cmd_string_string(const char *s, size_t *p, char endch, int esc)
 | 
				
			|||||||
				break;
 | 
									break;
 | 
				
			||||||
			if ((t = cmd_string_variable(s, p)) == NULL)
 | 
								if ((t = cmd_string_variable(s, p)) == NULL)
 | 
				
			||||||
				goto error;
 | 
									goto error;
 | 
				
			||||||
			buf = xrealloc(buf, 1, len + strlen(t) + 1);
 | 
								cmd_string_copy(&buf, t, &len);
 | 
				
			||||||
			strlcpy(buf + len, t, strlen(t) + 1);
 | 
					 | 
				
			||||||
			len += strlen(t);
 | 
					 | 
				
			||||||
			free(t);
 | 
					 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -324,6 +324,9 @@ screen_write_parsestyle(
 | 
				
			|||||||
			fg = defgc->fg;
 | 
								fg = defgc->fg;
 | 
				
			||||||
			bg = defgc->bg;
 | 
								bg = defgc->bg;
 | 
				
			||||||
			attr = defgc->attr;
 | 
								attr = defgc->attr;
 | 
				
			||||||
 | 
								flags &= ~(GRID_FLAG_FG256|GRID_FLAG_BG256);
 | 
				
			||||||
 | 
								flags |=
 | 
				
			||||||
 | 
								    defgc->flags & (GRID_FLAG_FG256|GRID_FLAG_BG256);
 | 
				
			||||||
		} else if (end > 3 && strncasecmp(tmp + 1, "g=", 2) == 0) {
 | 
							} else if (end > 3 && strncasecmp(tmp + 1, "g=", 2) == 0) {
 | 
				
			||||||
			if ((val = colour_fromstring(tmp + 3)) == -1)
 | 
								if ((val = colour_fromstring(tmp + 3)) == -1)
 | 
				
			||||||
				return;
 | 
									return;
 | 
				
			||||||
@@ -335,8 +338,11 @@ screen_write_parsestyle(
 | 
				
			|||||||
					} else
 | 
										} else
 | 
				
			||||||
						flags &= ~GRID_FLAG_FG256;
 | 
											flags &= ~GRID_FLAG_FG256;
 | 
				
			||||||
					fg = val;
 | 
										fg = val;
 | 
				
			||||||
				} else
 | 
									} else {
 | 
				
			||||||
					fg = defgc->fg;
 | 
										fg = defgc->fg;
 | 
				
			||||||
 | 
										flags &= ~GRID_FLAG_FG256;
 | 
				
			||||||
 | 
										flags |= defgc->flags & GRID_FLAG_FG256;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
			} else if (*in == 'b' || *in == 'B') {
 | 
								} else if (*in == 'b' || *in == 'B') {
 | 
				
			||||||
				if (val != 8) {
 | 
									if (val != 8) {
 | 
				
			||||||
					if (val & 0x100) {
 | 
										if (val & 0x100) {
 | 
				
			||||||
@@ -345,8 +351,11 @@ screen_write_parsestyle(
 | 
				
			|||||||
					} else
 | 
										} else
 | 
				
			||||||
						flags &= ~GRID_FLAG_BG256;
 | 
											flags &= ~GRID_FLAG_BG256;
 | 
				
			||||||
					bg = val;
 | 
										bg = val;
 | 
				
			||||||
				} else
 | 
									} else {
 | 
				
			||||||
					bg = defgc->bg;
 | 
										bg = defgc->bg;
 | 
				
			||||||
 | 
										flags &= ~GRID_FLAG_BG256;
 | 
				
			||||||
 | 
										flags |= defgc->flags & GRID_FLAG_BG256;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
			} else
 | 
								} else
 | 
				
			||||||
				return;
 | 
									return;
 | 
				
			||||||
		} else if (end > 2 && strncasecmp(tmp, "no", 2) == 0) {
 | 
							} else if (end > 2 && strncasecmp(tmp, "no", 2) == 0) {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								server.c
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								server.c
									
									
									
									
									
								
							@@ -167,7 +167,7 @@ server_start(int lockfd, char *lockfile)
 | 
				
			|||||||
		load_cfg(SYSTEM_CFG, NULL, &cfg_causes);
 | 
							load_cfg(SYSTEM_CFG, NULL, &cfg_causes);
 | 
				
			||||||
	else if (errno != ENOENT) {
 | 
						else if (errno != ENOENT) {
 | 
				
			||||||
		cfg_add_cause(
 | 
							cfg_add_cause(
 | 
				
			||||||
		    &cfg_causes, "%s: %s", strerror(errno), SYSTEM_CFG);
 | 
							    &cfg_causes, "%s: %s", SYSTEM_CFG, strerror(errno));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (cfg_file != NULL)
 | 
						if (cfg_file != NULL)
 | 
				
			||||||
		load_cfg(cfg_file, NULL, &cfg_causes);
 | 
							load_cfg(cfg_file, NULL, &cfg_causes);
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								tmux.h
									
									
									
									
									
								
							@@ -1516,7 +1516,7 @@ extern int       cfg_finished;
 | 
				
			|||||||
extern int       cfg_references;
 | 
					extern int       cfg_references;
 | 
				
			||||||
extern struct causelist cfg_causes;
 | 
					extern struct causelist cfg_causes;
 | 
				
			||||||
void printflike2 cfg_add_cause(struct causelist *, const char *, ...);
 | 
					void printflike2 cfg_add_cause(struct causelist *, const char *, ...);
 | 
				
			||||||
int		 load_cfg(const char *, struct cmd_ctx *, struct causelist *);
 | 
					enum cmd_retval	 load_cfg(const char *, struct cmd_ctx *, struct causelist *);
 | 
				
			||||||
void		 show_cfg_causes(struct session *);
 | 
					void		 show_cfg_causes(struct session *);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* format.c */
 | 
					/* format.c */
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user