Falconindy, can you elaborate on your approach?
]]>ld.so.conf.d isn't Arch specific. I'm still very unconvinced you're doing it right; especially so if you say that other distributions are configuring java incorrectly.
Not being able to use OpenGL by default seems incorrectly setup, no? I mean, here on Arch it works out of the box so why not on other distributions? However, I have no knowledge on the matter. My client is based on another one that's written in Perl and that developer is my main contact for when I had questions. He seems to know his stuff (and he is in contact with the developers of RuneScape) so I thought he would probably be right. I asked him on Skype today when you mentioned /etc/ld.so.conf.d/ and here is his reply:
[16:28:57] HikariKnight: true but i decided to not mess with those because java hardlinks them (at least in java6)
plus with the LD_LIBRARY_PATH i have an universal way :P plus i can support custom javas :P
[16:29:54] Unia: universal way how?
[16:30:30] HikariKnight: 2 scenarios :P
[16:31:46] HikariKnight: 1. a linux distro decide to play king of the hill and fuck with standards (fedora loves to do this sometimes)
2. ld.conf.d is changed
3. works on solaris and bsd too
[16:31:49] HikariKnight: and ofcourse
[16:31:58] HikariKnight: we can use custom java for runescape itself
[16:32:28] HikariKnight: lets say that a user NEEDs to use oracle java however rs runs better with openjdk (or other way around)
[16:32:46] HikariKnight: so client is able to use a different java without screwing up the ld.conf ;)
However, I am very willing to change my current approach - could you explain a bit more about this ld.so.conf.d? It seems a better method of fixing this.
]]>Unia wrote:I need to feed Java the LD_LIBRARY_PATH to libjli.so
This really seems like something that needs to be fixed in /etc/ld.so.conf.d/ so that the library can be loaded via normal means...
I really think you're solving the wrong problem, but you haven't really explained enough about what the problem is.
On Arch Linux it works just fine, but I guess other distributions do not configure Java properly: when I start the game there, OpenGL can not be used (if it could be, it would be used by default by RuneScape, but it's not and when I change the setting, it crashes). Thus, to get OpenGL working on those distributions, I have to tell Java where to find the libraries.
]]>I need to feed Java the LD_LIBRARY_PATH to libjli.so
This really seems like something that needs to be fixed in /etc/ld.so.conf.d/ so that the library can be loaded via normal means...
I really think you're solving the wrong problem, but you haven't really explained enough about what the problem is.
]]>*strstr(libfile,"/jli/libjli.so") = '\0';
This truncates the string at the start of that substring.
This could cause problems though if something went wrong and there was no match, so I'd include the following check
char *endpoint = strstr(libflile,"/jli/libjli.so");
if (endpoint) {
endpoint = '\0';
// do something with libfile
}
else {
// error
}
But in looking back, what should this return? That removes most of the ldd output.
In order to get OpenGL working on other distributions, I have to feed Java the location of its libraries.
Running ldd gives me this:
libjli.so => /usr/lib/jvm/java-7-openjdk/jre/bin/../lib/amd64/jli/libjli.so (0x00007feabafc4000)
I need to feed that to Java like this:
LD_LIBRARY_PATH=/usr/lib/jvm/java-7-openjdk/jre/bin/../lib/amd64
So yea, I need to remove most of the output.
Regarding ditching all of what I have now, I tried that. On one of my Google results, they mentioned I could get ldd-like functionality by using this:
setenv("LD_TRACE_LOADED_OBJECTS", "yes", 1);
Problem is, the output still is the same so I'm still struggling with how to process that. I will take a look at your suggestions after work!
Thanks!
]]>ldd = popen(ldd_command,"r");
char line[MAX_LINE+1];
char libfile[MAX_LINE] = "";
while (fgets(line,MAX_LINE,ldd) && (sscanf(line," libjli.so => %s",libfile) != 1 ));
if (strlen(libfile) > 1) {
// do something with found libfile
}
pclose(ldd);
This assumes MAX_LINE has been suitable defined.
EDIT: oops, missed the sed command part, but that should be easy enough - I'll give you a shot at that and check back a bit later.
The double backslashes threw me for a bit - I forgot you were escaping for the passing to the shell. So all you are doing is removing the beginning of the string?
char *newlibfil = strstr(libfile,".so")+3;
But in looking back, what should this return? That removes most of the ldd output.
EDIT2: Actually, I'd just ditch the popen("ldd ...") all together and just do what ldd does: read from the binary header. ldd is very small to start with, and a lot of the code is checking to make sure it was actually passed a suitable parameter: http://src.gnu-darwin.org/src/usr.bin/ldd/ldd.c.html
]]>I'll report back!
]]>>>> re.search(r'libjli.so => (.*)/jli/libjli.so', ldd_output).group(1)
'/usr/lib/jvm/java-7-openjdk/jre/bin/../lib/amd64'
It's in Python, but the regular expressions themselves are pretty similar between implemtations, you just have to figure a right pattern. There is a regex implementation 'pcre' in core for Perl like syntax and regex.h for POSIX regexes, i'm sure there are more.
]]>Finally, I have implemented all the features I want in my RuneScape Client for Linux, so now it's time to tidy up the code and fix the present bugs.
The first issue I would like to tackle is the following:
In order to get OpenGL to work (on other distributions, on Arch we don't need a fix) I need to feed Java the LD_LIBRARY_PATH to libjli.so. In order to check where that file resides, I use ldd. Currently, I'm handling it like this:
ldd_command = g_strjoin(" ", "ldd", java_binary, "| awk '/libjli.so/ {print $3}' | sed 's/jli\\/libjli\\.so//'", NULL);
ldd_output = popen(ldd_command, "r");
if (ldd_output != NULL) {
fgets(opengl_fix, sizeof(opengl_fix), ldd_output);
pclose(ldd_output);
ld_library_path = g_strjoin("", "LD_LIBRARY_PATH=", opengl_fix, NULL);
} else {
g_fprintf(stderr, "Could not retrieve the path to libjli.so: Java will run without OpenGL implementation\n\n");
}
So, basically, to actually process the output I now reside on the shell. I could not find a way to process this natively in C. Do you know of one - or is this the best way to handle this?
Thanks in advance!
]]>