From owner-freebsd-rc@FreeBSD.ORG Mon Dec 17 21:58:33 2012 Return-Path: Delivered-To: freebsd-rc@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 8CD986A0 for ; Mon, 17 Dec 2012 21:58:33 +0000 (UTC) (envelope-from prvs=691a0532e=pschmehl_lists@tx.rr.com) Received: from ip-002.utdallas.edu (ip-002.utdallas.edu [129.110.20.108]) by mx1.freebsd.org (Postfix) with ESMTP id 464B58FC0A for ; Mon, 17 Dec 2012 21:58:33 +0000 (UTC) X-Group: None X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AikCACSUz1CBbgoggWdsb2JhbABFvj0OAQEWJieCHgEBAQMBAQI1Aj8FCwsOCi4oLwYTG4dmAwkGDLBRCYlZjF2DYmEDiGGKe4NKkj4 X-IronPort-AV: E=Sophos;i="4.84,304,1355119200"; d="scan'208";a="112926365" Received: from zxtm01.utdallas.edu (HELO utd71538.utdallas.edu) ([129.110.10.32]) by ip-002.utdallas.edu with ESMTP/TLS/DHE-RSA-AES256-SHA; 17 Dec 2012 15:58:31 -0600 Date: Mon, 17 Dec 2012 15:58:29 -0600 From: Paul Schmehl To: Ian Lepore Subject: Re: rc.subr questions - continued Message-ID: <8B926666D7562B144745B444@utd71538.campus.ad.utdallas.edu> In-Reply-To: <1355771964.1198.169.camel@revolution.hippie.lan> References: <8A328288ADDF512269BB31D5@utd71538.campus.ad.utdallas.edu> <1355764632.1198.162.camel@revolution.hippie.lan> <09612E06DF09112FB130CEC8@utd71538.campus.ad.utdallas.edu> <1355769038.1198.163.camel@revolution.hippie.lan> <9705ED9C5E7AB320208BEBAC@utd71538.campus.ad.utdallas.edu> <1355771964.1198.169.camel@revolution.hippie.lan> X-Mailer: Mulberry/4.1.0a1 (Mac OS X) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline; size=4773 Cc: freebsd-rc@freebsd.org X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Paul Schmehl List-Id: "Discussion related to /etc/rc.d design and implementation." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Dec 2012 21:58:33 -0000 --On December 17, 2012 12:19:24 PM -0700 Ian Lepore wrote: > On Mon, 2012-12-17 at 12:52 -0600, Paul Schmehl wrote: >> --On December 17, 2012 11:30:38 AM -0700 Ian Lepore >> wrote: >> >> > On Mon, 2012-12-17 at 11:43 -0600, Paul Schmehl wrote: >> >> --On December 17, 2012 10:17:12 AM -0700 Ian Lepore >> >> wrote: >> >> >> >> > On Mon, 2012-12-17 at 10:50 -0600, Paul Schmehl wrote: >> >> >> Since I maintain three ports (security/sguil-server, >> >> >> security/sguil-sensor and security/sguil-client) that have this >> >> >> problem, I decided to start with the server port. The current >> >> >> port version is 0.7.0 and the init script worked fine when I >> >> >> submitted the port a while ago. Here it is: >> >> > >> >> > I can't answer the part about why it used to work and now it >> >> > doesn't, but in general that doesn't look like a modern rc script >> >> > that starts and stops a daemon. >> >> > >> >> > Someone had a similar problem with a simple solution in the past... >> >> > >> >> > http://lists.freebsd.org/pipermail/freebsd-questions/2010-October/2 >> >> > 223 54. html >> >> > >> >> >> >> Unfortunately, that doesn't work for me. Here's the current script: >> >> >> >> . /etc/rc.subr >> >> >> >> name="sguild" >> >> load_rc_config ${name} >> >> # set some defaults >> >> sguild_enable=${sguild_enable:-"NO"} >> >> sguild_conf=${sguild_conf:-"/usr/local/etc/sguild/sguild.conf"} >> >> sguild_pid=${sguild_pid:-"/var/run/sguild/sguild.pid"} >> >> sguild_flags=${sguild_flags:-"-D -P ${sguild_pid}"} >> >> sguild_user=${sguild_user:-"sguil"} >> >> >> >> command="/usr/local/bin/${name}" >> >> command_args="-c ${sguild_conf} ${sguild_flags}" >> >> procname="/usr/local/bin/tclsh8.5" >> >> start_cmd="sguild_start" >> >> >> >> sguild_start(){ >> >> echo "starting sguild." >> >> /bin/sh ${command} ${command_args} >> >> } >> >> >> >> run_rc_command "$1" >> >> >> >> When I run start, I get this: >> >> >> >> # /usr/local/etc/rc.d/sguild start >> >> starting sguild. >> >> /usr/local/etc/rc.d/sguild: unknown directive '/usr/local/bin/sguild'. >> >> Usage: /usr/local/etc/rc.d/sguild >> >> [fast|force|one|quiet](start|stop|restart|rcvar|status|poll) >> >> >> >> Status and stop work fine. >> >> >> >> The "unknown directive is coming from line 913 in rc.subr: >> >> echo 1>&2 "$0: unknown directive '$rc_arg'." >> >> rc_usage $_keywords >> >> # not reached >> >> >> >> rc_arg is >> >> (fast|force|one|quiet)(start|stop|restart|rcvar|status|poll). >> >> >> >> This error: >> >> /usr/local/etc/rc.d/sguild: unknown directive '/usr/local/bin/sguild'. >> >> >> >> Seems to indicate that the rc.subr script thinks $0 is >> >> /usr/local/bin/sguild rather than /usr/local/etc/rc.d/sguild, which is >> >> odd to me. >> >> >> >> >> > >> > Does running with rc_debug=YES provide any extra clues? >> > >> >> Not really: >> >> # /usr/local/etc/rc.d/sguild start >> /usr/local/etc/rc.d/sguild: DEBUG: checkyesno: sguild_enable is set to >> YES. Starting sguild. >> /usr/local/etc/rc.d/sguild: DEBUG: run_rc_command: doit: su -m sguil -c >> 'sh -c "/usr/local/bin/sguild -D -P /var/run/sguild/sguild.pid "' >> /usr/local/etc/rc.d/sguild: unknown directive '/usr/local/bin/sguild'. >> Usage: /usr/local/etc/rc.d/sguild >> [fast|force|one|quiet](start|stop|restart|rcvar|status|poll) >> /usr/local/etc/rc.d/sguild: WARNING: failed to start sguild >> >> The key to the problem is the unknown directive error. For some reason >> rc.subr thinks the script it's trying to start is /usr/local/bin/sguild >> instead of /usr/local/etc/rc.d/sguild. >> >> I just can't figure out why it thinks that. >> > > Hmmm. A quick grep shows nothing germane in the source base saying > "unknown directive". That makes me think it's tcl saying that (but I > don't have it installed to test). In your /usr/local/bin/sguild script, > trying changing the "$0" "$@" to be just "$@" (just a guess, since the > contents of $0 seem to match exactly what's echoed after 'unknown > directive'). > I finally figure it out. I have to edit the program to change this: #!/bin/sh exec tclsh "$0" "$@" to this: #!/usr/local/bin/tcslsh8.5 Then everything works as expected. I'm sure now that the 'exec tclsh "$0" "$@"' line was confusing rc.subr. -- Paul Schmehl, Senior Infosec Analyst As if it wasn't already obvious, my opinions are my own and not those of my employer. ******************************************* "It is as useless to argue with those who have renounced the use of reason as to administer medication to the dead." Thomas Jefferson "There are some ideas so wrong that only a very intelligent person could believe in them." George Orwell