Skip to content

Commit 9987b6f

Browse files
committed
lightningd: try harder to ensure uniqueness in --dev-save-plugin-io names.
Incorporate a time: this covers the restart case as well. And make it time_mono(), which doesn't get overridden when we override normal wall time. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 75616f6 commit 9987b6f

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

lightningd/plugin.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2622,16 +2622,24 @@ static void dev_save_plugin_io(struct plugins *plugins,
26222622
const char *buf, size_t len)
26232623
{
26242624
static size_t counter;
2625+
static u64 starttime;
26252626
const char *file;
26262627
int fd;
26272628

26282629
if (!plugins->dev_save_io)
26292630
return;
26302631

2632+
/* If we reexec, we still want unique names */
2633+
if (!starttime) {
2634+
struct timemono start = time_mono();
2635+
starttime = start.ts.tv_sec * 1000000 + start.ts.tv_nsec / 1000;
2636+
}
2637+
26312638
file = path_join(tmpctx, plugins->dev_save_io,
2632-
take(tal_fmt(NULL, "%s-%s-%u-%zu",
2639+
take(tal_fmt(NULL, "%s-%s-%u-%"PRIu64"-%zu",
26332640
type, name,
26342641
(unsigned int)getpid(),
2642+
starttime,
26352643
counter++)));
26362644
fd = open(file, O_CREAT|O_EXCL|O_WRONLY, 0600);
26372645
if (fd < 0 || !write_all(fd, buf, len))

tests/test_misc.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3692,8 +3692,6 @@ def test_version_reexec(node_factory, bitcoind):
36923692
# We use a file to tell our openingd wrapper where the real one is
36933693
with open(os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "openingd-real"), 'w') as f:
36943694
f.write(os.path.abspath('lightningd/lightning_openingd'))
3695-
# Internal restart doesn't work well with --dev-save-plugin-io
3696-
del l1.daemon.opts['dev-save-plugin-io']
36973695
l1.start()
36983696
# This is a "version" message
36993697
verfile = os.path.join(l1.daemon.lightning_dir, TEST_NETWORK, "openingd-version")
@@ -4569,11 +4567,7 @@ def test_setconfig_changed(node_factory, bitcoind):
45694567

45704568
@unittest.skipIf(os.getenv('TEST_DB_PROVIDER', 'sqlite3') != 'sqlite3', "deletes database, which is assumed sqlite3")
45714569
def test_recover_command(node_factory, bitcoind):
4572-
l1 = node_factory.get_node(start=False)
4573-
# Internal restart doesn't work well with --dev-save-plugin-io
4574-
del l1.daemon.opts['dev-save-plugin-io']
4575-
l1.start()
4576-
l2 = node_factory.get_node()
4570+
l1, l2 = node_factory.get_nodes(2)
45774571

45784572
l1oldid = l1.info['id']
45794573

0 commit comments

Comments
 (0)