diff options
author | Nicholas Marriott <nicm@openbsd.org> | 2013-03-22 15:50:13 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@openbsd.org> | 2013-03-22 15:50:13 +0000 |
commit | 0ff9275ad75e7ef8933d290bb274d5420a625b4f (patch) | |
tree | 1b5bc56f793d0756e73e88f893fd1544885e435a | |
parent | d1e6ce26722e3a0774d240e39bbc69b07e93c48b (diff) | |
download | rtmux-0ff9275ad75e7ef8933d290bb274d5420a625b4f.tar.gz rtmux-0ff9275ad75e7ef8933d290bb274d5420a625b4f.tar.bz2 rtmux-0ff9275ad75e7ef8933d290bb274d5420a625b4f.zip |
load_cfg can actually use the same context now they are reference counted.
-rw-r--r-- | cfg.c | 30 |
1 files changed, 13 insertions, 17 deletions
@@ -73,14 +73,13 @@ cfg_add_cause(struct causelist *causes, const char *fmt, ...) * causes. Note that causes must be initialised by the caller! */ enum cmd_retval -load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes) +load_cfg(const char *path, struct cmd_ctx *ctx, struct causelist *causes) { FILE *f; u_int n; char *buf, *copy, *line, *cause; size_t len, oldlen; struct cmd_list *cmdlist; - struct cmd_ctx ctx; enum cmd_retval retval; if ((f = fopen(path, "rb")) == NULL) { @@ -90,6 +89,15 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes) cfg_references++; + if (ctx != NULL) + cmd_ref_ctx(ctx); + else { + ctx = cmd_get_ctx(); + ctx->error = cfg_error; + ctx->print = cfg_print; + ctx->info = cfg_print; + } + n = 0; line = NULL; retval = CMD_RETURN_NORMAL; @@ -146,22 +154,8 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes) if (cmdlist == NULL) continue; - if (ctxin == NULL) { - ctx.msgdata = NULL; - ctx.curclient = NULL; - ctx.cmdclient = NULL; - } else { - ctx.msgdata = ctxin->msgdata; - ctx.curclient = ctxin->curclient; - ctx.cmdclient = ctxin->cmdclient; - } - - ctx.error = cfg_error; - ctx.print = cfg_print; - ctx.info = cfg_print; - cfg_cause = NULL; - switch (cmd_list_exec(cmdlist, &ctx)) { + switch (cmd_list_exec(cmdlist, ctx)) { case CMD_RETURN_YIELD: if (retval != CMD_RETURN_ATTACH) retval = CMD_RETURN_YIELD; @@ -186,6 +180,8 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes) } fclose(f); + cmd_free_ctx(ctx); + cfg_references--; return (retval); |