summaryrefslogtreecommitdiffstats
path: root/usr.bin/tmux/cfg.c
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2010-02-06 17:15:33 +0000
committernicm <nicm@openbsd.org>2010-02-06 17:15:33 +0000
commit9a53e128e82783ea59ef6d1323ae061f893b30e7 (patch)
tree73d3f8459a72afb2915c00727c817b42d2bf3e7c /usr.bin/tmux/cfg.c
parentwhen receiving the first message of an rsn group key handshake (diff)
downloadwireguard-openbsd-9a53e128e82783ea59ef6d1323ae061f893b30e7.tar.xz
wireguard-openbsd-9a53e128e82783ea59ef6d1323ae061f893b30e7.zip
Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode displaying them.
Diffstat (limited to 'usr.bin/tmux/cfg.c')
-rw-r--r--usr.bin/tmux/cfg.c59
1 files changed, 39 insertions, 20 deletions
diff --git a/usr.bin/tmux/cfg.c b/usr.bin/tmux/cfg.c
index 934838b33c8..a89f8d9e9cd 100644
--- a/usr.bin/tmux/cfg.c
+++ b/usr.bin/tmux/cfg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cfg.c,v 1.8 2009/11/26 21:37:13 nicm Exp $ */
+/* $OpenBSD: cfg.c,v 1.9 2010/02/06 17:15:33 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -34,6 +34,9 @@ void printflike2 cfg_print(struct cmd_ctx *, const char *, ...);
void printflike2 cfg_error(struct cmd_ctx *, const char *, ...);
char *cfg_cause;
+int cfg_finished;
+char **cfg_causes;
+u_int cfg_ncauses;
/* ARGSUSED */
void printflike2
@@ -52,19 +55,38 @@ cfg_error(unused struct cmd_ctx *ctx, const char *fmt, ...)
va_end(ap);
}
+void printflike3
+cfg_add_cause(u_int *ncauses, char ***causes, const char *fmt, ...)
+{
+ char *cause;
+ va_list ap;
+
+ va_start(ap, fmt);
+ xvasprintf(&cause, fmt, ap);
+ va_end(ap);
+
+ *causes = xrealloc(*causes, *ncauses + 1, sizeof **causes);
+ (*causes)[(*ncauses)++] = cause;
+}
+
+/*
+ * Load configuration file. Returns -1 for an error with a list of messages in
+ * causes. Note that causes and ncauses must be initialised by the caller!
+ */
int
-load_cfg(const char *path, struct cmd_ctx *ctxin, char **cause)
+load_cfg(
+ const char *path, struct cmd_ctx *ctxin, u_int *ncauses, char ***causes)
{
FILE *f;
u_int n;
- char *buf, *line, *ptr;
+ char *buf, *line, *cause;
size_t len;
struct cmd_list *cmdlist;
struct cmd_ctx ctx;
if ((f = fopen(path, "rb")) == NULL) {
- xasprintf(cause, "%s: %s", path, strerror(errno));
- return (1);
+ cfg_add_cause(ncauses, causes, "%s: %s", path, strerror(errno));
+ return (-1);
}
n = 0;
@@ -80,10 +102,13 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, char **cause)
}
n++;
- if (cmd_string_parse(buf, &cmdlist, cause) != 0) {
- if (*cause == NULL)
+ if (cmd_string_parse(buf, &cmdlist, &cause) != 0) {
+ if (cause == NULL)
continue;
- goto error;
+ cfg_add_cause(
+ ncauses, causes, "%s: %u: %s", path, n, cause);
+ xfree(cause);
+ continue;
}
if (cmdlist == NULL)
continue;
@@ -107,23 +132,17 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, char **cause)
cmd_list_exec(cmdlist, &ctx);
cmd_list_free(cmdlist);
if (cfg_cause != NULL) {
- *cause = cfg_cause;
- goto error;
+ cfg_add_cause(
+ ncauses, causes, "%s: %d: %s", path, n, cfg_cause);
+ xfree(cfg_cause);
+ continue;
}
}
if (line != NULL)
xfree(line);
fclose(f);
+ if (*ncauses != 0)
+ return (-1);
return (0);
-
-error:
- if (line != NULL)
- xfree(line);
- fclose(f);
-
- xasprintf(&ptr, "%s: %s at line %u", path, *cause, n);
- xfree(*cause);
- *cause = ptr;
- return (1);
}