Subject: pkg/17833: NOCOL bug fix & feature patch
To: None <gnats-bugs@gnats.netbsd.org>
From: None <mishka@terabyte.com.ua>
List: netbsd-bugs
Date: 08/04/2002 17:18:00
>Number: 17833
>Category: pkg
>Synopsis: Annoyed bug in Strcasestr() and new feature in portmon(8)
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: pkg-manager
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Sun Aug 04 07:19:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Mishka
>Release: NetBSD 1.5ZC
>Organization:
Terabyte ACS
>Environment:
System: NetBSD/i386 1.5ZC
>Description:
Greetings!
The some annoyed bug in NOCOL portmon falls to situation,
when portmon can't detect the correct response from remote
server, but response the same was exists. Such, portmon
lyng increases the severity status for some host. This
appears in Strcasestr() function in portmon.c file. Please
look to "How-To-Repeat" section for more info and to "Fix"
section for provided patch.
Also, the output from portmon user's variable is very logic,
but have not sence. It indicates the last request was
success (1) or fail (0). But there is also good viewing
by severity status. Such, I change the status by elapsed
time in seconds, which is much more informative. The
following table shows advantages of it:
---- portmon-confg starts ----
HOST 10 15 20 Response string
---- portmon-confg ends ----
resp time | severity | comment
----------+----------+-----------
9 | info | all right
0 | info | excelent!
0 | >=warning| port is unavailable
17 | >=warning| slow response time
5 | >=warning| server is not replies correctly - fault
The patch is porvided.
>How-To-Repeat:
The Strcasestr() bug displays very randomly and time to
time. You can see that bug with passing "PORT x y z
<RESPONSE>" line in etc/portmon-confg and then executing
multiple times "portmon -d -d -d" command for more verbose
debug info.
>Fix:
Unfortunatelly, I have not enough time for investigate that
problem, so I just returned to strstr(3) function. Please
use the following patch (please note it already contains
above-mentioned feature request in very first patch chunk):
--- portmon/portmon.c Thu Apr 6 22:32:26 2000
+++ portmon/portmon.c.new Sun Aug 4 15:48:56 2002
@@ -180,7 +180,7 @@
else
{
update_event(&v, harray[i]->status,
- /* value */ (u_long)(harray[i]->status),
+ /* value */ (u_long)(harray[i]->elapsedsecs),
harray[i]->testseverity) ;
lseek(fdout, -(off_t)sizeof(v), SEEK_CUR);
write(fdout, (char *)&v, sizeof(v));
@@ -619,56 +619,24 @@
}
/*
- * Our very own strstr() function. Does a case-insensitive match.
- * Finds the first occurrence of the substring 'needle' in the
- * string 'haystack'.
- * Returns
- * Ptr in 'haystack' to the begining of 'needle'
- * Ptr to 'haystack' if needle is empty
- * NULL if needle is not found.
- *
+ * There is case-insensetive hack for strstr() function.
+ * Please look to strstr(3).
+ * NOTE: this function changes both haystack and needle variables.
*/
static char *Strcasestr(haystack, needle)
char *haystack; /* string */
char *needle; /* string to find */
{
- char p, q;
- size_t needlelen;
+ int i;
- if (haystack == NULL)
- return NULL;
-
- if (needle == NULL || *needle == 0)
- return (char *)haystack;
-
- p = *needle++;
- needlelen = strlen(needle);
-
- for ( ; ; )
- {
- register char *s1, *s2;
- int n;
-
- do
- { /* match first character */
- if ((q = *haystack++) == 0)
- return (NULL);
- } while ( tolower(q) != tolower(p) );
+ for (i=0; haystack[i]; i++) {
+ haystack[i] = tolower(haystack[i]);
+ }
+ for (i=0; needle[i]; i++) {
+ needle[i] = tolower(needle[i]);
+ }
- s1 = haystack; s2 = needle; n = needlelen;
- do
- {
- if (tolower(*s1) != tolower(*s2++) || *s1 == 0) /* */
- break;
- ++s1;
- } while (--n != 0);
-
- if (n == 0 || *s1 == 0)
- break; /* found, break out of forever loop */
-
- } /* end for */
- haystack--;
- return ((char *)haystack);
+ return (strstr(haystack, needle));
} /* Strcasestr() */
/*+
--
Best regads,
Mishka.
>Release-Note:
>Audit-Trail:
>Unformatted: