x/sys/windows: mgr.Service.UpdateConfig(...) cannot set empty dependency list #73494
Labels
LibraryProposal
Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Go version
1.22.4 / x/sys@v0.20.0 (but the relevant code hasn't changed
Output of
go env
in your module/workspace:What did you do?
I was trying to update the configuration of a developed Windows service to remove all dependencies on other services, using the
(*mgr.Service).UpdateConfig(mgr.Config)
function. Themgr.Config
struct exposes dependencies asmgr.Config.Dependencies []string
, to which I was supplying an empty string slice.Minimal example; error checking/cleanup elided:
What did you see happen?
The service dependencies are unchanged, as observed in the Windows GUI. Subsequent calls to
mgr.OpenService(...).Config()
return the original value forDependencies
.What did you expect to see?
The service configuration should have been updated to have zero dependencies.
Naiive workaround is to call
windows.ChangeServiceConfig(...)
(i.e. the Win32 function wrapper) directly, passing a pointer to an explicitly-crafted[]uint16
Problem appears to relate to unexposed method
toStringBlock([]string) *uint16
, and how it handles empty slices (i.e. it returnsnil
).Guidance for the Win32
ChangeServiceConfigW
method suggests:Since changing the behaviour of
toStringBlock
or the exposure ofDependencies
may have backward-compatibility concerns, I'm not sure of the best way to expose the intent to clear this list. Perhaps a new method onmgr.Config
which empties the slice and sets an unexported flag, whichUpdateConfig
would then handle?Or maybe it is sufficient to document the lmitation and alternative in
UpdateConfig()
...The text was updated successfully, but these errors were encountered: