chiark / gitweb /
watershed, common: Break out m_[v]asprintf into common.c (nfc0
[chiark-utils.git] / cprogs / xbatmon-simple.c
index 62a7f258fbb6590ba7318eb786cb7c0cb7bfd7eb..5d64ff482b7f1223704db8b2bb79b13064291eb8 100644 (file)
@@ -326,6 +326,16 @@ ALL_VARS(V_NOTFOUND)
 ALL_DIRECT_VARS(V_PRINT)
   }
 
 ALL_DIRECT_VARS(V_PRINT)
   }
 
+  if (this_type == -1) {
+    /* some kernels don't seem to provide TYPE in the uevent
+     * guess the type from whether we see "present" or "online" */
+    if (this_online >= 0 && this_present == -1) this_type = TYPE_MAINS;
+    if (this_online == -1 && this_present >= 0) this_type = TYPE_BATTERY;
+    if (debug)
+      printf(" type absent from uevent %6s guessed %12s %"PRId64"\n",
+            "", "", this_type);
+  }
+
   int needsfields_MAINS   = this_type == TYPE_MAINS;
   int needsfields_BATTERY = this_type == TYPE_BATTERY;
   int needsfields_BOTH    = 1;
   int needsfields_MAINS   = this_type == TYPE_MAINS;
   int needsfields_BATTERY = this_type == TYPE_BATTERY;
   int needsfields_BOTH    = 1;
@@ -532,7 +542,7 @@ static const char *getresource(const char *want) {
   sprintf(class_buf,"Xacpi-Simple.%s",want);
   
   r= XrmGetResource(xrm, name_buf,class_buf, &rep_type_dummy, &val);
   sprintf(class_buf,"Xacpi-Simple.%s",want);
   
   r= XrmGetResource(xrm, name_buf,class_buf, &rep_type_dummy, &val);
-  if (!r) return val.addr;
+  if (r) return val.addr;
   
   return 0;
 }
   
   return 0;
 }