Re: No hrSWRunPath in HOST-RESOURCES-MIB
Kamil Kisiel <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <C5F7974F.8EF4%[email protected]> |
On 31/03/09 0:20 , "Dave Shield" <[email protected]> wrote: > 2009/3/30 Kamil Kisiel <[email protected]>: >> Right, so now that we know the symptoms, I guess the question is why does >> this only happen on the version of Net-SNMP that openSUSE ships? Despite >> using the same version number on my Gentoo machines, the hrSWRunPath works >> fine there for all processes. For the kernel level processes it just returns >> the process name. > > Try comparing the output of "cat /proc/2'/status" on the two systems. > Do you see similar output in both cases? > Or is the openSuSE version empty? > > Thomas' output has confirmed that it's the handling of the /proc/{pid}/status > file which is triggering this problem. Now we just need to come up with a > better long-term fix. I decided to dive in to the source code of hr_swrun.c and found the following: 728 #elif defined(linux) 729 sprintf(string, "/proc/%d/cmdline", pid); 730 if ((fp = fopen(string, "r")) == NULL) { 731 strcpy(string, "<exited>"); 732 *var_len = strlen(string); 733 return (u_char *) string; 734 } 735 if (fgets(buf, sizeof(buf) - 1, fp)) /* argv[0] '\0' argv[1] '\0' .... */ 736 strcpy(string, buf); 737 else { 738 /* 739 * swapped out - no cmdline 740 */ 741 fclose(fp); 742 sprintf(string, "/proc/%d/status", pid); 743 if ((fp = fopen(string, "r")) == NULL) 744 return NULL; 745 fgets(buf, sizeof(buf), fp); /* Name: process name */ 746 if ( cp == NULL ) { 747 fclose(fp); 748 return NULL; /* the process probably died */ 749 } 750 cp = strchr(buf, ':'); 751 if ( cp == NULL ) { 752 fclose(fp); 753 return NULL; /* the process file is malformed */ 754 } 755 ++cp; 756 while (isspace(*cp)) 757 ++cp; 758 strcpy(string, cp); 759 cp = strchr(string, '\n'); 760 if (cp) 761 *cp = 0; It seems to me there's an error at line 746. Why is it checking to see if "cp" (presumably "char pointer") is NULL after reading a line in to "buf"? Should it not be checking if "buf" is NULL instead at this point? I'm thinking that perhaps on the systems where this works properly "cp" may have been initialized by chance. It's used extensively in the preceding code for a whole bunch of string manipulations. Notice of Confidentiality: The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, re-transmission, dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error please contact the sender immediately by return electronic transmission and then immediately delete this transmission including all attachments without copying, distributing or disclosing the same. ------------------------------------------------------------------------------ _______________________________________________ Net-snmp-users mailing list [email protected] Please see the following page to unsubscribe or change other options: https://lists.sourceforge.net/lists/listinfo/net-snmp-users