Fix https://github.com/hashcat/oclHashcat/issues/374
authorjsteube <jens.steube@gmail.com>
Sun, 19 Jun 2016 08:08:55 +0000 (10:08 +0200)
committerjsteube <jens.steube@gmail.com>
Sun, 19 Jun 2016 08:08:55 +0000 (10:08 +0200)
Fix https://github.com/hashcat/oclHashcat/issues/375

include/shared.h
src/ext_xnvctrl.c
src/shared.c

index 7af0aa3..a3cbc56 100644 (file)
@@ -72,6 +72,20 @@ static inline int  CPU_ISSET (int num, cpu_set_t *cs) { return (cs->count & (1 <
 #define hc_dlsym dlsym
 #endif
 
+#define HC_LOAD_FUNC2(ptr,name,type,var,libname,noerr) \
+  ptr->name = (type) hc_dlsym (ptr->var, #name); \
+  if (noerr != -1) { \
+    if (!ptr->name) { \
+      if (noerr == 1) { \
+        log_error ("ERROR: %s is missing from %s shared library.", #name, #libname); \
+        exit (-1); \
+      } else { \
+        log_info ("WARNING: %s is missing from %s shared library.", #name, #libname); \
+        return (-1); \
+      } \
+    } \
+  }
+
 #define HC_LOAD_FUNC(ptr,name,type,libname,noerr) \
   ptr->name = (type) hc_dlsym (ptr->lib, #name); \
   if (noerr != -1) { \
index 78ffab6..a1e6789 100644 (file)
@@ -22,7 +22,9 @@ int xnvctrl_init (XNVCTRL_PTR *xnvctrl)
 
   if (xnvctrl->lib_x11 == NULL)
   {
-    if (data.quiet == 0) log_info ("WARNING: load X11 library failed, proceed without X11 HWMon enabled.");
+    if (data.quiet == 0) log_info ("WARNING: Failed loading the X11 library: %s", dlerror());
+    if (data.quiet == 0) log_info ("         Please install libx11-dev package.");
+    if (data.quiet == 0) log_info ("");
 
     return -1;
   }
@@ -31,26 +33,21 @@ int xnvctrl_init (XNVCTRL_PTR *xnvctrl)
 
   if (xnvctrl->lib_xnvctrl == NULL)
   {
-    xnvctrl->lib_xnvctrl = dlopen ("libXNVCtrl.so.0", RTLD_LAZY);
+    if (data.quiet == 0) log_info ("WARNING: Failed loading the XNVCTRL library: %s", dlerror());
+    if (data.quiet == 0) log_info ("         Please install libxnvctrl-dev package.");
+    if (data.quiet == 0) log_info ("");
 
-    if (xnvctrl->lib_xnvctrl == NULL)
-    {
-      if (data.quiet == 0) log_info ("WARNING: load XNVCTRL library failed, proceed without XNVCTRL HWMon enabled.");
-
-      return -1;
-    }
+    return -1;
   }
 
-  xnvctrl->XOpenDisplay  = dlsym (xnvctrl->lib_x11, "XOpenDisplay");
-  xnvctrl->XCloseDisplay = dlsym (xnvctrl->lib_x11, "XCloseDisplay");
+  HC_LOAD_FUNC2 (xnvctrl, XOpenDisplay,  XOPENDISPLAY,  lib_x11, X11, 0);
+  HC_LOAD_FUNC2 (xnvctrl, XCloseDisplay, XCLOSEDISPLAY, lib_x11, X11, 0);
 
-  xnvctrl->XNVCTRLQueryTargetAttribute = dlsym (xnvctrl->lib_xnvctrl, "XNVCTRLQueryTargetAttribute");
-  xnvctrl->XNVCTRLSetTargetAttribute   = dlsym (xnvctrl->lib_xnvctrl, "XNVCTRLSetTargetAttribute");
+  HC_LOAD_FUNC2 (xnvctrl, XNVCTRLQueryTargetAttribute, XNVCTRLQUERYTARGETATTRIBUTE, lib_xnvctrl, XNVCTRL, 0);
+  HC_LOAD_FUNC2 (xnvctrl, XNVCTRLSetTargetAttribute,   XNVCTRLSETTARGETATTRIBUTE,   lib_xnvctrl, XNVCTRL, 0);
 
   #endif
 
-  // not using HC_LOAD_FUNC() here, because we're using 2 libraries and therefore have 2 different variable names for them
-
   return 0;
 }
 
@@ -78,6 +75,10 @@ void xnvctrl_close (XNVCTRL_PTR *xnvctrl)
 
 int hm_XNVCTRL_XOpenDisplay (XNVCTRL_PTR *xnvctrl)
 {
+  if (xnvctrl == NULL) return -1;
+
+  if (xnvctrl->XOpenDisplay == NULL) return -1;
+
   void *dpy = xnvctrl->XOpenDisplay (NULL);
 
   if (dpy == NULL)
@@ -94,6 +95,10 @@ int hm_XNVCTRL_XOpenDisplay (XNVCTRL_PTR *xnvctrl)
 
 void hm_XNVCTRL_XCloseDisplay (XNVCTRL_PTR *xnvctrl)
 {
+  if (xnvctrl == NULL) return;
+
+  if (xnvctrl->XCloseDisplay == NULL) return;
+
   if (xnvctrl->dpy == NULL) return;
 
   xnvctrl->XCloseDisplay (xnvctrl->dpy);
@@ -101,6 +106,10 @@ void hm_XNVCTRL_XCloseDisplay (XNVCTRL_PTR *xnvctrl)
 
 int get_fan_control (XNVCTRL_PTR *xnvctrl, int gpu, int *val)
 {
+  if (xnvctrl == NULL) return -1;
+
+  if (xnvctrl->XNVCTRLQueryTargetAttribute == NULL) return -1;
+
   if (xnvctrl->dpy == NULL) return -1;
 
   int rc = xnvctrl->XNVCTRLQueryTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_GPU, gpu, 0, NV_CTRL_GPU_COOLER_MANUAL_CONTROL, val);
@@ -112,6 +121,10 @@ int get_fan_control (XNVCTRL_PTR *xnvctrl, int gpu, int *val)
 
 int set_fan_control (XNVCTRL_PTR *xnvctrl, int gpu, int val)
 {
+  if (xnvctrl == NULL) return -1;
+
+  if (xnvctrl->XNVCTRLSetTargetAttribute == NULL) return -1;
+
   if (xnvctrl->dpy == NULL) return -1;
 
   int cur;
@@ -133,6 +146,10 @@ int set_fan_control (XNVCTRL_PTR *xnvctrl, int gpu, int val)
 
 int get_core_threshold (XNVCTRL_PTR *xnvctrl, int gpu, int *val)
 {
+  if (xnvctrl == NULL) return -1;
+
+  if (xnvctrl->XNVCTRLQueryTargetAttribute == NULL) return -1;
+
   if (xnvctrl->dpy == NULL) return -1;
 
   int rc = xnvctrl->XNVCTRLQueryTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_GPU, gpu, 0, NV_CTRL_GPU_CORE_THRESHOLD, val);
@@ -144,6 +161,10 @@ int get_core_threshold (XNVCTRL_PTR *xnvctrl, int gpu, int *val)
 
 int get_fan_speed_current (XNVCTRL_PTR *xnvctrl, int gpu, int *val)
 {
+  if (xnvctrl == NULL) return -1;
+
+  if (xnvctrl->XNVCTRLQueryTargetAttribute == NULL) return -1;
+
   if (xnvctrl->dpy == NULL) return -1;
 
   int rc = xnvctrl->XNVCTRLQueryTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_COOLER, gpu, 0, NV_CTRL_THERMAL_COOLER_CURRENT_LEVEL, val);
@@ -155,6 +176,10 @@ int get_fan_speed_current (XNVCTRL_PTR *xnvctrl, int gpu, int *val)
 
 int get_fan_speed_target (XNVCTRL_PTR *xnvctrl, int gpu, int *val)
 {
+  if (xnvctrl == NULL) return -1;
+
+  if (xnvctrl->XNVCTRLQueryTargetAttribute == NULL) return -1;
+
   if (xnvctrl->dpy == NULL) return -1;
 
   int rc = xnvctrl->XNVCTRLQueryTargetAttribute (xnvctrl->dpy, NV_CTRL_TARGET_TYPE_COOLER, gpu, 0, NV_CTRL_THERMAL_COOLER_LEVEL, val);
@@ -166,6 +191,10 @@ int get_fan_speed_target (XNVCTRL_PTR *xnvctrl, int gpu, int *val)
 
 int set_fan_speed_target (XNVCTRL_PTR *xnvctrl, int gpu, int val)
 {
+  if (xnvctrl == NULL) return -1;
+
+  if (xnvctrl->XNVCTRLSetTargetAttribute == NULL) return -1;
+
   if (xnvctrl->dpy == NULL) return -1;
 
   int cur;
index b70c7a9..1516c0f 100644 (file)
@@ -4743,7 +4743,7 @@ int sort_by_dictstat (const void *s1, const void *s2)
   dictstat_t *d1 = (dictstat_t *) s1;
   dictstat_t *d2 = (dictstat_t *) s2;
 
-  #ifdef _POSIX
+  #ifdef _LINUX
   d2->stat.st_atim = d1->stat.st_atim;
   #else
   d2->stat.st_atime = d1->stat.st_atime;