pkgsrc-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

pkg/53470: check_swap crashes if /proc/meminfo present on build system, missing on target



>Number:         53470
>Category:       pkg
>Synopsis:       check_swap crashes if /proc/meminfo present on build system, missing on target
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jul 24 17:10:00 +0000 2018
>Originator:     ef%math.uni-bonn.de@localhost
>Release:        pkgsrc-2017Q3
>Organization:
Mathematisches Institut der Uni Bonn
>Description:
	If net/nagios-plugins is built on a system with /proc mounted, the resulting check_swap plugin crashes if run on a system with /proc not mounted.
>How-To-Repeat:
	Build net/nagios-plugins on a system with /proc/meminfo present, run libexec/nagios/check_swap on a system with /proc/meminfo missing.
>Fix:
	The following (slightly gross) patch ensures that with HAVE_PROC_MEMINFO defined, but /proc/meminfo absent, the same code path as for HAVE_PROC_MEMINFO absent is executed.
	I'm afraid there's little point in trying to upstream this since Penguinists usually don't consider target systems differing from the build system.

	--- plugins/check_swap.c.orig	2018-07-24 17:10:34.000000000 +0200
	+++ plugins/check_swap.c	2018-07-24 17:13:25.000000000 +0200
	@@ -80,7 +80,7 @@ main (int argc, char **argv)
		char input_buffer[MAX_INPUT_BUFFER];
	 #ifdef HAVE_PROC_MEMINFO
		FILE *fp;
	-#else
	+#endif
		int conv_factor = SWAP_CONVERSION;
	 # ifdef HAVE_SWAP
		char *temp_buffer;
	@@ -99,7 +99,6 @@ main (int argc, char **argv)
	 #   endif /* CHECK_SWAP_SWAPCTL_SVR4 */
	 #  endif /* HAVE_DECL_SWAPCTL */
	 # endif
	-#endif
		char str[32];
		char *status;
	 
	@@ -116,10 +115,15 @@ main (int argc, char **argv)
			usage4 (_("Could not parse arguments"));
	 
	 #ifdef HAVE_PROC_MEMINFO
	+	fp = fopen (PROC_MEMINFO, "r");
		if (verbose >= 3) {
	-		printf("Reading PROC_MEMINFO at %s\n", PROC_MEMINFO);
	+		if (fp)
	+			printf("Reading PROC_MEMINFO at %s\n", PROC_MEMINFO);
	+		else
	+			printf("Can't open PROC_MEMINFO %s\n", PROC_MEMINFO);
		}
	-	fp = fopen (PROC_MEMINFO, "r");
	+	if (fp) {
	+	/*!>indent */
		while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, fp)) {
			if (sscanf (input_buffer, "%*[S]%*[w]%*[a]%*[p]%*[:] %lf %lf %lf", &dsktotal_mb, &dskused_mb, &dskfree_mb) == 3) {
				dsktotal_mb = dsktotal_mb / 1048576;	/* Apply conversion */
	@@ -156,7 +160,10 @@ main (int argc, char **argv)
		total_swap_mb = dsktotal_mb;
		used_swap_mb = dskused_mb;
		free_swap_mb = dskfree_mb;
	-#else
	+	goto read_meminfo;
	+	/*!<indent */
	+	}
	+#endif /* HAVE_PROC_MEMINFO */
	 # ifdef HAVE_SWAP
		xasprintf(&swap_command, "%s", SWAP_COMMAND);
		xasprintf(&swap_format, "%s", SWAP_FORMAT);
	@@ -350,7 +357,7 @@ main (int argc, char **argv)
	 #   endif /* CHECK_SWAP_SWAPCTL_BSD */
	 #  endif /* CHECK_SWAP_SWAPCTL_SVR4 */
	 # endif /* HAVE_SWAP */
	-#endif /* HAVE_PROC_MEMINFO */
	+read_meminfo:
	 
		/* if total_swap_mb == 0, swap is most likely missing or disabled and should go critical */
		if(total_swap_mb == 0) {



Home | Main Index | Thread Index | Old Index