Example #1
0
void command_fail(struct command *cmd, const char *fmt, ...)
{
	char *quote, *error;
	struct json_connection *jcon = cmd->jcon;
	va_list ap;

	if (!jcon) {
		log_unusual(cmd->dstate->base_log,
			    "Command failed after jcon close");
		tal_free(cmd);
		return;
	}

	va_start(ap, fmt);
	error = tal_vfmt(cmd, fmt, ap);
	va_end(ap);

	log_debug(jcon->log, "Failing: %s", error);

	/* Remove " */
	while ((quote = strchr(error, '"')) != NULL)
		*quote = '\'';

	/* Now surround in quotes. */
	quote = tal_fmt(cmd, "\"%s\"", error);

	assert(jcon->current == cmd);
	json_result(jcon, cmd->id, "null", quote);
	jcon->current = tal_free(cmd);
}
Example #2
0
PRINTF_FMT(2,3) static void attempt_failed_fmt(struct pay_command *pc, const char *fmt, ...)
{
	struct pay_attempt *attempt = current_attempt(pc);
	va_list ap;

	va_start(ap,fmt);
	attempt->failure = tal_vfmt(pc->ps->attempts, fmt, ap);
	attempt->end = time_now();
	va_end(ap);
}
Example #3
0
Pkt *pkt_err(struct peer *peer, const char *msg, ...)
{
	Error *e = tal(peer, Error);
	va_list ap;

	error__init(e);
	va_start(ap, msg);
	e->problem = tal_vfmt(e, msg, ap);
	va_end(ap);

	return make_pkt(peer, PKT__PKT_ERROR, e);
}
Example #4
0
lines_from_cmd(const void *ctx, const char *format, ...)
{
	va_list ap;
	char *cmd;
	FILE *p;
	struct rbuf in;

	va_start(ap, format);
	cmd = tal_vfmt(ctx, format, ap);
	va_end(ap);

	p = popen(cmd, "r");
	if (!p)
		err(1, "Executing '%s'", cmd);

	/* FIXME: Use rbuf_read_str(&in, '\n') rather than strsplit! */
	rbuf_init(&in, fileno(p), tal_arr(ctx, char, 0), 0);
	if (!rbuf_read_str(&in, 0, do_tal_realloc) && errno)
		err(1, "Reading from '%s'", cmd);
	pclose(p);

	return tal_strsplit(ctx, in.buf, "\n", STR_EMPTY_OK);
}