tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: rc.subr: Passing extra arguments to run_rc_command



On Fri, Mar 12, 2010 at 7:18 PM, Bernd Ernesti 
<netbsd%lists.veego.de@localhost> wrote:
> On Fri, Mar 12, 2010 at 05:53:42PM +0000, Julio Merino wrote:
>> Hello,
>>
>> [ Please CC me any replies ]
> [But not me, Bernd]

Turns out I'm still subscribed to the list, so don't bother with CCing me ;-)

>> The run_rc_command function from rc.subr(8) only allows giving it a
>> command name, and this command name cannot take any extra arguments.
>>
>> While writing an rc.d script for monotone, which provides a few
>> non-standard commands, I felt the need to pass extra arguments to my
>> custom commands.  To do so, I had to mess around with the original
>> argv, which is obviously not a nice approach.
>
> If you would give some example why that is needed.

In the rc.d script for monotone, I defined a custom command called
'genkey' that initializes a private key pair for the server, and
another command called 'read' that takes a file and passes it to
monotone.

The 'genkey' command deduces a name for the key pair, but the deduced
name may be incorrect (specially if you don't have a public domain
name).  Therefore, 'genkey' takes an extra argument which allows the
user to specify his own key name.  I thought about putting this as a
variable in rc.conf, but it doesn't make much sense: the value is only
required once while generating the key pair, and not during normal
operation.

Similarly, the 'read' command takes a file name as an argument, and
the contents of the file are passed to the server to import them into
the server database.

I'm also considering adding a 'run' command that passes commands
straight to the monotone server (e.g. "run db fsck"), and such command
would require extra arguments.

My current approach for this kinda works, but it's broken: it doesn't
not preserve whitespace (and other special characters) in the
arguments correctly, and the only way to do that is to modify rc.subr
to pass "${@}" around untouched.

>> Therefore, I'd like to modify run_rc_command to take a set of optional
>> extra arguments that will later be fed to the _precmd, _cmd and
>> _postcmd functions.  See the attached patch.
>>
>> Any objections or comments?
>
> That won't help you for the current supported NetBSD releases which do not
> support such a feature if this is going into the tree.

I know -- it won't help my external script immediately, but that
doesn't mean the feature cannot be implemented at all :-)  We can also
pull this up later on given that it's a pretty small change.

-- 
Julio Merino


Home | Main Index | Thread Index | Old Index