jclaar / zork

Full C++-20 port of the 616-point version of Zork from MIT circa 1978-1981
20 stars 10 forks source link

Zork crashes if not in current path #3

Closed TobiasKarnat closed 4 years ago

TobiasKarnat commented 4 years ago

Zork crashes if the executable is not in the current path:

$ which zork /usr/games/zork $ ls zork ls: cannot access 'zork': No such file or directory $ zork terminate called after throwing an instance of 'boost::process::process_error' what(): execve failed: No such file or directory

Patch for upstream version from Bitbucket

--- mdlfun.cpp  2019-12-28 22:40:39.384126978 +0000
+++ mdlfun.cpp  2019-12-28 23:04:55.587833908 +0000
@@ -9,6 +9,7 @@
 #pragma warning(disable: 4244)
 #include <boost/process.hpp>
 #pragma warning(default: 4244)
+#include <boost/dll.hpp>

 std::string pw(SIterator unm, SIterator key);
 std::string username();
@@ -54,7 +55,7 @@
        // exit.
        while (status == 1)
         {
-            boost::process::child c(argv[0], "-go");
+            boost::process::child c(boost::dll::program_location(), "-go");
             c.wait();
             status = c.exit_code();
         }

I also needed to add libboost_filesystem.a and -ldl for the link step in the makefile.

jclaar commented 4 years ago

Thanks for reporting this. I was unable to reproduce the issue...what distro are you using? In any case, your fix has been incorporated into a new release, since it works fine on all test platforms I tried.

TobiasKarnat commented 4 years ago

The binary was compiled on Ubuntu 18.04 with default libboost 1.65.1.0ubuntu1 (within a docker container), with following changes

CC=gcc-8 CFLAGS=--std=c++17 -Os -flto $(DEPFLAGS) BOOSTLIB=/usr/lib/x86_64-linux-gnu/libboost_serialization.a /usr/lib/x86_64-linux-gnu/libboost_system.a

And run on Ubuntu 16.04