6

I've run into a weird issue when installing SWI-Prolog using homebrew on my OSX 10.9 box. I'm trying to debug it to figure out whose bug it is (SWI-Prolog's, homebrew's, or OSX's), so I can report it appropriately and get it fixed.

The swipl in my path is /usr/local/bin/swipl which symlinks to /usr/local/Cellar/swi-prolog/6.2.3/bin/swipl which symlinks to /usr/local/Cellar/swi-prolog/6.2.3/lib/swipl-6.2.3/bin/x86_64-darwin13.0.0/swipl.

% which swipl
/usr/local/bin/swipl
% find /usr/local -name swipl -exec ls -l {} \;
lrwxr-xr-x  1 rampion  admin  36 Oct 23 20:54 /usr/local/bin/swipl -> ../Cellar/swi-prolog/6.2.3/bin/swipl
lrwxr-xr-x  1 rampion  admin  48 Oct 23 20:54 /usr/local/Cellar/swi-prolog/6.2.3/bin/swipl -> ../lib/swipl-6.2.3/bin/x86_64-darwin13.0.0/swipl
-r-xr-xr-x  1 rampion  admin  8760 Oct 23 20:54 /usr/local/Cellar/swi-prolog/6.2.3/lib/swipl-6.2.3/bin/x86_64-darwin13.0.0/swipl

I can run the actual executable in /usr/local/Cellar/swi-prolog/6.2.3/lib/swipl-6.2.3/bin/x86_64-darwin13.0.0/swipl:

% /usr/local/Cellar/swi-prolog/6.2.3/lib/swipl-6.2.3/bin/x86_64-darwin13.0.0/swipl
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 6.2.3)
...

And I can use the symlink at /usr/local/Cellar/swi-prolog/6.2.3/bin/swipl:

% /usr/local/Cellar/swi-prolog/6.2.3/bin/swipl
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 6.2.3)
...

But when I try to use the symlink at /usr/local/bin/swipl, which just symlinks to the other symlink, I get an error:

% /usr/local/bin/swipl
Abort trap: 6
% echo $?
134

I can also make my own symlinks to /usr/local/Cellar/swi-prolog/6.2.3/lib/swipl-6.2.3/bin/x86_64-darwin13.0.0/swipl, and they work:

% ln -s /usr/local/Cellar/swi-prolog/6.2.3/lib/swipl-6.2.3/bin/x86_64-darwin13.0.0/swipl swipl.0
% ./swipl.0 
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 6.2.3)
...

And my own symlinks to /usr/local/Cellar/swi-prolog/6.2.3/bin/swipl, and they fail:

% ln -s /usr/local/Cellar/swi-prolog/6.2.3/bin/swipl swipl.1
% ./swipl.1
Abort trap: 6
% echo $?
134

So I have no idea what's going wrong. Why would a symlink to a file work, but a symlink to a symlink to a file fail?

rampion
  • 1,589
  • 1
  • 10
  • 14
  • Related: http://stackoverflow.com/questions/19594148/swi-prolog-aborts-after-installation-via-homebrew –  Oct 29 '13 at 01:06
  • The latest version of swi-prolog in Homebrew is 6.4.1, can you try update to latest version to see if it works? Or you have to use version 6.2.3? I've tried swi-prolog 6.4.1 in OSX 10.8.5, your test cases all runs without issue. – number5 Oct 29 '13 at 01:55
  • I don't this has anything to do with versions, nor an issue with the links, it's probably that the script that's running just doesn't handle being called from multiple levels of indirection when called via symlinks. – slm Oct 29 '13 at 01:57
  • number1: trying now, but it looks like [others have encountered the same problem with 6.4.1](http://stackoverflow.com/questions/19594148/swi-prolog-aborts-after-installation-via-homebrew). – rampion Oct 29 '13 at 03:55
  • number1: Just installed SWI-prolog 6.4.1 on OSX 10.9 and the issue is the same, running the symlink to the symlink results in an abort. – rampion Oct 29 '13 at 04:04

2 Answers2

1

try do some example, your system supports chained symlinks, for example cd

ln -s /bin/ls myls1
ln -s myls1 myls2
ln -s myls2 myls3

start experiment:

./myls1 should work
./myls2 works or not?
./myls3 works or not?

When myls3 works, your system supports chained symlinks. I don't belive it doesn't :) Then I think problem is not with symlinks, but with SWI-Prolog. I thing it is trying resolve symlinks because he wans to know his phycical location. Usually it's needed for finding default libraries and other goods. In my opinion this can be bug in SWI-Prolog . Maybe it's repaired in higher version. Maybe you should report this bug. Maybe any fix is available.

Znik
  • 639
  • 1
  • 8
  • 15
0

I don't this has anything to do with versions, nor an issue with the links, it's probably that the script that's running just doesn't handle being called from multiple levels of indirection when called via symlinks.

Example

Say I have a setup like this of links to links to a file.

$ tree
.
|-- 1
|   |-- 2
|   |   |-- 3
|   |   |   |-- 4
|   |   |   |   `-- afile
|   |   |   `-- afile -> 4/afile
|   |   `-- afile -> 3/afile
|   `-- afile -> 2/afile
`-- afile -> 1/afile

So that there is a single file, 1/2/3/4/afile and all the afile's above are a chain of links to each other, which ultimately lead to the single afile file.

$ find . -ls
10890091    4 drwxrwxr-x   3 saml     saml         4096 Oct 28 22:03 .
10890244    0 lrwxrwxrwx   1 saml     saml            7 Oct 28 22:03 ./afile -> 1/afile
10890107    4 drwxrwxr-x   3 saml     saml         4096 Oct 28 22:02 ./1
10890247    0 lrwxrwxrwx   1 saml     saml            7 Oct 28 22:02 ./1/afile -> 2/afile
10890121    4 drwxrwxr-x   3 saml     saml         4096 Oct 28 22:02 ./1/2
10890246    0 lrwxrwxrwx   1 saml     saml            7 Oct 28 22:02 ./1/2/afile -> 3/afile
10890136    4 drwxrwxr-x   3 saml     saml         4096 Oct 28 22:02 ./1/2/3
10890245    0 lrwxrwxrwx   1 saml     saml            7 Oct 28 22:02 ./1/2/3/afile -> 4/afile
10890137    4 drwxrwxr-x   2 saml     saml         4096 Oct 28 22:06 ./1/2/3/4
10890243    4 -rw-rw-r--   1 saml     saml            5 Oct 28 22:06 ./1/2/3/4/afile

I can always access the file from any of the links above it, for example:

$ pwd
/home/saml/tst/97990/1
$ cat afile 
blah

I can use readlink to find out the canonical path the links pointing to:

$ readlink -f afile 
/home/saml/tst/97990/1/2/3/4/afile
slm
  • 363,520
  • 117
  • 767
  • 871
  • I would suspect this as well, if it couldn't handle a single layer of indirection (that is, if a symlink to the executable didn't work). I'm unclear on what the executable could be using to resolve a single layer of indirection that made it unable to handle multiple, though. – rampion Oct 29 '13 at 03:50
  • 1
    @rampion - probably some homegrown logic that's flawed. – slm Oct 29 '13 at 03:56
  • Another point against this theory is that the multiple layers of indirection is no problem on [10.8.5 according to number1](http://unix.stackexchange.com/questions/97990/why-wouldnt-a-symlink-to-a-symlink-work#comment149068_97990). So if the homegrown logic is flawed, it's flawed in an unstable manner (respective to the operating system). – rampion Oct 29 '13 at 04:09
  • @rampion - so what's your theory? Some versions work on some versions of OSX while others don't? And that it has something to do with the symlinking? BTW, what type of file is `swipl`? If it's a shell script run it like this, `bash -x swipl` and see what it's doing. – slm Oct 29 '13 at 04:22
  • slm: it's a binary file. My current theory is either 1) swi-prolog was using an unsupported API in 10.8 for resolution that got changed in 10.9 (so, your theory) or 2) Apple broke an API when moving from 10.8 to 10.9. – rampion Oct 29 '13 at 04:41