]> git.kaiwu.me - njs.git/commitdiff
Shell: passing original filename to parser.
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 28 Feb 2019 12:32:15 +0000 (15:32 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Thu, 28 Feb 2019 12:32:15 +0000 (15:32 +0300)
njs/njs_shell.c

index ea9f8cf1f89816cc87eb14d481e8ff11f36eea9d..e23bdfb9b4c8f1cce9b7afb5714dae0cd1f54e03 100644 (file)
@@ -14,6 +14,7 @@
 #include <fcntl.h>
 #include <stdlib.h>
 #include <sys/stat.h>
+#include <sys/param.h>
 #include <locale.h>
 
 #include <readline.h>
@@ -195,6 +196,7 @@ static njs_console_t  njs_console;
 int
 main(int argc, char **argv)
 {
+    char          path[MAXPATHLEN], *p;
     nxt_int_t     ret;
     njs_opts_t    opts;
     njs_vm_opt_t  vm_options;
@@ -215,14 +217,19 @@ main(int argc, char **argv)
     nxt_memzero(&vm_options, sizeof(njs_vm_opt_t));
 
     if (!opts.quiet) {
-        if (opts.file != NULL) {
-            vm_options.file.start = (u_char *) opts.file;
-            vm_options.file.length = strlen(opts.file);
-            nxt_file_basename(&vm_options.file, &vm_options.file);
+        if (opts.file == NULL) {
+            p = getcwd(path, sizeof(path));
+            if (p == NULL) {
+                fprintf(stderr, "getcwd() failed:%s\n", strerror(errno));
+                return EXIT_FAILURE;
+            }
 
-        } else {
-            vm_options.file = nxt_string_value("shell");
+            memcpy(path + strlen(path), "/shell", sizeof("/shell"));
+            opts.file = path;
         }
+
+        vm_options.file.start = (u_char *) opts.file;
+        vm_options.file.length = strlen(opts.file);
     }
 
     vm_options.init = !opts.interactive;