patch-jruby-launcher_unixlauncher_cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. $OpenBSD: patch-jruby-launcher_unixlauncher_cpp,v 1.4 2015/07/26 04:40:16 jeremy Exp $
  2. Attempt to replicate the following shell code:
  3. JAVA_HOME=$(javaPathHelper -h jruby)
  4. Without this, if the JAVA_HOME environment variable is not
  5. defined, bin/jruby will segfault when run.
  6. --- jruby-launcher/unixlauncher.cpp.orig Wed Dec 31 16:00:00 1969
  7. +++ jruby-launcher/unixlauncher.cpp Mon May 21 14:43:20 2012
  8. @@ -1,5 +1,6 @@
  9. #include <stdlib.h>
  10. #include <unistd.h>
  11. +#include <string.h>
  12. #include "unixlauncher.h"
  13. #include "utilsfuncs.h"
  14. @@ -45,6 +46,44 @@ int UnixLauncher::run(int argc, char* argv[], char* en
  15. prepareOptions();
  16. string java("");
  17. +
  18. + if (getenv("JAVA_HOME") == NULL) {
  19. + char *path;
  20. + FILE *java_home_pipe;
  21. + char java_home_path[256];
  22. +
  23. + path = getenv("PATH");
  24. + if (path == NULL || strlen(path) == 0) {
  25. + setenv("PATH", "/usr/bin:${LOCALBASE}/bin:${JAVA_HOME}/bin", 1);
  26. + } else {
  27. + char *paths[3] = {(char *)"/usr/bin", (char *)"${LOCALBASE}/bin", (char *)"${JAVA_HOME}/bin"};
  28. + int modified = 0;
  29. + int i;
  30. +
  31. + strlcpy(java_home_path, path, sizeof(java_home_path));
  32. + for (i = 0; i < 3; i++) {
  33. + if (strstr(path, paths[i]) == NULL) {
  34. + modified = 1;
  35. + strlcat(java_home_path, ":", sizeof(java_home_path));
  36. + strlcat(java_home_path, paths[i], sizeof(java_home_path));
  37. + }
  38. + }
  39. +
  40. + if (modified == 1) {
  41. + setenv("PATH", java_home_path, 1);
  42. + }
  43. + }
  44. +
  45. + if(java_home_pipe = popen("javaPathHelper -h jruby", "r")) {
  46. + size_t bytes_read;
  47. + bytes_read = fread(java_home_path, 1, 255, java_home_pipe);
  48. + if (bytes_read > 0) {
  49. + java_home_path[bytes_read-1] = '\0';
  50. + setenv("JAVA_HOME", java_home_path, 1);
  51. + }
  52. + pclose(java_home_pipe);
  53. + }
  54. + }
  55. if (getenv("JAVACMD") != NULL) {
  56. java = getenv("JAVACMD");