[Pkg-wmaker-commits] [wmbattery] 58/241: * Sort devices returned by readdir in acpi, since the order can be random. Closes: #204721
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Mon Aug 24 23:37:31 UTC 2015
This is an automated email from the git hooks/post-receive script.
dtorrance-guest pushed a commit to branch master
in repository wmbattery.
commit 18532cde599927fae1d924f6927d483223fe25b6
Author: joey <joey at a4a2c43b-8ac3-0310-8836-e0e880c912e2>
Date: Wed Aug 13 15:44:12 2003 +0000
* Sort devices returned by readdir in acpi, since the order can be random.
Closes: #204721
---
acpi.c | 38 ++++++++++++++++++++++++++++----------
debian/changelog | 7 +++++++
2 files changed, 35 insertions(+), 10 deletions(-)
diff --git a/acpi.c b/acpi.c
index 1b36666..02e9af7 100644
--- a/acpi.c
+++ b/acpi.c
@@ -17,6 +17,7 @@
#include "acpi.h"
+#define PROC_ACPI "/proc/acpi"
#define ACPI_MAXITEM 8
int acpi_batt_count = 0;
@@ -141,6 +142,13 @@ int get_acpi_batt_capacity(int battery) {
return cap;
}
+/* Comparison function for qsort. */
+int _acpi_compare_strings (const void *a, const void *b) {
+ const char **pa = (const char **)a;
+ const char **pb = (const char **)b;
+ return strcasecmp((const char *)*pa, (const char *)*pb);
+}
+
/* Find something (batteries, ac adpaters, etc), and set up a string array
* to hold the paths to info and status files of the things found. Must be
* in /proc/acpi to call this. Returns the number of items found. */
@@ -148,28 +156,38 @@ int find_items (char *itemname, char infoarray[ACPI_MAXITEM][128],
char statusarray[ACPI_MAXITEM][128]) {
DIR *dir;
struct dirent *ent;
- int count = 0;
+ int num_devices=0;
+ int i;
+ char **devices = malloc(ACPI_MAXITEM * sizeof(char *));
dir = opendir(itemname);
if (dir == NULL)
return 0;
-
while ((ent = readdir(dir))) {
if (!strncmp(".", ent->d_name, 1) ||
!strncmp("..", ent->d_name, 2))
continue;
- sprintf(infoarray[count], "%s/%s/%s", itemname, ent->d_name,
+ devices[num_devices]=strdup(ent->d_name);
+ num_devices++;
+ if (num_devices >= ACPI_MAXITEM)
+ break;
+ }
+ closedir(dir);
+
+ /* Sort, since readdir can return in any order. /proc/does
+ * sometimes list BATT2 before BATT1. */
+ qsort(devices, num_devices, sizeof(char *), _acpi_compare_strings);
+
+ for (i = 0; i < num_devices; i++) {
+ sprintf(infoarray[i], "%s/%s/%s", itemname, devices[i],
acpi_labels[label_info]);
- sprintf(statusarray[count], "%s/%s/%s", itemname, ent->d_name,
+ sprintf(statusarray[i], "%s/%s/%s", itemname, devices[i],
acpi_labels[label_status]);
- count++;
- if (count > ACPI_MAXITEM)
- break;
+ free(devices[i]);
}
- closedir(dir);
- return count;
+ return num_devices;
}
/* Find batteries, return the number, and set acpi_batt_count to it as well. */
@@ -216,7 +234,7 @@ int acpi_supported (void) {
char *version;
int num;
- if (chdir("/proc/acpi") == -1) {
+ if (chdir(PROC_ACPI) == -1) {
return 0;
}
diff --git a/debian/changelog b/debian/changelog
index 62e0102..9e6bf7c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+wmbattery (2.18) unstable; urgency=low
+
+ * Sort devices returned by readdir in acpi, since the order can be random.
+ Closes: #204721
+
+ -- Joey Hess <joeyh at debian.org> Wed, 13 Aug 2003 01:45:55 -0400
+
wmbattery (2.17) unstable; urgency=low
* Make acpi code put -1 in the time remaining field if the "present rate"
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmbattery.git
More information about the Pkg-wmaker-commits
mailing list