Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/sys/windows/svc/mgr: Documentation of args argument to CreateService incorrect. #20440

Closed
helloPiers opened this issue May 20, 2017 · 5 comments

Comments

@helloPiers
Copy link
Contributor

@helloPiers helloPiers commented May 20, 2017

The "args" passed to Mgr.CreateService are distinct from the arguments passed to Service.Start (or via the "Start parameters" field in the service's Properties dialog box). The documentation implies they are the same. The args passed to Service.Start appear as the args on Svc.Handler.Execute, but the args passed to CreateService end up as command line arguments (os.Args).

I have a doc fix which I plan to submit as a way to learn the contribution process.

@gopherbot gopherbot added this to the Unreleased milestone May 20, 2017
@gopherbot
Copy link

@gopherbot gopherbot commented May 20, 2017

CL https://golang.org/cl/43714 mentions this issue.

@alexbrainman
Copy link
Member

@alexbrainman alexbrainman commented May 22, 2017

The "args" passed to Mgr.CreateService are distinct from the arguments passed to Service.Start (or via the "Start parameters" field in the service's Properties dialog box).

Distinct in what way? And so what? Why should we care?

The documentation implies they are the same.

Both args are passed to svc.Handler.Execute. That is the only "same" thing. Is that a problem?

The args passed to Service.Start appear as the args on Svc.Handler.Execute,

Correct.

... but the args passed to CreateService end up as command line arguments (os.Args).

Maybe. I did not check.

I do not understand what is the problem here. I suspect you are unhappy about some documentation. Which documentation is invalid and why? Thank you.

Alex

@helloPiers
Copy link
Contributor Author

@helloPiers helloPiers commented May 22, 2017

Hi Alex,

The windows API call StartService takes some arguments, and these are passed to the windows API callback ServiceMain. (This is what the Go package makes available as the args parameter to svc.Handler.Execute.)

When you register a service with the windows API call CreateService, you are allowed to include in lpBinaryPathName some command-line arguments. These get passed to the service's executable program as standard command line args (e.g. as "argv" to main()).

Those two types of arguments are distinct.

The Go package's Mgr.CreateService()'s args parameter is the second type; i.e. they are string appended to exepath:

        s := syscall.EscapeArg(exepath)
        for _, v := range args {
                s += " " + syscall.EscapeArg(v)
        }

This distinction caught me out because the doc comment for Mgr.CreateService implied its args parameter was the first type - "... args will be passed to svc.Handler.Execute". But, they won't be. (They're in os.Args.)

Hope it's clear what I mean, it took me a while to work out what was happening yesterday while trying to pass some args to a service.

(I'd already submitted a small doc fix CL which Brad merged before your comment.)

thanks
Piers

@alexbrainman
Copy link
Member

@alexbrainman alexbrainman commented May 24, 2017

"... args will be passed to svc.Handler.Execute". But, they won't be. (They're in os.Args.)

I was mistaken about that. Thank you for explaining.

Alex

@helloPiers
Copy link
Contributor Author

@helloPiers helloPiers commented May 24, 2017

No problem - this was a pretty minor thing overall. That the svc package exists and functions so well has been a huge boost to our project. Cheers.

@golang golang locked and limited conversation to collaborators May 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants