ports/143222: [UPDATE] sysutils/htop: improve some code from svn

Hung-Yi Chen gaod at hychen.org
Mon Jan 25 21:00:17 UTC 2010


>Number:         143222
>Category:       ports
>Synopsis:       [UPDATE] sysutils/htop: improve some code from svn
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jan 25 21:00:16 UTC 2010
>Closed-Date:
>Last-Modified:
>Originator:     Hung-Yi Chen
>Release:        FreeBSD 8.0-RELEASE-p2 i386
>Organization:
>Environment:
System: FreeBSD gaod.tfcis.org 8.0-RELEASE-p2 FreeBSD 8.0-RELEASE-p2 #3: Tue Jan 12 17:56:41 CST 2010 gaod at gaod.tfcis.org:/usr/obj/usr/src/sys/GENERIC i386

>Description:
	Simplify code, extra checks for lsof failures, coverity fixes.
	If there is no problem, I would take maintainership to provide further updates.
>How-To-Repeat:
>Fix:


--- htop begins here ---
===> Generating patch
===> Viewing diff with more
diff -ruN --exclude=CVS /usr/ports/sysutils/htop.orig/Makefile /usr/ports/sysutils/htop/Makefile
--- /usr/ports/sysutils/htop.orig/Makefile	2009-08-09 03:32:28.000000000 +0800
+++ /usr/ports/sysutils/htop/Makefile	2010-01-26 04:40:35.000000000 +0800
@@ -7,6 +7,7 @@
 
 PORTNAME=	htop
 PORTVERSION=	0.8.3
+PORTREVISION=	1
 CATEGORIES=	sysutils
 MASTER_SITES=	SF
 
diff -ruN --exclude=CVS /usr/ports/sysutils/htop.orig/files/patch-FunctionBar.c /usr/ports/sysutils/htop/files/patch-FunctionBar.c
--- /usr/ports/sysutils/htop.orig/files/patch-FunctionBar.c	1970-01-01 08:00:00.000000000 +0800
+++ /usr/ports/sysutils/htop/files/patch-FunctionBar.c	2010-01-26 03:52:06.000000000 +0800
@@ -0,0 +1,19 @@
+--- FunctionBar.c.orig	2010-01-26 03:50:57.000000000 +0800
++++ FunctionBar.c	2010-01-26 03:51:50.000000000 +0800
+@@ -52,14 +52,12 @@
+       this->functions = malloc(sizeof(char*) * 15);
+       this->keys = malloc(sizeof(char*) * 15);
+       this->events = malloc(sizeof(int) * 15);
+-      int i = 0;
+-      while (i < 15 && functions[i]) {
++      for (int i = 0; i < 15 && functions[i]; i++) {
+          this->functions[i] = String_copy(functions[i]);
+          this->keys[i] = String_copy(keys[i]);
+          this->events[i] = events[i];
+-         i++;
++         this->size = i;
+       }
+-      this->size = i;
+    } else {
+       this->staticData = true;
+       this->functions = functions ? functions : FunctionBar_FLabels;
diff -ruN --exclude=CVS /usr/ports/sysutils/htop.orig/files/patch-OpenFilesScreen.c /usr/ports/sysutils/htop/files/patch-OpenFilesScreen.c
--- /usr/ports/sysutils/htop.orig/files/patch-OpenFilesScreen.c	1970-01-01 08:00:00.000000000 +0800
+++ /usr/ports/sysutils/htop/files/patch-OpenFilesScreen.c	2010-01-26 03:56:35.000000000 +0800
@@ -0,0 +1,56 @@
+--- OpenFilesScreen.c.orig	2010-01-26 03:53:04.000000000 +0800
++++ OpenFilesScreen.c	2010-01-26 03:56:23.000000000 +0800
+@@ -26,7 +26,7 @@
+ typedef struct OpenFiles_ProcessData_ {
+    char* data[256];
+    struct OpenFiles_FileData_* files;
+-   bool failed;
++   int error;
+ } OpenFiles_ProcessData;
+ 
+ typedef struct OpenFiles_FileData_ {
+@@ -80,16 +80,18 @@
+    OpenFiles_ProcessData* process = calloc(sizeof(OpenFiles_ProcessData), 1);
+    OpenFiles_FileData* file = NULL;
+    OpenFiles_ProcessData* item = process;
+-   process->failed = true;
+    bool anyRead = false;
++
++   if (!fd) {
++      process->error = 127;
++      return process;
++   }
++
+    while (!feof(fd)) {
+       int cmd = fgetc(fd);
+-      if (cmd == EOF && !anyRead) {
+-         process->failed = true;
++      if (cmd == EOF && !anyRead)
+          break;
+-      }
+       anyRead = true;
+-      process->failed = false;
+       char* entry = malloc(1024);
+       if (!fgets(entry, 1024, fd)) break;
+       char* newline = strrchr(entry, '\n');
+@@ -106,7 +108,7 @@
+       }
+       item->data[cmd] = entry;
+    }
+-   pclose(fd);
++   process->error = pclose(fd);
+    return process;
+ }
+ 
+@@ -115,8 +117,10 @@
+    int index = MAX(Panel_getSelectedIndex(panel), 0);
+    Panel_prune(panel);
+    OpenFiles_ProcessData* process = OpenFilesScreen_getProcessData(this->process->pid);
+-   if (process->failed) {
++   if (process->error == 127) {
+       Panel_add(panel, (Object*) ListItem_new("Could not execute 'lsof'. Please make sure it is available in your $PATH.", 0));
++   } else if (process->error == 1) {
++      Panel_add(panel, (Object*) ListItem_new("Failed listing open files.", 0));
+    } else {
+       OpenFiles_FileData* file = process->files;
+       while (file) {
diff -ruN --exclude=CVS /usr/ports/sysutils/htop.orig/files/patch-OpenFilesScreen.h /usr/ports/sysutils/htop/files/patch-OpenFilesScreen.h
--- /usr/ports/sysutils/htop.orig/files/patch-OpenFilesScreen.h	1970-01-01 08:00:00.000000000 +0800
+++ /usr/ports/sysutils/htop/files/patch-OpenFilesScreen.h	2010-01-26 03:57:27.000000000 +0800
@@ -0,0 +1,11 @@
+--- OpenFilesScreen.h.orig	2010-01-26 03:57:03.000000000 +0800
++++ OpenFilesScreen.h	2010-01-26 03:57:19.000000000 +0800
+@@ -28,7 +28,7 @@
+ typedef struct OpenFiles_ProcessData_ {
+    char* data[256];
+    struct OpenFiles_FileData_* files;
+-   bool failed;
++   int error;
+ } OpenFiles_ProcessData;
+ 
+ typedef struct OpenFiles_FileData_ {
diff -ruN --exclude=CVS /usr/ports/sysutils/htop.orig/files/patch-ProcessList.c /usr/ports/sysutils/htop/files/patch-ProcessList.c
--- /usr/ports/sysutils/htop.orig/files/patch-ProcessList.c	1970-01-01 08:00:00.000000000 +0800
+++ /usr/ports/sysutils/htop/files/patch-ProcessList.c	2010-01-26 04:27:41.000000000 +0800
@@ -0,0 +1,20 @@
+--- ProcessList.c.orig	2010-01-26 03:58:10.000000000 +0800
++++ ProcessList.c	2010-01-26 04:22:58.000000000 +0800
+@@ -313,7 +313,7 @@
+    unsigned int pid = p->pid;
+    int index = Vector_indexOf(this->processes, p, Process_pidCompare);
+    assert(index != -1);
+-   Vector_remove(this->processes, index);
++   if (index >= 0) Vector_remove(this->processes, index);
+    assert(Hashtable_get(this->processTable, pid) == NULL); (void)pid;
+    assert(Hashtable_count(this->processTable) == Vector_count(this->processes));
+ }
+@@ -730,7 +730,7 @@
+ 
+ void ProcessList_scan(ProcessList* this) {
+    unsigned long long int usertime, nicetime, systemtime, systemalltime, idlealltime, idletime, totaltime;
+-   unsigned long long int swapFree;
++   unsigned long long int swapFree = 0;
+ 
+    FILE* status;
+    char buffer[128];
diff -ruN --exclude=CVS /usr/ports/sysutils/htop.orig/files/patch-UptimeMeter.c /usr/ports/sysutils/htop/files/patch-UptimeMeter.c
--- /usr/ports/sysutils/htop.orig/files/patch-UptimeMeter.c	1970-01-01 08:00:00.000000000 +0800
+++ /usr/ports/sysutils/htop/files/patch-UptimeMeter.c	2010-01-26 04:27:56.000000000 +0800
@@ -0,0 +1,11 @@
+--- UptimeMeter.c.orig	2010-01-26 04:26:23.000000000 +0800
++++ UptimeMeter.c	2010-01-26 04:27:01.000000000 +0800
+@@ -19,7 +19,7 @@
+ };
+ 
+ static void UptimeMeter_setValues(Meter* this, char* buffer, int len) {
+-   double uptime;
++   double uptime = 0;
+    FILE* fd = fopen(PROCDIR "/uptime", "r");
+    fscanf(fd, "%lf", &uptime);
+    fclose(fd);
===> Done
--- htop ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-ports-bugs mailing list