rpcd: iwinfo: add IEEE 802.11be support
[project/rpcd.git] / ucode.c
diff --git a/ucode.c b/ucode.c
index c67a6193e8c32fd64c125e4b2c7db01ffa9ca394..5c84776d951519c9810cb4d4128064c938ae8db7 100644 (file)
--- a/ucode.c
+++ b/ucode.c
@@ -304,8 +304,13 @@ rpc_ucode_validate_call_args(struct ubus_object *obj, const char *ubus_method_na
                }
 
                /* named argument not found in policy */
-               if (!found)
+               if (!found) {
+                       /* allow special ubus_rpc_session argument */
+                       if (!strcmp("ubus_rpc_session", (char *)hdr->name) && blob_id(attr) == BLOBMSG_TYPE_STRING)
+                           continue;
+
                        goto inval;
+               }
        }
 
        *res = rpc_ucode_blob_array_to_ucv(&script->vm, blob_data(msg), blob_len(msg), true);
@@ -396,6 +401,7 @@ rpc_ucode_script_call(struct ubus_context *ctx, struct ubus_object *obj,
        rpc_ucode_script_t *script = rpc_ucode_obj_to_script(obj);
        uc_value_t *func, *args = NULL, *reqobj, *reqproto, *res;
        rpc_ucode_call_ctx_t *callctx;
+       const char *extype;
        size_t i;
        int rv;
 
@@ -494,6 +500,23 @@ rpc_ucode_script_call(struct ubus_context *ctx, struct ubus_object *obj,
 
        /* treat other exceptions as unknown error */
        default:
+               switch (script->vm.exception.type) {
+               case EXCEPTION_SYNTAX:    extype = "Syntax error";    break;
+               case EXCEPTION_RUNTIME:   extype = "Runtime error";   break;
+               case EXCEPTION_TYPE:      extype = "Type error";      break;
+               case EXCEPTION_REFERENCE: extype = "Reference error"; break;
+               default:                  extype = "Exception";
+               }
+
+               res = ucv_object_get(
+                       ucv_array_get(script->vm.exception.stacktrace, 0),
+                       "context", NULL);
+
+               fprintf(stderr,
+                       "Unhandled ucode exception in '%s' method!\n%s: %s\n\n%s\n",
+                       ubus_method_name, extype, script->vm.exception.message,
+                       ucv_string_get(res));
+
                ubus_complete_deferred_request(ctx, &callctx->req, UBUS_STATUS_UNKNOWN_ERROR);
                callctx->replied = true;
                break;
@@ -929,7 +952,6 @@ rpc_ucode_script_execute(struct ubus_context *ctx, const char *path, uc_program_
 
        script->path = strncpy(pptr, path, pathlen);
 
-       uc_search_path_init(&config.module_search_path);
        uc_vm_init(&script->vm, &config);
        rpc_ucode_init_globals(script);
 
@@ -1019,6 +1041,10 @@ rpc_ucode_api_init(const struct rpc_daemon_ops *ops, struct ubus_context *ctx)
                fprintf(stderr, "Failed to dlopen() ucode.so: %s, dynamic ucode plugins may fail\n",
                        dlerror());
        }
+
+       /* initialize default module search path */
+       uc_search_path_init(&config.module_search_path);
+
        if ((d = opendir(RPC_UCSCRIPT_DIRECTORY)) != NULL) {
                while ((e = readdir(d)) != NULL) {
                        snprintf(path, sizeof(path), RPC_UCSCRIPT_DIRECTORY "/%s", e->d_name);