From nobody@FreeBSD.org  Tue Dec 21 21:29:59 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 44DB11065670
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 21 Dec 2010 21:29:59 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (unknown [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 19D9C8FC0C
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 21 Dec 2010 21:29:59 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id oBLLTwVv076128
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 21 Dec 2010 21:29:58 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id oBLLTwdo076127;
	Tue, 21 Dec 2010 21:29:58 GMT
	(envelope-from nobody)
Message-Id: <201012212129.oBLLTwdo076127@red.freebsd.org>
Date: Tue, 21 Dec 2010 21:29:58 GMT
From: Damien Fleuriot <dam@c-mal.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] sabnzbd rc script fails to kill the process
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         153357
>Category:       ports
>Synopsis:       [patch] news/sabnzbdplus: rc script fails to kill the process
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    mandree
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Tue Dec 21 21:30:15 UTC 2010
>Closed-Date:    Thu Feb 24 20:18:54 UTC 2011
>Last-Modified:  Thu Feb 24 20:40:01 UTC 2011
>Originator:     Damien Fleuriot
>Release:        7.4
>Organization:
>Environment:
FreeBSD ks306450.kimsufi.com 7.4-PRERELEASE FreeBSD 7.4-PRERELEASE #2: Fri Dec 17 12:26:28 CET 2010     root@ks306450.kimsufi.com:/usr/obj/usr/src/sys/OVH  amd64
>Description:
The rc script for sabnzbd fails to stop the process.



See, I added a newsgroups host, which was added to sabnzbd.ini


The stop command in the rc.d script uses grep to find what host to send the stop command to (it uses the web interface to shutdown sabnzbd):
host=`grep -E '^host\ =\ [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' ${sabnzbd_conf_dir}/sabnzbd.ini | tr -dc '[0-9].'`


The problem is, now that I added a newsgroups host, grep matches it too.

Which gives me a $host variable with: "127.0.0.1" (interface sabnzbd binds to) AND again "yourdummyngprovider.com" (the newsgroups host) for a grand total of:
$host="127.0.0.1yourdummyngprovider.com"

In turn, the stop command then tries to curl to:
http://127.0.0.1yourdummyngprovider.com:8080/api?mode=shutdown&apikey=yourapikeyhere

This will never work.

>How-To-Repeat:
This problem is repeatable all the time.
>Fix:
I suggest changing the grep command from:
host=`grep -E '^host\ =\ [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' ${sabnzbd_conf_dir}/sabnzbd.ini | tr -dc '[0-9].'`
to
host=`grep -E -m1 '^host\ =\ [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' ${sabnzbd_conf_dir}/sabnzbd.ini | tr -dc '[0-9].'`

-m1 ensures grep stops after 1 match, which is what we want.


Notice this is already done to determine what port the sabnzbd daemon is listening on:
port=`grep -m1 ^port ${sabnzbd_conf_dir}/sabnzbd.ini | tr -dc '[0-9]'`

I have made this change to the rc script on my box and it works fine.


>Release-Note:
>Audit-Trail:

From: Dam <dam@c-mal.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/153357: [patch] news/sabnzbdplus: rc script fails to kill
 the process
Date: Thu, 24 Feb 2011 12:14:54 +0100

 Additional information:
 
 I forgot to say, the newsgroup host I added points to a local stunnel
 which in turn forwards requests to my actual newsgroups provider.
 
 Thus the host I added for newsgroups is 127.0.0.1:119 , and that is
 why the rc script's grep matches it, in addition to the host sabnzbd
 runs on.

From: Dam <dam@c-mal.com>
To: bug-followup@freebsd.org
Cc:  
Subject: Re: ports/153357: [patch] news/sabnzbdplus: rc script fails to kill
 the process
Date: Thu, 24 Feb 2011 12:43:59 +0100

 --0015174c0c3eb539d7049d05ba3c
 Content-Type: text/plain; charset=ISO-8859-1
 
 Patch attached, to be run against the rc script
 
 patch /usr/local/etc/rc.d/sabnzbd sabnzbd.patch
 
 --0015174c0c3eb539d7049d05ba3c
 Content-Type: application/octet-stream; name="sabnzbd.patch"
 Content-Disposition: attachment; filename="sabnzbd.patch"
 Content-Transfer-Encoding: base64
 X-Attachment-Id: f_gkjlsinb0
 
 LS0tIHNhYm56YmQub2xkIDIwMTEtMDItMjQgMTE6MzQ6MjUuMDAwMDAwMDAwICswMTAwCisrKyBz
 YWJuemJkICAgICAyMDExLTAyLTI0IDExOjM0OjM3LjAwMDAwMDAwMCArMDEwMApAQCAtNDYsNyAr
 NDYsNyBAQAogICAgIGVjaG8gIlN0b3BwaW5nICRuYW1lIgogICAgIGlmIFsgLWYgIiR7c2Fibnpi
 ZF9jb25mX2Rpcn0vc2FibnpiZC5pbmkiIF07IHRoZW4KICAgICAgICAgYXBpa2V5PWBncmVwIF5h
 cGlfa2V5ICR7c2FibnpiZF9jb25mX2Rpcn0vc2FibnpiZC5pbmkgfCB0ciAtZCAiIF8iYAotICAg
 ICAgICBob3N0PWBncmVwIC1FICdeaG9zdFwgPVwgWzAtOV17MSwzfVwuWzAtOV17MSwzfVwuWzAt
 OV17MSwzfVwuWzAtOV17MSwzfScgJHtzYWJuemJkX2NvbmZfZGlyfS9zYWJuemJkLmluaSB8IHRy
 IC1kYyAnWzAtOV0uJ2AKKyAgICAgICAgaG9zdD1gZ3JlcCAtbTEgLUUgJ15ob3N0XCA9XCBbMC05
 XXsxLDN9XC5bMC05XXsxLDN9XC5bMC05XXsxLDN9XC5bMC05XXsxLDN9JyAke3NhYm56YmRfY29u
 Zl9kaXJ9L3NhYm56YmQuaW5pIHwgdHIgLWRjICdbMC05XS4nYAogICAgICAgICBpZiBbICR7aG9z
 dH0gPSAiMC4wLjAuMCIgXSA7IHRoZW4gaG9zdD0ibG9jYWxob3N0IiA7IGZpCiAgICAgICAgIHBv
 cnQ9YGdyZXAgLW0xIF5wb3J0ICR7c2FibnpiZF9jb25mX2Rpcn0vc2FibnpiZC5pbmkgfCB0ciAt
 ZGMgJ1swLTldJ2AKICAgICAgICAgZmV0Y2ggLW8gL2Rldi9udWxsICJodHRwOi8vJHtob3N0fTok
 e3BvcnR9L2FwaT9tb2RlPXNodXRkb3duJiR7YXBpa2V5fSIgPiAvZGV2L251bGwgMj4mMQo=
 --0015174c0c3eb539d7049d05ba3c--
State-Changed-From-To: open->feedback 
State-Changed-By: mandree 
State-Changed-When: Thu Feb 24 12:06:06 UTC 2011 
State-Changed-Why:  
waiting for maintainer feedback (approval/disapproval) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=153357 

From: Matthias Andree <mandree@FreeBSD.org>
To: daniel@netwalk.org
Cc: bug-followup@FreeBSD.org
Subject: Re: ports/153357: [patch] news/sabnzbdplus: rc script fails to kill
 the process
Date: Thu, 24 Feb 2011 13:05:42 +0100

 Daniel,
 
 please check <http://www.freebsd.org/cgi/query-pr.cgi?pr=153357> and
 follow up with a message stating whether you approve of the proposed patch.
 
 Thank you.
 
 Best regards
 Matthias Andree
Responsible-Changed-From-To: freebsd-ports-bugs->mandree 
Responsible-Changed-By: mandree 
Responsible-Changed-When: Thu Feb 24 20:01:52 UTC 2011 
Responsible-Changed-Why:  
I'll take it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=153357 
State-Changed-From-To: feedback->closed 
State-Changed-By: mandree 
State-Changed-When: Thu Feb 24 20:18:53 UTC 2011 
State-Changed-Why:  
Committed. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=153357 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/153357: commit references a PR
Date: Thu, 24 Feb 2011 20:18:35 +0000 (UTC)

 mandree     2011-02-24 20:18:30 UTC
 
   FreeBSD ports repository
 
   Modified files:
     news/sabnzbdplus     Makefile 
     news/sabnzbdplus/files sabnzbd.in 
   Log:
   Only grep first host from .ini file in rcfile when shutting down.
   
   Submitted by: Damien Fleuriot <dam@c-mal.com>
   Approved by:  Daniel Bretoi <daniel@netwalk.org> (maintainer)
   PR:           ports/153357
   
   Revision  Changes    Path
   1.31      +1 -0      ports/news/sabnzbdplus/Makefile
   1.2       +1 -1      ports/news/sabnzbdplus/files/sabnzbd.in
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: Matthias Andree <mandree@FreeBSD.org>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Fwd: Re: ports/153357: [patch] news/sabnzbdplus: rc script fails
 to kill the process
Date: Thu, 24 Feb 2011 21:35:43 +0100

 -------- Original-Nachricht --------
 Betreff: 	Re: ports/153357: [patch] news/sabnzbdplus: rc script fails to
 kill the process
 Datum: 	Thu, 24 Feb 2011 08:02:01 -0800
 Von: 	Daniel <daniel@netwalk.org>
 An: 	Matthias Andree <mandree@freebsd.org>
 
 
 
 I approve
 
 On Thu, Feb 24, 2011 at 4:05 AM, Matthias Andree <mandree@freebsd.org
 <mailto:mandree@freebsd.org>> wrote:
 
      Daniel,
 
      please check <http://www.freebsd.org/cgi/query-pr.cgi?pr=153357> and
      follow up with a message stating whether you approve of the proposed
      patch.
 [...]
>Unformatted:
