2018-09-04 04:53:32 +02:00
|
|
|
#include <ccan/tal/str/str.h>
|
2017-08-28 18:05:01 +02:00
|
|
|
#include <common/dev_disconnect.h>
|
2017-09-12 06:56:59 +02:00
|
|
|
#include <common/status.h>
|
2018-01-08 11:01:09 +01:00
|
|
|
#include <common/subdaemon.h>
|
|
|
|
#include <common/utils.h>
|
|
|
|
#include <common/version.h>
|
2017-09-12 06:56:59 +02:00
|
|
|
#include <signal.h>
|
2017-02-24 06:52:56 +01:00
|
|
|
#include <stdio.h>
|
2017-05-24 12:10:16 +02:00
|
|
|
#include <stdlib.h>
|
2017-02-24 06:52:56 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
2018-03-28 04:32:39 +02:00
|
|
|
#include <wally_core.h>
|
2017-02-24 06:52:56 +01:00
|
|
|
|
2018-03-29 04:06:45 +02:00
|
|
|
static void status_backtrace_print(const char *fmt, ...)
|
2017-09-12 06:56:59 +02:00
|
|
|
{
|
2018-03-29 04:06:45 +02:00
|
|
|
va_list ap;
|
2017-09-12 06:56:59 +02:00
|
|
|
|
2018-03-29 04:06:45 +02:00
|
|
|
va_start(ap, fmt);
|
|
|
|
status_vfmt(LOG_BROKEN, fmt, ap);
|
|
|
|
va_end(ap);
|
2017-09-12 06:56:59 +02:00
|
|
|
}
|
|
|
|
|
2018-03-29 04:06:45 +02:00
|
|
|
static void status_backtrace_exit(void)
|
2017-09-12 06:56:59 +02:00
|
|
|
{
|
2018-03-29 04:06:45 +02:00
|
|
|
status_failed(STATUS_FAIL_INTERNAL_ERROR, "FATAL SIGNAL");
|
2017-09-12 06:56:59 +02:00
|
|
|
}
|
|
|
|
|
2018-01-15 10:36:17 +01:00
|
|
|
void subdaemon_setup(int argc, char *argv[])
|
|
|
|
{
|
2018-01-08 11:01:09 +01:00
|
|
|
if (argc == 2 && streq(argv[1], "--version")) {
|
|
|
|
printf("%s\n", version());
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2018-01-15 10:36:17 +01:00
|
|
|
for (int i = 1; i < argc; i++) {
|
2018-02-05 05:09:28 +01:00
|
|
|
if (streq(argv[i], "--log-io"))
|
|
|
|
logging_io = true;
|
2017-05-24 12:10:16 +02:00
|
|
|
}
|
|
|
|
|
2018-02-05 05:09:28 +01:00
|
|
|
#if DEVELOPER
|
2018-01-15 10:36:17 +01:00
|
|
|
/* From debugger, set debugger_spin to 0. */
|
|
|
|
for (int i = 1; i < argc; i++) {
|
|
|
|
if (streq(argv[i], "--debugger")) {
|
2018-09-04 04:53:32 +02:00
|
|
|
char *cmd = tal_fmt(NULL, "${DEBUG_TERM:-gnome-terminal --} gdb -ex 'attach %u' %s &", getpid(), argv[0]);
|
|
|
|
fprintf(stderr, "Running %s\n", cmd);
|
|
|
|
system(cmd);
|
|
|
|
/* Continue in the debugger. */
|
|
|
|
kill(getpid(), SIGSTOP);
|
2017-02-24 06:52:56 +01:00
|
|
|
}
|
2018-02-05 05:09:28 +01:00
|
|
|
if (strstarts(argv[i], "--dev-disconnect=")) {
|
|
|
|
dev_disconnect_init(atoi(argv[i]
|
|
|
|
+ strlen("--dev-disconnect=")));
|
|
|
|
}
|
2017-02-24 06:52:56 +01:00
|
|
|
}
|
2017-10-24 04:06:14 +02:00
|
|
|
#endif
|
2018-03-28 04:30:49 +02:00
|
|
|
|
2018-03-29 04:06:45 +02:00
|
|
|
daemon_setup(argv[0], status_backtrace_print, status_backtrace_exit);
|
2018-03-28 04:30:49 +02:00
|
|
|
}
|
2018-03-29 04:06:45 +02:00
|
|
|
|