NetBSD Problem Report #53278

From www@NetBSD.org  Fri May 11 15:47:15 2018
Return-Path: <www@NetBSD.org>
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 2BF907A159
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 11 May 2018 15:47:15 +0000 (UTC)
Message-Id: <20180511154713.DD2DD7A183@mollari.NetBSD.org>
Date: Fri, 11 May 2018 15:47:13 +0000 (UTC)
From: tr@vispaul.me
Reply-To: tr@vispaul.me
To: gnats-bugs@NetBSD.org
Subject: sysutils/salt 2018.3.0 immediately crashes
X-Send-Pr-Version: www-1.0

>Number:         53278
>Category:       pkg
>Synopsis:       sysutils/salt 2018.3.0 immediately crashes
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri May 11 15:50:00 +0000 2018
>Closed-Date:    Sat May 12 11:34:08 +0000 2018
>Last-Modified:  Wed Jun 20 11:55:01 +0000 2018
>Originator:     Travis Paul
>Release:        current
>Organization:
>Environment:
NetBSD n7.local 7.1.2 NetBSD 7.1.2 (GENERIC.201803151611Z) amd64
>Description:
Salt version 2018.3.0, in pkgsrc current does not work on NetBSD 7.1.2. The salt and salt-master commands crash immediately:

# salt
Traceback (most recent call last):
... [snip] ...
  File "/opt/pkg/lib/python2.7/site-packages/salt/grains/core.py", line 458, in _bsd_memdata
    grains['swap_total'] = int(swap_total) // 1024 // 1024
ValueError: invalid literal for int() with base 10: "sysctl: second level name 'swap_total' in 'vm.swap_total' is invalid"

These commands attempt to get the available swap space but crash due to not having a special case for NetBSD.  They try to get the value of a nonexistent "vm.swap_total" sysctl.

Upstream has fixed this issue by checking for swap in the same way as OpenBSD[1]. However, this does not work if the system has no configured swap space and the commands still crash with:

# salt-master
Traceback (most recent call last):
... [snip] ...
  File "/opt/pkg/lib/python2.7/site-packages/salt/grains/core.py", line 458, in _bsd_memdata
    grains['swap_total'] = int(swap_total) // 1024 // 1024
ValueError: invalid literal for int() with base 10: 'swap'

The attached patch fixes both issues and has been approved upstream [2] but is not yet merged (at the time of writing.)

[1] https://github.com/saltstack/salt/blob/bd184a257f3488175b0626a170e93433ec77e79e/salt/grains/core.py#L460
[2] https://github.com/saltstack/salt/pull/47600
>How-To-Repeat:
Install salt 2018.3.0 from pkgsrc, attempt to run the either salt or salt-master command.
>Fix:
See patches below (created with cvs diff -Nu)
Also uploaded the patch file here: https://gist.github.com/travispaul/cf2f163b3889b3ff63f548ef3bf7c315:

Index: distinfo
===================================================================
RCS file: /cvsroot/pkgsrc/sysutils/salt/distinfo,v
retrieving revision 1.34
diff -u -r1.34 distinfo
--- distinfo    13 Apr 2018 07:58:22 -0000      1.34
+++ distinfo    11 May 2018 15:42:29 -0000
@@ -4,4 +4,5 @@
 RMD160 (salt-2018.3.0.tar.gz) = 54ea78736292c97367c4b34b586bce25b434ecce
 SHA512 (salt-2018.3.0.tar.gz) = 3d64a4d12d4ff7effe644b682b138d8f49fd00523e9cfe3e80bebff9c944a089fb41cbac92e63139633425f49c1eebeb99145290a0bdd1b4f306da86abe9b2e5
 Size (salt-2018.3.0.tar.gz) = 13448567 bytes
+SHA1 (patch-salt_grains_core.py) = 011772f5f82c57833b82f7825b1bac201e42d024
 SHA1 (patch-salt_version.py) = 1827dac3609a938fae38ee5dfd2a873c9723dfbd
Index: patches/patch-salt_grains_core.py
===================================================================
RCS file: patches/patch-salt_grains_core.py
diff -N patches/patch-salt_grains_core.py
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-salt_grains_core.py   11 May 2018 15:42:29 -0000
@@ -0,0 +1,25 @@
+$NetBSD$
+
+Prevent crash on NetBSD and OpenBSD when no swap is configured.
+https://github.com/saltstack/salt/pull/47600
+
+--- salt/grains/core.py.orig   2018-05-11 13:12:38.000000000 +0000
++++ salt/grains/core.py
+@@ -450,11 +450,13 @@ def _bsd_memdata(osdata):
+             mem = __salt__['cmd.run']('{0} -n hw.physmem64'.format(sysctl))
+         grains['mem_total'] = int(mem) // 1024 // 1024
+
+-        if osdata['kernel'] == 'OpenBSD':
++        if osdata['kernel'] in ['OpenBSD', 'NetBSD']:
+             swapctl = salt.utils.path.which('swapctl')
+-            swap_total = __salt__['cmd.run']('{0} -sk'.format(swapctl)).split(' ')[1]
+-        else:
+-            swap_total = __salt__['cmd.run']('{0} -n vm.swap_total'.format(sysctl))
++            swap_data = __salt__['cmd.run']('{0} -sk'.format(swapctl))
++            if swap_data == 'no swap devices configured':
++                swap_total = 0
++            else:
++                swap_total = swap_data.split(' ')[1]
+         grains['swap_total'] = int(swap_total) // 1024 // 1024
+     return grains
+

>Release-Note:

>Audit-Trail:
From: "Maya Rashish" <maya@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/53278 CVS commit: pkgsrc/sysutils/salt
Date: Sat, 12 May 2018 11:29:36 +0000

 Module Name:	pkgsrc
 Committed By:	maya
 Date:		Sat May 12 11:29:36 UTC 2018

 Modified Files:
 	pkgsrc/sysutils/salt: Makefile distinfo
 Added Files:
 	pkgsrc/sysutils/salt/patches: patch-salt_grains_core.py

 Log Message:
 salt: don't crash if no swap is configured
 (in a netbsd/openbsd specific code block)

 from Travis Paul in PR pkg/53278, also upstream pull #47600
 bump PKGREVISION


 To generate a diff of this commit:
 cvs rdiff -u -r1.59 -r1.60 pkgsrc/sysutils/salt/Makefile
 cvs rdiff -u -r1.34 -r1.35 pkgsrc/sysutils/salt/distinfo
 cvs rdiff -u -r0 -r1.3 pkgsrc/sysutils/salt/patches/patch-salt_grains_core.py

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: maya@NetBSD.org
State-Changed-When: Sat, 12 May 2018 11:34:08 +0000
State-Changed-Why:
Applied, thanks!
I looked at the pkgsrc-2018Q1 version, and it looks different enough that it'd need a different patch.


From: tr@vispaul.me
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: pkg/53278 (sysutils/salt 2018.3.0 immediately crashes)
Date: Sat, 12 May 2018 21:50:41 +0800

 On 2018-05-12 19:34, maya@NetBSD.org wrote:
 > I looked at the pkgsrc-2018Q1 version, and it looks different enough
 > that it'd need a different patch.

 Hi Maya,

 I should have also mentioned: I don't see this behavior in salt 2017.7.4 
 on 2018Q1. They seemed to have recently changed the way that swap and 
 memory are determined in the latest version.

 Thanks for looking at this and applying the patch, much appreciated!
 Travis

From: "Travis Paul" <tpaul@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/53278 CVS commit: pkgsrc/sysutils/salt
Date: Wed, 20 Jun 2018 11:50:56 +0000

 Module Name:	pkgsrc
 Committed By:	tpaul
 Date:		Wed Jun 20 11:50:56 UTC 2018

 Modified Files:
 	pkgsrc/sysutils/salt: Makefile distinfo
 Added Files:
 	pkgsrc/sysutils/salt/patches: patch-salt_grains_core.py
 	    patch-salt_modules_pkgin.py

 Log Message:
 salt: don't crash if no swap is configured, apply pkgin module fixes

 patches/patch-salt_grains_core.py:
 - Reapply patch in a NetBSD/OpenBSD specific code block after package update
   to 2018.3.1, from PR pkg/53278
 - upstream pull #47600

 patches/patch-salt_modules_pkgin.py:
 - Apply patch in pkgin specific code block from PR pkg/53344
 - upstream pull #47814

 bump PKGREVISION
 ok <leot>


 To generate a diff of this commit:
 cvs rdiff -u -r1.62 -r1.63 pkgsrc/sysutils/salt/Makefile
 cvs rdiff -u -r1.36 -r1.37 pkgsrc/sysutils/salt/distinfo
 cvs rdiff -u -r0 -r1.5 pkgsrc/sysutils/salt/patches/patch-salt_grains_core.py
 cvs rdiff -u -r0 -r1.1 \
     pkgsrc/sysutils/salt/patches/patch-salt_modules_pkgin.py

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.