1 /* When running as a subdaemon controlled by lightningd the hsmd will
2 * report logging, debugging information and crash reports to
3 * lightningd via the status socket, using the wire protocol used in
4 * LN more generally. This is done so lightningd can print add the
5 * messages to its own logs, presenting a unified view of what is
6 * happening.
7 *
8 * When using libhsmd not as a subdaemon controlled by lightningd we
9 * cannot make use of the communication primitives we used in that
10 * context. For this reason libhsmd defers the selection of actual
11 * primitives to link time, and here we provide simple ones that just
12 * print to stdout, as alternatives to the status wire protocol ones.
13 */
14 #include <hsmd/libhsmd.h>
15 #include <stdio.h>
hsmd_status_bad_request(struct hsmd_client * client,const u8 * msg,const char * error)16 u8 *hsmd_status_bad_request(struct hsmd_client *client, const u8 *msg, const char *error)
17 {
18 fprintf(stderr, "%s\n", error);
19 return NULL;
20 }
21
hsmd_status_fmt(enum log_level level,const struct node_id * peer,const char * fmt,...)22 void hsmd_status_fmt(enum log_level level, const struct node_id *peer,
23 const char *fmt, ...)
24 {
25 va_list ap;
26 char *msg;
27 FILE *stream = level >= LOG_UNUSUAL ? stderr : stdout;
28 va_start(ap, fmt);
29 msg = tal_vfmt(NULL, fmt, ap);
30 va_end(ap);
31
32 if (peer != NULL)
33 fprintf(stream, "[%s] %s: %s\n", log_level_name(level),
34 node_id_to_hexstr(msg, peer), msg);
35 else
36 fprintf(stream, "[%s]: %s\n", log_level_name(level), msg);
37
38 tal_free(msg);
39 }
40
hsmd_status_failed(enum status_failreason reason,const char * fmt,...)41 void hsmd_status_failed(enum status_failreason reason, const char *fmt, ...)
42 {
43 va_list ap;
44
45 va_start(ap, fmt);
46 vfprintf(stderr, fmt, ap);
47 va_end(ap);
48
49 exit(0x80 | (reason & 0xFF));
50 }
51