NetBSD Problem Report #53470
From ef@math.uni-bonn.de Tue Jul 24 17:06:39 2018
Return-Path: <ef@math.uni-bonn.de>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 3B1487A1BA
for <gnats-bugs@gnats.NetBSD.org>; Tue, 24 Jul 2018 17:06:39 +0000 (UTC)
Message-Id: <20180724170635.893241BF1E@trave.math.uni-bonn.de>
Date: Tue, 24 Jul 2018 19:06:35 +0200 (CEST)
From: ef@math.uni-bonn.de
Reply-To: ef@math.uni-bonn.de
To: gnats-bugs@gnats.NetBSD.org
Subject: check_swap crashes if /proc/meminfo present on build system, missing on target
X-Send-Pr-Version: 3.95
>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
>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) {
(Contact us)
$NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.