Send connman mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.01.org/mailman/listinfo/connman
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of connman digest..."


Today's Topics:

   1. [PATCH 0/3] Move pacrunner to mozjs38 (Jeremy Linton)
   2. [PATCH 1/3] Fix test-mozjs memory leak (Jeremy Linton)
   3. [PATCH 2/3] Fix unclean shutdown with proxy_disable
      (Jeremy Linton)
   4. [PATCH 3/3] Pull mozjs forward to mozjs38 (Jeremy Linton)
   5. Do not lose wpa_supplicant interface configuration
      (Jose Blanquicet)


----------------------------------------------------------------------

Message: 1
Date: Thu, 22 Sep 2016 15:32:43 -0500
From: Jeremy Linton <[email protected]>
To: [email protected]
Subject: [PATCH 0/3] Move pacrunner to mozjs38
Message-ID: <[email protected]>

This set builds on the previous set moving pacrunner
to mozj24. This set fixes some general memory leaks/bugs
then moves pacrunner to mozjs38.

Jeremy Linton (3):
  Fix test-mozjs memory leak
  Fix unclean shutdown with proxy_disable
  Pull mozjs forward to mozjs38

 configure.ac      |  4 +--
 plugins/mozjs.cc  | 87 ++++++++++++++++++++++++++++---------------------------
 src/proxy.c       |  4 ++-
 unit/test-mozjs.c | 19 +++++++-----
 4 files changed, 62 insertions(+), 52 deletions(-)

-- 
2.9.2



------------------------------

Message: 2
Date: Thu, 22 Sep 2016 15:32:44 -0500
From: Jeremy Linton <[email protected]>
To: [email protected]
Subject: [PATCH 1/3] Fix test-mozjs memory leak
Message-ID: <[email protected]>

The mozjs execute calls returns a g_strdup'ed result. This
means that the unit test needs to free the resulting data.

Signed-off-by: Jeremy Linton <[email protected]>
---
 unit/test-mozjs.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/unit/test-mozjs.c b/unit/test-mozjs.c
index 7ccdee9..25c8634 100644
--- a/unit/test-mozjs.c
+++ b/unit/test-mozjs.c
@@ -93,19 +93,19 @@ static void test_multiple_init(void)
 
 static void test_single_execute_without_pac(void)
 {
-       const char *result;
+       char *result;
 
        g_assert(mozjs_init() == 0);
 
        result = __pacrunner_js_execute(proxy, EXAMPLE_URL, EXAMPLE_HOST);
        g_test_message("result: %s", result);
-
+       g_free(result);
        mozjs_exit();
 }
 
 static void test_multiple_execute_without_pac(void)
 {
-       const char *result;
+       char *result;
        int i;
 
        g_assert(mozjs_init() == 0);
@@ -114,6 +114,7 @@ static void test_multiple_execute_without_pac(void)
                result = __pacrunner_js_execute(proxy, EXAMPLE_URL,
                                                EXAMPLE_HOST);
                g_test_message("result %d: %s", i, result);
+               g_free(result);
        }
 
        mozjs_exit();
@@ -121,7 +122,7 @@ static void test_multiple_execute_without_pac(void)
 
 static void test_single_execute_with_direct_pac(void)
 {
-       const char *result;
+       char *result;
 
        g_assert(mozjs_init() == 0);
 
@@ -129,6 +130,7 @@ static void test_single_execute_with_direct_pac(void)
 
        result = __pacrunner_js_execute(proxy, EXAMPLE_URL, EXAMPLE_HOST);
        g_test_message("result: %s", result);
+       g_free(result);
 
        pacrunner_proxy_disable(proxy);
 
@@ -137,7 +139,7 @@ static void test_single_execute_with_direct_pac(void)
 
 static void test_multiple_execute_with_direct_pac(void)
 {
-       const char *result;
+       char *result;
        int i;
 
        mozjs_init();
@@ -148,6 +150,7 @@ static void test_multiple_execute_with_direct_pac(void)
                result = __pacrunner_js_execute(proxy, EXAMPLE_URL,
                                                EXAMPLE_HOST);
                g_test_message("result %d: %s", i, result);
+               g_free(result);
        }
 
        pacrunner_proxy_disable(proxy);
@@ -157,7 +160,7 @@ static void test_multiple_execute_with_direct_pac(void)
 
 static void test_massive_execute_with_direct_pac(void)
 {
-       const char *result;
+       char *result;
        int i;
 
        mozjs_init();
@@ -168,6 +171,7 @@ static void test_massive_execute_with_direct_pac(void)
                result = __pacrunner_js_execute(proxy, EXAMPLE_URL,
                                                EXAMPLE_HOST);
                g_test_message("result %d: %s", i, result);
+               g_free(result);
        }
 
        pacrunner_proxy_disable(proxy);
@@ -177,7 +181,7 @@ static void test_massive_execute_with_direct_pac(void)
 
 static void test_multiple_execute_with_example_pac(void)
 {
-       const char *result;
+       char *result;
        int i;
 
        mozjs_init();
@@ -188,6 +192,7 @@ static void test_multiple_execute_with_example_pac(void)
                result = __pacrunner_js_execute(proxy, EXAMPLE_URL,
                                                EXAMPLE_HOST);
                g_test_message("result %d: %s", i, result);
+               g_free(result);
        }
 
        pacrunner_proxy_disable(proxy);
-- 
2.9.2



------------------------------

Message: 3
Date: Thu, 22 Sep 2016 15:32:45 -0500
From: Jeremy Linton <[email protected]>
To: [email protected]
Subject: [PATCH 2/3] Fix unclean shutdown with proxy_disable
Message-ID: <[email protected]>

The proxy disable code calls set_proxy and clears the
context structure, which results in the mosjs_clear_proxy
not being called. Also there is a memory leak in the glist
due to use of remove_link() rather than remove(). The former
simply removes the entry from the linked list but doesn't free
it.

Signed-off-by: Jeremy Linton <[email protected]>
---
 src/proxy.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/proxy.c b/src/proxy.c
index db49c58..49d72ac 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -419,9 +419,11 @@ int pacrunner_proxy_disable(struct pacrunner_proxy *proxy)
 
        pthread_mutex_lock(&proxy_mutex);
        proxy_list = g_list_remove_link(proxy_list, list);
+       g_list_free(list); //must manually delete entry when 
g_link_remove_link()
+                          //is used instead of g_link_remove()
        pthread_mutex_unlock(&proxy_mutex);
 
-       __pacrunner_js_set_proxy(NULL);
+       __pacrunner_js_clear_proxy(proxy);
 
        pacrunner_proxy_unref(proxy);
 
-- 
2.9.2



------------------------------

Message: 4
Date: Thu, 22 Sep 2016 15:32:46 -0500
From: Jeremy Linton <[email protected]>
To: [email protected]
Subject: [PATCH 3/3] Pull mozjs forward to mozjs38
Message-ID: <[email protected]>

Mozjs24 is pretty old, lets move pacrunner forward
to a mozjs that has better support. This change replaces
some JSAPI macro's with C++ standard definitions
(JS_BOOL->bool), and adds the js rooting required
to be able to call the recent APIs.

Signed-off-by: Jeremy Linton <[email protected]>
---
 configure.ac     |  4 +--
 plugins/mozjs.cc | 87 +++++++++++++++++++++++++++++---------------------------
 2 files changed, 47 insertions(+), 44 deletions(-)

diff --git a/configure.ac b/configure.ac
index d2fc8f8..ad494d1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -76,8 +76,8 @@ AM_CONDITIONAL(DUKTAPE, test "${enable_duktape}" = "yes")
 AC_ARG_ENABLE(mozjs, AC_HELP_STRING([--enable-mozjs],
                [enable Mozilla Javascript plugin support]))
 if (test "${enable_mozjs}" = "yes"); then
-       PKG_CHECK_MODULES(MOZJS,  mozjs-24, dummy=yes,
-                       AC_MSG_ERROR(Mozilla Javascript >= 24 is required))
+       PKG_CHECK_MODULES(MOZJS,  mozjs-38, dummy=yes,
+                       AC_MSG_ERROR(Mozilla Javascript >= 38 is required))
        AC_SUBST(MOZJS_CFLAGS)
        AC_SUBST(MOZJS_LIBS)
 fi
diff --git a/plugins/mozjs.cc b/plugins/mozjs.cc
index 8c7a7ce..e10b297 100644
--- a/plugins/mozjs.cc
+++ b/plugins/mozjs.cc
@@ -50,40 +50,39 @@ struct pacrunner_mozjs {
        JSAutoCompartment *jsac;
 };
 
-static JSBool myipaddress(JSContext *jsctx, unsigned argc, jsval *vp)
+static bool myipaddress(JSContext *jsctx, unsigned argc, jsval *vp)
 {
        struct pacrunner_mozjs *ctx = (pacrunner_mozjs 
*)JS_GetContextPrivate(jsctx);
        char address[NI_MAXHOST];
 
        DBG("");
 
-       JS_SET_RVAL(jsctx, vp, JSVAL_NULL);
+       JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
+
+       args.rval().setNull();
 
        if (!ctx)
-               return JS_TRUE;
+               return true;
 
        if (__pacrunner_js_getipaddr(ctx->proxy, address, sizeof(address)) < 0)
-               return JS_TRUE;
+               return true;
 
        DBG("address %s", address);
 
-       JS_SET_RVAL(jsctx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(jsctx,
-                                                              address)));
+       args.rval().setString(JS_NewStringCopyZ(jsctx,address));
 
-       return JS_TRUE;
+       return true;
 }
 
-static JSBool dnsresolve(JSContext *jsctx, unsigned argc, jsval *vp)
+static bool dnsresolve(JSContext *jsctx, unsigned argc, jsval *vp)
 {
        struct pacrunner_mozjs *ctx = (pacrunner_mozjs 
*)JS_GetContextPrivate(jsctx);
        char address[NI_MAXHOST];
-       jsval *argv = JS_ARGV(jsctx, vp);
-       char *host = JS_EncodeString(jsctx, JS_ValueToString(jsctx, argv[0]));
+       JS::CallArgs args = JS::CallArgsFromVp(argc,vp);
+       char * host = JS_EncodeString(jsctx, args[0].toString());
 
        DBG("host %s", host);
 
-       JS_SET_RVAL(jsctx, vp, JSVAL_NULL);
-
        if (!ctx)
                goto out;
 
@@ -92,20 +91,16 @@ static JSBool dnsresolve(JSContext *jsctx, unsigned argc, 
jsval *vp)
 
        DBG("address %s", address);
 
-       JS_SET_RVAL(jsctx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(jsctx, 
address)));
+       args.rval().setString(JS_NewStringCopyZ(jsctx,address));
 
  out:
        JS_free(jsctx, host);
-       return JS_TRUE;
+       return true;
 
 }
 
 static JSClass jscls = {
        "global", JSCLASS_GLOBAL_FLAGS,
-       JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub,
-       JS_StrictPropertyStub,
-       JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL,
-       JSCLASS_NO_OPTIONAL_MEMBERS
 };
 
 static JSRuntime *jsrun;
@@ -114,7 +109,6 @@ static int create_object(struct pacrunner_proxy *proxy)
 {
        struct pacrunner_mozjs *ctx;
        const char *script;
-       jsval rval;
 
        script = pacrunner_proxy_get_script(proxy);
        if (!script)
@@ -133,22 +127,29 @@ static int create_object(struct pacrunner_proxy *proxy)
 
        JS::CompartmentOptions compart_opts;
        compart_opts.setVersion(JSVERSION_LATEST);
-       ctx->jsobj = JS_NewGlobalObject(ctx->jsctx, &jscls, NULL, compart_opts);
-       ctx->jsac = new JSAutoCompartment(ctx->jsctx, ctx->jsobj);
+       ctx->jsobj = JS_NewGlobalObject(ctx->jsctx, &jscls, nullptr,
+                                       JS::DontFireOnNewGlobalHook, 
compart_opts);
+       JS::RootedObject jsobj(ctx->jsctx,ctx->jsobj);
+
+       ctx->jsac = new JSAutoCompartment(ctx->jsctx, jsobj);
 
-       if (!JS_InitStandardClasses(ctx->jsctx, ctx->jsobj))
+       if (!JS_InitStandardClasses(ctx->jsctx, jsobj))
                pacrunner_error("Failed to init JS standard classes");
 
-       JS_DefineFunction(ctx->jsctx, ctx->jsobj, "myIpAddress",
-                         myipaddress, 0, 0);
-       JS_DefineFunction(ctx->jsctx, ctx->jsobj,
-                         "dnsResolve", dnsresolve, 1, 0);
+       JS_DefineFunction(ctx->jsctx, jsobj, "myIpAddress", myipaddress, 0, 0);
+       JS_DefineFunction(ctx->jsctx, jsobj, "dnsResolve", dnsresolve, 1, 0);
 
-       JS_EvaluateScript(ctx->jsctx, ctx->jsobj, __pacrunner_js_routines,
-                         strlen(__pacrunner_js_routines), NULL, 0, &rval);
+       JS::RootedValue rval(ctx->jsctx);
+       JS::CompileOptions opts(ctx->jsctx);
+       opts.setIntroductionType("pacrunner")
+           .setUTF8(true)
+           .setCompileAndGo(true);
 
-       JS_EvaluateScript(ctx->jsctx, ctx->jsobj, script, strlen(script),
-                         "wpad.dat", 0, &rval);
+       JS::Evaluate(ctx->jsctx, JS::HandleObject(jsobj), opts,
+                    __pacrunner_js_routines, strlen(__pacrunner_js_routines)
+                    , &rval);
+
+       JS::Evaluate(ctx->jsctx, jsobj, opts, script, strlen(script), &rval);
 
        return 0;
 }
@@ -165,6 +166,7 @@ static int mozjs_clear_proxy(struct pacrunner_proxy *proxy)
        delete ctx->jsac;
        JS_DestroyContext(ctx->jsctx);
        __pacrunner_proxy_set_jsctx(proxy, NULL);
+       g_free(ctx);
 
        return 0;
 }
@@ -172,7 +174,6 @@ static int mozjs_clear_proxy(struct pacrunner_proxy *proxy)
 static int mozjs_set_proxy(struct pacrunner_proxy *proxy)
 {
        DBG("proxy %p", proxy);
-
        if (!proxy)
                return 0;
 
@@ -185,10 +186,8 @@ static char * mozjs_execute(struct pacrunner_proxy *proxy, 
const char *url,
                            const char *host)
 {
        struct pacrunner_mozjs *ctx = (pacrunner_mozjs 
*)__pacrunner_proxy_get_jsctx(proxy);
-       JSBool result;
-       jsval rval, args[2];
+       bool result;
        char *answer, *g_answer;
-
        DBG("proxy %p ctx %p url %s host %s", proxy, ctx, url, host);
 
        if (!ctx)
@@ -197,12 +196,16 @@ static char * mozjs_execute(struct pacrunner_proxy 
*proxy, const char *url,
        pthread_mutex_lock(&mozjs_mutex);
 
        JS_BeginRequest(ctx->jsctx);
+       JS::RootedValue rval(ctx->jsctx);
+       JS::AutoValueArray<2> args(ctx->jsctx);
+
+       args[0].setString(JS_NewStringCopyZ(ctx->jsctx, url));
+       args[1].setString(JS_NewStringCopyZ(ctx->jsctx, host));
 
-       args[0] = STRING_TO_JSVAL(JS_NewStringCopyZ(ctx->jsctx, url));
-       args[1] = STRING_TO_JSVAL(JS_NewStringCopyZ(ctx->jsctx, host));
 
-       result = JS_CallFunctionName(ctx->jsctx, ctx->jsobj,
-                                    "FindProxyForURL", 2, args, &rval);
+       JS::RootedObject jsobj(ctx->jsctx,ctx->jsobj);
+
+       result = JS_CallFunctionName(ctx->jsctx, jsobj, "FindProxyForURL", args 
, &rval);
 
        JS_EndRequest(ctx->jsctx);
 
@@ -211,8 +214,7 @@ static char * mozjs_execute(struct pacrunner_proxy *proxy, 
const char *url,
        pthread_mutex_unlock(&mozjs_mutex);
 
        if (result) {
-               answer = JS_EncodeString(ctx->jsctx,
-                                        JS_ValueToString(ctx->jsctx, rval));
+               answer = JS_EncodeString(ctx->jsctx, rval.toString());
                g_answer = g_strdup(answer);
                JS_free(ctx->jsctx, answer);
                return g_answer;
@@ -232,8 +234,8 @@ static struct pacrunner_js_driver mozjs_driver = {
 static int mozjs_init(void)
 {
        DBG("");
-
-       jsrun = JS_NewRuntime(8 * 1024 * 1024, JS_USE_HELPER_THREADS);
+       JS_Init();
+       jsrun = JS_NewRuntime(JS::DefaultHeapMaxBytes, 8 * 1024 * 1024 );
 
        return pacrunner_js_driver_register(&mozjs_driver);
 }
@@ -245,6 +247,7 @@ static void mozjs_exit(void)
        pacrunner_js_driver_unregister(&mozjs_driver);
 
        JS_DestroyRuntime(jsrun);
+       JS_ShutDown();
 }
 
 PACRUNNER_PLUGIN_DEFINE(mozjs, mozjs_init, mozjs_exit)
-- 
2.9.2



------------------------------

Message: 5
Date: Fri, 23 Sep 2016 11:36:26 +0200
From: Jose Blanquicet <[email protected]>
To: [email protected],  "MANIEZZO Marco (MM)"
        <[email protected]>
Subject: Do not lose wpa_supplicant interface configuration
Message-ID:
        <CAFC8iJJdZctwKgn=tafxravwaep5uuqpy082xqj+2flqr65...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Hi,

Currently, each time ConnMan removes wpa_s interfaces at runtime the
configuration indicated in that file is lost. It was because wpa_s did
not expose the configuration file path in order to allow ConnMan to
recreate interfaces with the same configuration they were initially
created. In order to solve this we proposed a patch to wpa_s community
(b44d9c760fda85797187f1d0e97be47ed0182ed6), that patch aims to expose
the configuration file path as an D-Bus interface property. It was
recently applied and now ConnMan has the possibility to recreate
interfaces with the correct configuration file path, to solve the
following issues, (If someone knows other cases please let us know):

1. Enable/Disable WiFi: All wpa_s interfaces are removed, and config
information is lost.
2. Tethering: When enabling, the selected wpa_s interface is removed
and recreated with the bridge "tether". Also when disabling, again the
tethering wpa_s interface is removed and recreated without bridge.
After the tethering enable the config information is lost.
3. ConnMan turns off: All wpa_s interfaces are removed, and config
information is lost.

We are working on a patch to use this new property in order to not
lose the wpa_s interface configuration. To do this, we definitely need
to store this value before removing the interface and use it later
when recreating. We would like to discuss here on how and where store
this information in ConnMan:

1. Enable/Disable WiFi: Neither wifi nor device structs are removed,
so the path can be easily stored in any of these two structs.
2. Tethering: Both wifi and device structs are removed. We think that
could be a good idea to use a temporal struct inside Technology's
struct where we store the interface name or index and the config file
path of the tethering interface when tethering is disabling and then
pass this info again to wifi plugin when interface is re-detected and
will be re-created. There should not be problems because there is only
one tethering interface at a time per technology: anyone can confirm?
Please any feedback is appreciated.
3. ConnMan turns off: Due to ConnMan removes all wpa_s intefaces when
turning off, wpa_s remains almost useless and wpa_s cannot be used
neither from wpa_cli, because it will not communicate to wpa_s if it
has no interface registered. One idea could be then to close also
wpa_s.

Please everybody feel free to comment and make suggestions.

Regards,

Jose Blanquicet


------------------------------

Subject: Digest Footer

_______________________________________________
connman mailing list
[email protected]
https://lists.01.org/mailman/listinfo/connman


------------------------------

End of connman Digest, Vol 11, Issue 27
***************************************

Reply via email to