xiaoxiang781216 commented on code in PR #20599:
URL: https://github.com/apache/nuttx/pull/20599#discussion_r4259815944


##########
binfmt/script.c:
##########
@@ -149,24 +221,108 @@ static int script_loadbinary(FAR struct binary_s *binp,
       end++;
     }
 
-  *end = '\0';
+  if (*end != '\0')
+    {
+      *end++ = '\0';
+      while (isspace(*end))
+        {
+          end++;
+        }
+
+      if (*end != '\0')
+        {
+          arg = end;
+          end = arg + strlen(arg);
+          while (isspace(*(end - 1)))
+            {
+              end--;
+            }
+
+          *end = '\0';
+        }
+    }
 
-  binfo("Script: interp='%s' script='%s'\n", interp, filename);
+  binfo("Script: interp='%s' arg='%s' script='%s'\n",
+        interp, arg ? arg : "", filename);
 
-  /* Ask exec_module() to keep the original filename as the task name and
-   * forward the unchanged argv, so the interpreter receives the script
-   * path (the original filename) at argv[1].
+  /* The interpreter runs with: interp [arg] filename argv[1] ...
+   * filename is the path that was loaded, after the PATH search.
    */
 
-  binp->filename = true;
+  ret = script_setargv(binp, interp, arg, filename);

Review Comment:
   not good do the allocation two times in script_setargv and script_buildargv



##########
binfmt/binfmt_execmodule.c:
##########
@@ -212,7 +215,31 @@ int exec_module(FAR struct binary_s *binp,
       return -ENOMEM;
     }
 
+#ifdef CONFIG_BINFMT_SCRIPT
+  /* A script runs its interpreter, with the interpreter's arguments before
+   * the caller's arguments.
+   */
+
+  if (binp->scriptargv != NULL)
+    {
+      ret = script_buildargv(binp->scriptargv, argv, &scriptargv);

Review Comment:
   not good to allocate memory even the binary mayn't the script file



##########
binfmt/binfmt_execmodule.c:
##########
@@ -212,7 +215,31 @@ int exec_module(FAR struct binary_s *binp,
       return -ENOMEM;
     }
 
+#ifdef CONFIG_BINFMT_SCRIPT
+  /* A script runs its interpreter, with the interpreter's arguments before
+   * the caller's arguments.
+   */
+
+  if (binp->scriptargv != NULL)
+    {
+      ret = script_buildargv(binp->scriptargv, argv, &scriptargv);
+      if (ret < 0)
+        {
+          goto errout_with_tcb;
+        }
+
+      argv = scriptargv;
+    }
+#endif
+
   ret = binfmt_copyargv(&argv, argv);
+
+#ifdef CONFIG_BINFMT_SCRIPT
+  kmm_free(scriptargv);

Review Comment:
   not good to call script specific code in the common code.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to