Package: apachetop
Severity: normal
Tags: patch

   Hello. The attached patch adds support for more than 50 files.

-- System Information:
Debian Release: testing/unstable
  APT prefers unstable
  APT policy: (500, 'unstable'), (50, 'experimental')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.13-mm1
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
diff -puriN apachetop-0.12.5/src/apachetop.cc apachetop-0.12.5-new/src/apachetop.cc
--- apachetop-0.12.5/src/apachetop.cc	2005-10-12 17:03:04 +0200
+++ apachetop-0.12.5-new/src/apachetop.cc	2005-10-12 17:08:35 +0200
@@ -40,6 +40,7 @@ struct input *in;
 WINDOW *win;
 
 #if (POLLING_METHOD == USING_KQUEUE)
+struct kevent *ev;
 int kq;
 #elif (POLLING_METHOD == USING_FAM)
 /* master fd for talking to FAM */
@@ -58,7 +59,7 @@ int main(int argc, char *argv[])
 #if (POLLING_METHOD == USING_KQUEUE)
 	/* we have and are using kqueue */
 	struct timespec stv;
-	struct kevent *ev, *evptr;
+	struct kevent *evptr;
 #elif (POLLING_METHOD == USING_FAM)
 	/* we have and are using FAM */
 	int fam_fd;
@@ -107,8 +108,7 @@ int main(int argc, char *argv[])
 	cf.hostfilter = new Filter();
 	/* }}} */
 
-	/* support MAX_INPUT_FILES input files */
-	in = (struct input *)calloc(MAX_INPUT_FILES, sizeof(struct input));
+	in = NULL;
 
 #if (POLLING_METHOD == USING_KQUEUE) /* then create kqueue {{{ */
 	if ((kq = kqueue()) < 0)
@@ -118,7 +118,7 @@ int main(int argc, char *argv[])
 	}
 
 	/* space in ev for all inputs */
-	ev = (struct kevent *)calloc(MAX_INPUT_FILES, sizeof(struct kevent));
+	ev = NULL;
 /* }}} */
 #elif (POLLING_METHOD == USING_FAM) /* open FAM connection */
 	if (FAMOpen(&fc))
@@ -312,7 +312,7 @@ int main(int argc, char *argv[])
 		}
 
 		/* if we have any input files waiting to be opened, try to */
-		for (x = 0 ; x < MAX_INPUT_FILES ; ++x)
+		for (x = 0 ; x < cf.input_count ; ++x)
 		{
 			/* for each entry in input .. */
 			curfile = &in[x];
@@ -347,7 +347,7 @@ int main(int argc, char *argv[])
 #if (POLLING_METHOD == USING_KQUEUE) /* {{{ */
 		/* every 1/10th of a second */
 		stv.tv_sec = 0; stv.tv_nsec = 10000000;
-		x = kevent(kq, NULL, 0, ev, MAX_INPUT_FILES, &stv);
+		x = kevent(kq, NULL, 0, ev, cf.input_count, &stv);
 //		if (x == 0) continue; /* timeout, nothing happened */
 		if (x < 0) break; /* error */
 
@@ -407,7 +407,7 @@ int main(int argc, char *argv[])
 		select(NULL, NULL, NULL, NULL, &tv);
 
 		/* check every file */
-		for (x = 0 ; x < MAX_INPUT_FILES ; ++x)
+		for (x = 0 ; x < cf.input_count ; ++x)
 		{
 			curfile = &in[x];
 			fd = curfile->fd;
@@ -504,7 +504,7 @@ int main(int argc, char *argv[])
 			} /* while ((nl - buf) < buflen && nl) */
 		} /* for(evptr = ev ; evptr->filter ; evptr++) */
 		  /* while (FAMPending(&fc) == 1 && FAMNextEvent(&fc, &fe)) */
-		  /* for (i = 0 ; i < MAX_INPUT_FILES ; ++i) */
+		  /* for (i = 0 ; i < cf.input_count ; ++i) */
 
 		/* check for keypresses */
 		if ((ch = wgetch(win)) != ERR)
@@ -996,10 +996,16 @@ int new_file(char *filename, bool do_see
 
 	if (input_element == -1)
 	{
-		/* new open, make sure we have room in our arrays */
-		if (cf.input_count == MAX_INPUT_FILES)
+		/* Realloc structure */
+		in = (struct input *)realloc(in, (cf.input_count + 1) * sizeof(struct input));
+#if (POLLING_METHOD == USING_KQUEUE)
+		ev = (struct kevent *)realloc(ev, (cf.input_count + 1) * sizeof(struct kevent));
+		if (!ev || !in)
+#else
+		if (!in)
+#endif
 		{
-			DIE_N("Only 50 files are supported at the moment");
+			DIE_N("Could not allocate memory");
 		}
 
 		/* add it on at the end */
diff -puriN apachetop-0.12.5/src/apachetop.h apachetop-0.12.5-new/src/apachetop.h
--- apachetop-0.12.5/src/apachetop.h	2005-10-12 17:03:04 +0200
+++ apachetop-0.12.5-new/src/apachetop.h	2005-10-12 17:03:49 +0200
@@ -261,8 +261,6 @@ struct gstat {
 #define COLS_RESERVED 25
 #define LINES_RESERVED 7
 
-#define MAX_INPUT_FILES 50
-
 int recordstats(struct logbits l);
 
 int read_key(int ch);

Reply via email to