From owner-freebsd-hackers Wed Jun 12 18:51:39 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from angryfist.fasttrackmonkey.com (angryfist.fasttrackmonkey.com [216.223.196.4]) by hub.freebsd.org (Postfix) with ESMTP id 8F58637B407 for ; Wed, 12 Jun 2002 18:51:32 -0700 (PDT) Received: (qmail 96070 invoked by uid 85); 13 Jun 2002 01:51:17 -0000 Received: from spork@fasttrackmonkey.com by angryfist.fasttrackmonkey.com by uid 1001 with qmail-scanner-1.10 (sophie: 2.9/3.56. . Clear:0. Processed in 0.063763 secs); 13 Jun 2002 01:51:17 -0000 X-Qmail-Scanner-Mail-From: spork@fasttrackmonkey.com via angryfist.fasttrackmonkey.com X-Qmail-Scanner: 1.10 (Clear:0. Processed in 0.063763 secs) Received: from unknown (HELO white.nat.fasttrackmonkey.com) (64.47.30.2) by 0 with DES-CBC3-SHA encrypted SMTP; 13 Jun 2002 01:51:17 -0000 Date: Wed, 12 Jun 2002 21:51:40 -0400 (EDT) From: Charles Sprickman To: "freebsd-hackers@freebsd.org" Subject: porting from linux Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hi, I'm trying to track down a problem in the netsaint-plugins plugin "check_snmp". It partially works, but if check_snmp is given more than one OID, it bombs out with a failure in "strscat". Apparently "strscat" comes from "utils.c" which is linked with "check_snmp.c". The error generally looks like this: bash-2.05a# /usr/local/libexec/netsaint/check_snmp -H localhost -C "" -o .1.3.6.1.4.1.2021.10.1.5.1,.1.3.6.1.4.1.2021.10.1.5.2,.1.3.6.1.4.1.2021.10.1.5.3 -w :1,:2,:3 -c :5,:10,:20 -l load check_snmp in free(): warning: chunk is already free check_snmp in realloc(): warning: chunk is already free failed malloc in strscat I'm guessing that since netsaint is developed on Linux, I'm running into some odd linux-ism. I did a send-pr on the port and contacted the port maintainer, but I thought maybe I'd find someone here who would like to tinker. The port of the netsaint-plugins is under /usr/ports/net. FWIW, here's the strscat function in utils.c: /****************************************************************************** * * Concatenates one string to the end of another * * Given a pointer destination string, which may or may not already * hold some text, and a source string with additional text (possibly * NULL or empty), returns a pointer to a string that is the first * string with the second concatenated to it. Uses realloc to free * memory held by the dest argument if new storage space is required. * * Example: * * char *str=NULL; * str = strscpy("This is a line of text with no trailing newline"); * str = strscat(str,"\n"); * *****************************************************************************/ char *strscat(char *dest, const char *src) { int len,l2; if (src) l2 = strlen (src); else return dest; if (dest) len = strlen (dest); else len = 0; dest = realloc (dest, len + l2 + 1); if (dest == NULL) terminate (STATE_UNKNOWN, "failed malloc in strscat\n"); strncpy (dest + len, src, l2); dest[len + l2] = 0; return dest; } And the call to strscat in check_snmp: while (fgets(input_buffer, MAX_INPUT_BUFFER - 1, child_process)) output = strscat(output, input_buffer); --- if (ptr && strstr(ptr, delimiter) == NULL) { response = strscat(response, ptr); ptr = NULL; --- I'm not a C person at all. I wish this had just been written in perl :) FWIW, I found some general porting guidelines on the net, but most of them in talking about free(), malloc(), and realloc() just mention that you shouldn't be including malloc.h, and this does not. Any help is appreciated. PR is: http://www.freebsd.org/cgi/query-pr.cgi?pr=39182 port maintainer is: blaz@si.FreeBSD.org Thanks for any help! Charles To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message