Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sys.executablePath() returns /usr/bin/openfl on Linux #154

Closed
dukope opened this issue Dec 14, 2013 · 14 comments
Closed

Sys.executablePath() returns /usr/bin/openfl on Linux #154

dukope opened this issue Dec 14, 2013 · 14 comments

Comments

@dukope
Copy link

dukope commented Dec 14, 2013

OpenFL 1.2, Ubuntu 12.04, when running openfl test or openfl run, Sys.executablePath() returns:

/usr/bin/openfl

.. instead of the correct path to the built exe. Windows and Mac work ok. This might be a new issue with OpenFL 1.2 but enough stuff has changed in my code since 1.1 that I can't say for sure.

@DavisDevelopment
Copy link

Out of curiosity, what language are you attempting to compile it to?

@dukope
Copy link
Author

dukope commented Dec 15, 2013

native cpp

@DavisDevelopment
Copy link

Hmm.. Do you know any actual C++? If so, you could create an external C++ file for retrieving that information. Here's a link to how to get the info in C++:
http://stackoverflow.com/questions/143174/how-do-i-get-the-directory-that-a-program-is-running-from
Good luck.

@DavisDevelopment
Copy link

Also, have you tried just running the executable directly? I don't know much about the Ubuntu handles subprocesses, but your problem could be caused by the fact that the executable that initiated the subprocess that executed your program is located in that directory.

@dukope
Copy link
Author

dukope commented Dec 15, 2013

Running the exe directly works fine, as does running through openfl test/run on Windows & Mac. As far as I can tell, this is a problem exclusive to openfl test/run on Linux.

If I had to guess, you're probably right about the subprocess call. However openfl starts the exe on Linux for test/run is different from Mac & Windows. That's the bug I'm reporting here :)

@ruby0x1
Copy link
Contributor

ruby0x1 commented Dec 15, 2013

Judging by the code, it should setCwd when running the application, to the applications path.

If you try running
openfl test linux -v and check the output, you should see a line like this :

- Changing directory:
Right before
- Running command:

This is when it happens, or should.

@dukope
Copy link
Author

dukope commented Dec 15, 2013

The problem isn't with the current working directory, which is fine. The problem is with the function Sys.executablePath(), which returns the path to the openfl executable ("/usr/bin/openfl") when starting an application with openfl test linux or openfl run linux. The correct behavior is to return the path to your running executable, whether starting directly (works), or through openfl's shortcuts (doesn't work).

Checking hxlibc/Std.cpp, this looks like the Linux code for sys_exe_path:

const char *p = getenv("_");
if( p != NULL )
    return alloc_string(p);
{
    char path[PATH_MAX];
    int length = readlink("/proc/self/exe", path, sizeof(path));
    if( length < 0 )
        return alloc_null();
    path[length] = '\0';
    return alloc_string(path);
}

As DavisDevelopment suggests, depending on how the openfl run/test command starts the subprocess to run your application, this could pick up the openfl executable as /proc/self/exe. The code for the other platforms behaves correctly and always returns your true application path.

@ruby0x1
Copy link
Contributor

ruby0x1 commented Dec 15, 2013

Oh yea I misread,

(btw, test is just "build and run" , so really only run is the source of the call)

Looking at the code for the way it runs them from test / run - it uses Sys.command function (for all platforms). Though this seems to be a bug in the cpp side rather than the calling function, specific to linux (in hxlibc).

I will only have a gap later on to have a closer look, but figured I would leave more breadcrumbs while poking around there.

@dukope
Copy link
Author

dukope commented Dec 15, 2013

Cool, thanks Sven. This is super low priority for me, just wanted to post the issue here to give a heads up.

For anyone else running into this, the workaround is to check the result from Sys.executablePath(). If it contains "openfl", build the path yourself using Sys.getCwd() and your known app name. Because openfl does a setCwd before running, you're guaranteed to be in the same dir as the exe (on Linux/Windows anyways).

@jgranick
Copy link
Member

I personally have been frustrated by this problem. Could you help me understand the scenario?

Does it matter if you target Neko or C++? Does the application run properly if you execute it from the shell instead of running it through "lime test" or "lime run"?

Is this a problem specifically with running through the command-line tools, or does it occur elsewhere?

Thank you!

@DavisDevelopment
Copy link

From the way he talks, running directly, or through the command line, works just fine. It's when he used lime test or lime run that the problem manifested.

@dukope
Copy link
Author

dukope commented Jan 23, 2014

Yeah I don't have any additional info beyond what's up there. It returns the correct result when run by itself, the wrong result when run through lime test/run. I've only tried with the C++ target.

fwiw, this is my workaround code:

    exeDir = Path.addTrailingSlash(Path.directory(Sys.executablePath()));
    #if linux
    // @@ hack workaround for linux "lime test" bug
    if (Sys.executablePath().indexOf("lime") >= 0)
        exeDir = Path.addTrailingSlash(Sys.getCwd());
    #end

@jgranick
Copy link
Member

It's not perfect, but I've used this to improve (I think) the default behavior for OpenFL and the working directory:

openfl/openfl-native@0a995cc

It will first check if "lime.ndll" is present in the current working directory. If launched from the lime tools, it will set the CWD and this will be the case. Otherwise, it will set the working directory to the executable path. This still might not work properly if the application is launched from some types of launchers, but (hopefully) a launcher like that will at least set the CWD so it will work.

Let me know if you think is a good way to handle it, thanks!

@dukope
Copy link
Author

dukope commented Jan 24, 2014

That logic seems fine for setting the working directory.

_But this issue has nothing to do with the working directory. It's a problem with the value of Sys.executablePath() when starting an app through lime test/run, and only under Linux._

LeiChenIntel pushed a commit to LeiChenIntel/openfl that referenced this issue Nov 16, 2023
* initial doc structure change

* add utilities folder

* test image import

* fixes

* added architecture section

* restructure docs

* moving package structure to index

* ignore fix

* Restructure openfl section

* openfl docs restructuring

* introduced director-based workflow

* fix

* another fix

* Federation setup flow

* list fix

* added text

* added director start commands

* added envoy commands

* fox commands

* Small typo fixes

* Changed titels

* Added interactive API sections

* attempt to structure the new workflow

* attempts openfl#2

* restructuring

* attempt openfl#4

* director based workflow merged

* merging openfl#2

* fill director workflow

* director starting procedure

* envoy starting procedure described

* docs gitignore change

* Fixing the python API section

* a few typo fixes

* fixing python api docs

* interactive api section changes

* finished editing director workflow

* Finished text description

* rebased on develop

* resolving comments in pr

* plugins test

* small rewrite

* filled plugins section

* typo fixes for plugins

* added a link to a shard descriptor interface

* fix italic

* more fix italic

* moved and fixed data splitters
also restructured PKI and the old workflow

* fixes

* moved the old workflow to sources

* static diagram + fixes

* alexey's changes

* added a static diagram

* static diagram section
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants