From a6b5007161eef4a366d551dcecb5c6bd4bfae19a Mon Sep 17 00:00:00 2001 From: Martin Alt Date: Thu, 20 Aug 2015 21:04:15 +0200 Subject: [PATCH] bugfix: fix service.enable for missing rc.conf The code assumed rc.conf to be existing and non-empty. Added a length check to ensure it works even if rc.conf is missing, such as in a newly created jail. --- salt/modules/freebsdservice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/modules/freebsdservice.py b/salt/modules/freebsdservice.py index 6a6855e15d..05a48354e5 100644 --- a/salt/modules/freebsdservice.py +++ b/salt/modules/freebsdservice.py @@ -162,7 +162,7 @@ def _switch(name, # pylint: disable=C0103 edited = True if not edited: # Ensure that the file ends in a \n - if nlines[-1][-1] != '\n': + if len(nlines) > 1 and nlines[-1][-1] != '\n': nlines[-1] = '{0}\n'.format(nlines[-1]) nlines.append('{0}="{1}"\n'.format(rcvar, val))