Add the directory name from the arguments cgminer was called from as well to allow it running from a relative pathname.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
diff --git a/main.c b/main.c
index 355ab1b..b79e28d 100644
--- a/main.c
+++ b/main.c
@@ -31,6 +31,8 @@
#include <ccan/opt/opt.h>
#include <jansson.h>
#include <curl/curl.h>
+#include <libgen.h>
+
#include "compat.h"
#include "miner.h"
#include "findnonce.h"
@@ -225,6 +227,7 @@ bool opt_autofan;
bool opt_autoengine;
char *opt_kernel_path;
+char *cgminer_path;
#define QUIET (opt_quiet || opt_realquiet)
@@ -4950,8 +4953,11 @@ int main (int argc, char *argv[])
sigaction(SIGTERM, &handler, &termhandler);
sigaction(SIGINT, &handler, &inthandler);
- opt_kernel_path = malloc(PATH_MAX);
+ opt_kernel_path = alloca(PATH_MAX);
strcpy(opt_kernel_path, CGMINER_PREFIX);
+ cgminer_path = alloca(PATH_MAX);
+ strcpy(cgminer_path, dirname(argv[0]));
+ strcat(cgminer_path, "/");
// Hack to make cgminer silent when called recursively on WIN32
int skip_to_bench = 0;
@@ -5307,8 +5313,6 @@ int main (int argc, char *argv[])
char *buf;
applog(LOG_ERR, "The most common reason for this failure is cgminer being unable to read the kernel .cl files");
- applog(LOG_ERR, "You must either CD into the directory you are running cgminer from,");
- applog(LOG_ERR, "or run it from a 'make install'ed location. ");
applog(LOG_ERR, "Alternatively if it has failed on different GPUs, restarting might help.");
failmessage = true;
buf = curses_input("Press enter to continue");
@@ -5415,8 +5419,6 @@ int main (int argc, char *argv[])
free(block);
}
- free(opt_kernel_path);
-
curl_global_cleanup();
return 0;
diff --git a/miner.h b/miner.h
index 5618e12..113c36f 100644
--- a/miner.h
+++ b/miner.h
@@ -304,6 +304,7 @@ extern bool opt_debug;
extern bool opt_protocol;
extern bool opt_log_output;
extern char *opt_kernel_path;
+extern char *cgminer_path;
extern bool opt_autofan;
extern bool opt_autoengine;
diff --git a/ocl.c b/ocl.c
index 8dde384..ab6fdfb 100644
--- a/ocl.c
+++ b/ocl.c
@@ -39,9 +39,17 @@ char *file_contents(const char *filename, int *length)
strcpy(fullpath, opt_kernel_path);
strcat(fullpath, filename);
- f = fopen(filename, "rb");
- if (!f)
+ /* Try in the optional kernel path or installed prefix first */
+ f = fopen(fullpath, "rb");
+ if (!f) {
+ /* Then try from the path cgminer was called */
+ strcpy(fullpath, cgminer_path);
+ strcat(fullpath, filename);
f = fopen(fullpath, "rb");
+ }
+ /* Finally try opening it directly */
+ if (!f)
+ f = fopen(filename, "rb");
if (!f) {
applog(LOG_ERR, "Unable to open %s or %s for reading", filename, fullpath);