Skip to content

Conversation

@cdecker
Copy link
Member

@cdecker cdecker commented Dec 3, 2018

  • Changelog entry
  • tal_arr_remove
  • Timeout for getmanifest call
  • Double free issue when killing a plugin.

@cdecker cdecker added the plugin label Dec 3, 2018
@cdecker cdecker added this to the v0.6.3 milestone Dec 3, 2018
@cdecker cdecker self-assigned this Dec 3, 2018
@cdecker cdecker requested a review from rustyrussell December 3, 2018 22:29
Copy link
Contributor

@rustyrussell rustyrussell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor cleanups only; looks v nice!

@rustyrussell
Copy link
Contributor

See previous comment:

Also, I think we can now remove the if (cmd && and similar in find_cmd and jsonrpc_command_add?

If we don't clean this up now, we'll never do it, since everyone will wonder if there's some subtle reason they can be NULL. I'm assuming, of course, that there isn't!

@rustyrussell
Copy link
Contributor

Needed this, so I fixed the other two and rebased...

@cdecker
Copy link
Member Author

cdecker commented Dec 5, 2018

Fixups squashed, will merge as soon as CI passes.

They pass the executable test, but aren't really executable.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
Signed-off-by: Christian Decker <@cdecker>
Suggested-by: Rusty Russell <@rustyrussell>
Signed-off-by: Christian Decker <decker.christian@gmail.com>
If the plugin fails to respond to we may end up hanging indefinitely,
so we limit the time we're willing to wait to 10 seconds.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
We can use the internal buffering of the json_stream instead of
manually building JSON-RPC calls. This makes it a lot easier to handle
these requests.

Notice that we do not flush concurrently and still buffer all the
things, but it avoids double-buffering things.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
Suggested-by: Rusty Russell <@rustyrussell>
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This used to be a use-after-free bug in which we'd free the plugin and
then still have two connections that expect to be able to operate on
the plugin. This now signals the connections to exit and cleans up
once they do.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
Both of these plugins will fail in interesting ways, and we should
still handle them correctly.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
@cdecker
Copy link
Member Author

cdecker commented Dec 5, 2018

The rebase on top of master introduced a new error (failtimeout.py is supposed to fail, but if we use plugin-dir=contrib/plugins it'll get picked up automatically.

Hence I added commit 85c520c which ignores subdirectories and moved the failing plugins into a subdirectory.

range-diff pre- vs post-rebase:

-:  -------- > 1:  85c520c7 plugin: Ignore directories in the plugin-directory
1:  bc5e6d71 = 2:  bb69dba7 changelog: Add plugin JSON-RPC passthrough
2:  9fb4db7b = 3:  07662f22 common: Add tal_arr_remove helper
3:  f52f71bb = 4:  1f84a6d1 plugin: Add a timeout to the `getmanifest` call
4:  e50d8497 = 5:  62e9a115 plugin: Migrate request creation to json_stream
5:  6fca4da5 = 6:  8b353114 jsonrpc: Use tal_arr_remove instead of leaving NULL in the commands
6:  a9512f3b = 7:  bc929c4d plugin: Better cleanup when a plugin fails
7:  316c064c ! 8:  d6906eb0 plugin: Add a test for timeout and broken manifest
    @@ -7,10 +7,10 @@
     
         Signed-off-by: Christian Decker <decker.christian@gmail.com>
     
    -diff --git a/contrib/plugins/failtimeout.py b/contrib/plugins/failtimeout.py
    +diff --git a/contrib/plugins/fail/failtimeout.py b/contrib/plugins/fail/failtimeout.py
     new file mode 100755
     --- /dev/null
    -+++ b/contrib/plugins/failtimeout.py
    ++++ b/contrib/plugins/fail/failtimeout.py
     @@
     +#!/usr/bin/env python3
     +"""An example plugin that fails to answer to `getmanifest`
    @@ -82,8 +82,8 @@
     +
     +def test_failing_plugins():
     +    fail_plugins = [
    -+        'contrib/plugins/failtimeout.py',
    -+        'contrib/plugins/doesnotexist.py',
    ++        'contrib/plugins/fail/failtimeout.py',
    ++        'contrib/plugins/fail/doesnotexist.py',
     +    ]
     +
     +    for p in fail_plugins:

diff pre- vs. post-rebase:

diff --git a/contrib/plugins/failtimeout.py b/contrib/plugins/fail/failtimeout.py
similarity index 100%
rename from contrib/plugins/failtimeout.py
rename to contrib/plugins/fail/failtimeout.py
diff --git a/lightningd/plugin.c b/lightningd/plugin.c
index 5d003add..121ddf42 100644
--- a/lightningd/plugin.c
+++ b/lightningd/plugin.c
@@ -723,7 +723,11 @@ static const char *plugin_fullpath(const tal_t *ctx, const char *dir,
 	fullname = path_join(ctx, dir, basename);
 	if (stat(fullname, &st) != 0)
 		return tal_free(fullname);
-	if (!(st.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)))
+	if (!(st.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH)) || st.st_mode & S_IFDIR)
+		return tal_free(fullname);
+
+	/* Ignore directories, they have exec mode, but aren't executable. */
+	if (st.st_mode & S_IFDIR)
 		return tal_free(fullname);
 	return fullname;
 }
diff --git a/tests/test_plugin.py b/tests/test_plugin.py
index 68390ad9..8b85269a 100644
--- a/tests/test_plugin.py
+++ b/tests/test_plugin.py
@@ -81,8 +81,8 @@ def test_plugin_disable(node_factory):
 
 def test_failing_plugins():
     fail_plugins = [
-        'contrib/plugins/failtimeout.py',
-        'contrib/plugins/doesnotexist.py',
+        'contrib/plugins/fail/failtimeout.py',
+        'contrib/plugins/fail/doesnotexist.py',
     ]
 
     for p in fail_plugins:

Copy link
Contributor

@rustyrussell rustyrussell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack d6906eb


/* Ignore directories, they have exec mode, but aren't executable. */
if (st.st_mode & S_IFDIR)
return tal_free(fullname);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reversing these tests makes more sense, but it's a trivial cleanup, so I'll apply this and do a separate PR.

@rustyrussell rustyrussell merged commit f5a3f1f into ElementsProject:master Dec 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants