[ntp:questions] Re: Specifying command line parameters for ntpd running as a w2k service?

mayer at gis.net mayer at gis.net
Fri Jan 21 18:04:24 UTC 2005


Terje Mathisen wrote:
> Martin Burnicki wrote:
> > mayer at gis.net wrote:
> >
> >>No, there is no specific key you can set for a service to
automatically
> >>read and pass. The basic design of services assumes a
Windows-centric
> >>view where all keys can be read directly out of the registry and it
> >>doesn't need to pass any command line options. Getting around this
> >>problem is a chore.
> >
> >
> > I'm currently looking at how this could be implemented the best
way.
> >
> > Assuming we already have added a Windows registry key which
contains a
> > string of command line parameters, e.g. "-g -L" OR "-gL".
> >
> > Normally if ntpd starts as service it would read the registry key
and
> > evaluate the contents of the registry key string.
> >
> > However, ntpd can also be run from a command line. Depending on the
actual
> > command line parameters, it can stay in the foreground, or start
itself as
> > service.
> >

You already know whether or not it is being run interactively
or the service since it comes in at NTmain in ntservice.c or
through main in ntpd.c if running as a service. You can therefore
set flags and values appropriately to do the rigt thing.

> > What would be the preferred behaviour in this case:
> >
> > - get the arguments from the command line, and read the parameters
from the
> > registry only if does not stay in the foreground
> >
> > - always get arguments from the registry, then from the command
line, which
> > made it possible to override arguments from the registry
> >
> > - anything else
>

An interactive session should always take it's arguments
from the command line if run interactively and from the registry
key if running as a service.

> My suggestion would be for the ntpd program to default to reading the

> registry key, unless at least one paramter is given. In that case use

> only the parameters specified on the command line.
>
> I.e.:
>
>    LPSTR cmd = GetCommandLine();
>    LPWSTR * pstr = CommandLineToArgV(cmd, &NrOfArgs);
>
>    if (NrOfArgs == 0) {
>       LONG res = RegQueryValue(... &buffer)
>       pstr = CommandLineToArgV(buffer, &NrOfArgs);
>    }
>    ... use parameters in pstr here!
>
That looks good.

Danny

> Terje
>
> --
> - <Terje.Mathisen at hda.hydro.com>
> "almost all programming can be viewed as an exercise in caching"




More information about the questions mailing list