xiaoxiang781216 commented on code in PR #3859:
URL: https://github.com/apache/nuttx-apps/pull/3859#discussion_r4332170863


##########
interpreters/duktape/duk_cmdline.patch:
##########
@@ -2,17 +2,55 @@ diff --color -ur duktape/examples/cmdline/duk_cmdline.c 
duktape-2.5.0-modifed/ex
 --- duktape/examples/cmdline/duk_cmdline.c     2019-11-25 06:04:27.000000000 
+0800
 +++ duktape-2.5.0-modifed/examples/cmdline/duk_cmdline.c       2020-08-07 
23:20:27.320000000 +0800
 @@ -103,7 +103,7 @@
+ 
  #define  MEM_LIMIT_NORMAL   (128*1024*1024)   /* 128 MB */
  #define  MEM_LIMIT_HIGH     (2047*1024*1024)  /* ~2 GB */
 -#define  LINEBUF_SIZE       65536
 +#define  LINEBUF_SIZE       256
  
  static int main_argc = 0;
  static char **main_argv = NULL;
-
-@@ -810,10 +810,12 @@
+@@ -167,14 +167,28 @@ static void set_resource_limits(rlim_t m
+ #endif  /* DUK_CMDLINE_RLIMIT */
+ 
+ #if defined(DUK_CMDLINE_SIGNAL)
++#include <signal.h>
++
++static volatile sig_atomic_t g_interrupted = 0;
++
++duk_bool_t duk_cmdline_timeout_check(void *udata) {
++      (void) udata;
++      return g_interrupted;
++}
++
+ static void my_sighandler(int x) {
+-      fprintf(stderr, "Got signal %d\n", x);
+-      fflush(stderr);
++      (void) x;
++      g_interrupted = 1;
+ }
+ static void set_sigint_handler(void) {
+       (void) signal(SIGINT, my_sighandler);
+       (void) signal(SIGPIPE, SIG_IGN);  /* avoid SIGPIPE killing process */
+ }
++#else
++duk_bool_t duk_cmdline_timeout_check(void *udata) {
++      (void) udata;
++      return 0;
++}
+ #endif  /* DUK_CMDLINE_SIGNAL */
+ 
+ static void cmdline_fatal_handler(void *udata, const char *msg) {
+@@ -809,11 +823,19 @@ static int handle_interactive(duk_contex
+               fflush(stdout);
  
                for (;;) {
++#if defined(DUK_CMDLINE_SIGNAL)
++                      if (g_interrupted) {
++                              got_eof = 1;
++                              break;
++                      }
++#endif
                        int c = fgetc(stdin);
 +                      fputc(c, stdout);
 +                      fflush(stdout);

Review Comment:
   why add



##########
interpreters/duktape/duk_cmdline.patch:
##########
@@ -2,17 +2,55 @@ diff --color -ur duktape/examples/cmdline/duk_cmdline.c 
duktape-2.5.0-modifed/ex
 --- duktape/examples/cmdline/duk_cmdline.c     2019-11-25 06:04:27.000000000 
+0800
 +++ duktape-2.5.0-modifed/examples/cmdline/duk_cmdline.c       2020-08-07 
23:20:27.320000000 +0800
 @@ -103,7 +103,7 @@
+ 
  #define  MEM_LIMIT_NORMAL   (128*1024*1024)   /* 128 MB */
  #define  MEM_LIMIT_HIGH     (2047*1024*1024)  /* ~2 GB */
 -#define  LINEBUF_SIZE       65536
 +#define  LINEBUF_SIZE       256
  
  static int main_argc = 0;
  static char **main_argv = NULL;
-
-@@ -810,10 +810,12 @@
+@@ -167,14 +167,28 @@ static void set_resource_limits(rlim_t m
+ #endif  /* DUK_CMDLINE_RLIMIT */
+ 
+ #if defined(DUK_CMDLINE_SIGNAL)
++#include <signal.h>
++
++static volatile sig_atomic_t g_interrupted = 0;
++
++duk_bool_t duk_cmdline_timeout_check(void *udata) {
++      (void) udata;
++      return g_interrupted;
++}
++
+ static void my_sighandler(int x) {
+-      fprintf(stderr, "Got signal %d\n", x);
+-      fflush(stderr);
++      (void) x;
++      g_interrupted = 1;
+ }
+ static void set_sigint_handler(void) {
+       (void) signal(SIGINT, my_sighandler);
+       (void) signal(SIGPIPE, SIG_IGN);  /* avoid SIGPIPE killing process */
+ }
++#else
++duk_bool_t duk_cmdline_timeout_check(void *udata) {
++      (void) udata;
++      return 0;
++}
+ #endif  /* DUK_CMDLINE_SIGNAL */
+ 
+ static void cmdline_fatal_handler(void *udata, const char *msg) {
+@@ -809,11 +823,19 @@ static int handle_interactive(duk_contex
+               fflush(stdout);
  
                for (;;) {
++#if defined(DUK_CMDLINE_SIGNAL)
++                      if (g_interrupted) {

Review Comment:
   DUK_USE_EXEC_TIMEOUT_CHECK



##########
interpreters/duktape/duk_cmdline.patch:
##########
@@ -24,6 +62,29 @@ diff --color -ur duktape/examples/cmdline/duk_cmdline.c 
duktape-2.5.0-modifed/ex
                                break;
                        } else if (idx >= LINEBUF_SIZE) {
                                fprintf(stderr, "line too long\n");
+@@ -1268,6 +1290,9 @@ int main(int argc, char *argv[]) {
+ 
+       main_argc = argc;
+       main_argv = (char **) argv;
++#if defined(DUK_CMDLINE_SIGNAL)
++      g_interrupted = 0;
++#endif
+ 
+ #if defined(EMSCRIPTEN)
+       /* Try to use NODEFS to provide access to local files.  Mount the
+@@ -1509,6 +1534,12 @@ int main(int argc, char *argv[]) {
+               fflush(stderr);
+       }
+ 
++#if defined(DUK_CMDLINE_SIGNAL)
++      if (g_interrupted) {

Review Comment:
   DUK_USE_EXEC_TIMEOUT_CHECK



-- 
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