Revision: 77114
          http://sourceforge.net/p/brlcad/code/77114
Author:   starseeker
Date:     2020-09-13 00:27:23 +0000 (Sun, 13 Sep 2020)
Log Message:
-----------
Do the working directory check for Archer and MGED as well.

Modified Paths:
--------------
    brlcad/branches/RELEASE/src/archer/archer.c
    brlcad/branches/RELEASE/src/mged/mged.c

Modified: brlcad/branches/RELEASE/src/archer/archer.c
===================================================================
--- brlcad/branches/RELEASE/src/archer/archer.c 2020-09-13 00:09:36 UTC (rev 
77113)
+++ brlcad/branches/RELEASE/src/archer/archer.c 2020-09-13 00:27:23 UTC (rev 
77114)
@@ -26,6 +26,10 @@
 #include "bnetwork.h"
 #include "bio.h"
 
+#ifdef HAVE_WINDOWS_H
+#  include <direct.h> /* For chdir */
+#endif
+
 #include "tcl.h"
 #ifdef HAVE_TK
 #  include "tk.h"
@@ -95,6 +99,19 @@
     }
     bu_vls_free(&tlog);
 
+    /* If the working directory is BU_DIR_BIN, try shifting to the user's
+     * home directory instead */
+    char cwd[MAXPATHLEN] = {0};
+    char bindir[MAXPATHLEN] = {0};
+    bu_dir(cwd, MAXPATHLEN, BU_DIR_CURR, NULL);
+    bu_dir(bindir, MAXPATHLEN, BU_DIR_BIN, NULL);
+    if (BU_STR_EQUAL(cwd, bindir)) {
+       bu_dir(cwd, MAXPATHLEN, BU_DIR_HOME, NULL);
+       if (chdir(cwd)) {
+           bu_exit(EXIT_FAILURE, "Working directory is the binary directory 
\"%s\" (read-only), and chdir to home directory \"%s\" failed.", bindir, cwd);
+       }
+    }
+
     archer_tcl = bu_brlcad_root("share/tclscripts/archer/archer_launch.tcl", 
1);
     Tcl_DStringInit(&temp);
     fullname = Tcl_TranslateFileName(interp, archer_tcl, &temp);

Modified: brlcad/branches/RELEASE/src/mged/mged.c
===================================================================
--- brlcad/branches/RELEASE/src/mged/mged.c     2020-09-13 00:09:36 UTC (rev 
77113)
+++ brlcad/branches/RELEASE/src/mged/mged.c     2020-09-13 00:27:23 UTC (rev 
77114)
@@ -49,6 +49,10 @@
 #  include <poll.h>
 #endif
 
+#ifdef HAVE_WINDOWS_H
+#  include <direct.h> /* For chdir */
+#endif
+
 #include "bio.h"
 #include "bsocket.h"
 
@@ -1047,6 +1051,21 @@
 
     bu_setprogname(argv[0]);
 
+
+    /* If the working directory is BU_DIR_BIN, try shifting to the user's
+     * home directory instead */
+    char cwd[MAXPATHLEN] = {0};
+    char bindir[MAXPATHLEN] = {0};
+    bu_dir(cwd, MAXPATHLEN, BU_DIR_CURR, NULL);
+    bu_dir(bindir, MAXPATHLEN, BU_DIR_BIN, NULL);
+    if (BU_STR_EQUAL(cwd, bindir)) {
+       bu_dir(cwd, MAXPATHLEN, BU_DIR_HOME, NULL);
+       if (chdir(cwd)) {
+           bu_exit(EXIT_FAILURE, "Working directory is the binary directory 
\"%s\" (read-only), and chdir to home directory \"%s\" failed.", bindir, cwd);
+       }
+    }
+
+
     /* If multiple processors might be used, initialize for it.
      * Do not run any commands before here.
      * Do not use bu_log() or bu_malloc() before here.

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to