summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2010-02-22 20:54:01 +0000
committerHisham Muhammad <hisham@gobolinux.org>2010-02-22 20:54:01 +0000
commitc9e59b4a339522f01dcaa883989656f31534a124 (patch)
tree21ed005c70654fb1043c0f3a184b8120f09b726c
parent7dcd2beb90a560819bf634e6b7dbd50686c026d9 (diff)
minor tweaks by David Weber
-rw-r--r--BatteryMeter.c4
-rw-r--r--ProcessList.c17
-rw-r--r--Settings.c6
3 files changed, 9 insertions, 18 deletions
diff --git a/BatteryMeter.c b/BatteryMeter.c
index e9e9940f..c1ec9ec4 100644
--- a/BatteryMeter.c
+++ b/BatteryMeter.c
@@ -35,7 +35,7 @@ static unsigned long int parseUevent(FILE * file, char *key) {
while (fgets(line, sizeof line, file)) {
if (strncmp(line, key, strlen(key)) == 0) {
char *value;
- value = strtok(line, "=");
+ strtok(line, "=");
value = strtok(NULL, "=");
dValue = atoi(value);
break;
@@ -122,7 +122,6 @@ static ACPresence chkIsOnline() {
char *entryName;
if (!power_supplyDir) {
- closedir(power_supplyDir);
return AC_ERROR;
}
@@ -246,7 +245,6 @@ static double getSysBatData() {
if (!power_supplyDir) {
- closedir(power_supplyDir);
return 0;
}
diff --git a/ProcessList.c b/ProcessList.c
index dea1844e..3f6b7310 100644
--- a/ProcessList.c
+++ b/ProcessList.c
@@ -488,10 +488,7 @@ static void ProcessList_readIoFile(ProcessList* this, Process* proc, char* dirna
unsigned long long now = tv.tv_sec*1000+tv.tv_usec/1000;
unsigned long long last_read = proc->io_read_bytes;
unsigned long long last_write = proc->io_write_bytes;
- while (!feof(io)) {
- char* ok = fgets(buffer, 255, io);
- if (!ok)
- break;
+ while (fgets(buffer, 255, io)) {
if (ProcessList_read(this, buffer, "rchar: %llu", &proc->io_rchar)) continue;
if (ProcessList_read(this, buffer, "wchar: %llu", &proc->io_wchar)) continue;
if (ProcessList_read(this, buffer, "syscr: %llu", &proc->io_syscr)) continue;
@@ -520,6 +517,7 @@ static bool ProcessList_processEntries(ProcessList* this, char* dirname, Process
DIR* dir;
struct dirent* entry;
Process* prototype = this->prototype;
+ int parentPid = parent ? parent->pid : 0;
dir = opendir(dirname);
if (!dir) return false;
@@ -648,10 +646,7 @@ static bool ProcessList_processEntries(ProcessList* this, char* dirname, Process
else {
char buffer[256];
process->vxid = 0;
- while (!feof(status)) {
- char* ok = fgets(buffer, 255, status);
- if (!ok)
- break;
+ while (fgets(buffer, 255, status)) {
if (String_startsWith(buffer, "VxID:")) {
int vxid;
@@ -687,9 +682,10 @@ static bool ProcessList_processEntries(ProcessList* this, char* dirname, Process
command[i] = ' ';
command[amtRead] = '\0';
}
+ fclose(status);
+
command[PROCESS_COMM_LEN] = '\0';
process->comm = String_copy(command);
- fclose(status);
}
int percent_cpu = (process->utime + process->stime - lasttimes) /
@@ -737,8 +733,7 @@ void ProcessList_scan(ProcessList* this) {
status = ProcessList_fopen(this, PROCMEMINFOFILE, "r");
assert(status != NULL);
int processors = this->processorCount;
- while (!feof(status)) {
- fgets(buffer, 128, status);
+ while (fgets(buffer, 128, status)) {
switch (buffer[0]) {
case 'M':
diff --git a/Settings.c b/Settings.c
index f062986c..2d55afdb 100644
--- a/Settings.c
+++ b/Settings.c
@@ -63,12 +63,10 @@ static bool Settings_read(Settings* this, char* fileName) {
if (fd == NULL) {
return false;
}
- const int maxLine = 65535;
+ const int maxLine = 2048;
char buffer[maxLine];
bool readMeters = false;
- while (!feof(fd)) {
- buffer[0] = '\0';
- fgets(buffer, maxLine, fd);
+ while (fgets(buffer, maxLine, fd)) {
char** option = String_split(buffer, '=');
if (String_eq(option[0], "fields")) {
char* trim = String_trim(option[1]);

© 2014-2024 Faster IT GmbH | imprint | privacy policy