Skip to content

Commit

Permalink
Windows: Print all arguments passed to service (#1746)
Browse files Browse the repository at this point in the history
  • Loading branch information
jefferbrecht authored Jul 5, 2024
1 parent 96c4733 commit 4b3b749
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
11 changes: 5 additions & 6 deletions cmd/google_cloud_ops_agent_diagnostics/main_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ func (s *service) Execute(args []string, r <-chan svc.ChangeRequest, changes cha

const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown
changes <- svc.Status{State: svc.StartPending}
if err := s.parseFlags(args); err != nil {

allArgs := append([]string{}, os.Args[1:]...)
allArgs = append(allArgs, args[1:]...)
if err := s.parseFlags(allArgs); err != nil {
s.log.Error(DiagnosticsEventID, fmt.Sprintf("failed to parse arguments: %v", err))
return false, ERROR_INVALID_PARAMETER
}
Expand Down Expand Up @@ -122,9 +125,5 @@ func (s *service) parseFlags(args []string) error {
s.log.Info(DiagnosticsEventID, fmt.Sprintf("args: %#v", args))
var fs flag.FlagSet
fs.StringVar(&s.userConf, "config", "", "path to the user specified agent config")
s.log.Info(DiagnosticsEventID, s.userConf)

allArgs := append([]string{}, os.Args[1:]...)
allArgs = append(allArgs, args[1:]...)
return fs.Parse(allArgs)
return fs.Parse(args)
}
10 changes: 5 additions & 5 deletions cmd/ops_agent_windows/run_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ func (s *service) Execute(args []string, r <-chan svc.ChangeRequest, changes cha
defer cancel()
const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown
changes <- svc.Status{State: svc.StartPending}
if err := s.parseFlags(args); err != nil {

allArgs := append([]string{}, os.Args[1:]...)
allArgs = append(allArgs, args[1:]...)
if err := s.parseFlags(allArgs); err != nil {
s.log.Error(EngineEventID, fmt.Sprintf("failed to parse arguments: %v", err))
// ERROR_INVALID_ARGUMENT
return false, 0x00000057
Expand Down Expand Up @@ -104,10 +107,7 @@ func (s *service) parseFlags(args []string) error {
var fs flag.FlagSet
fs.StringVar(&s.userConf, "in", "", "path to the user specified agent config")
fs.StringVar(&s.outDirectory, "out", "", "directory to write generated configuration files to")

allArgs := append([]string{}, os.Args[1:]...)
allArgs = append(allArgs, args[1:]...)
return fs.Parse(allArgs)
return fs.Parse(args)
}

func (s *service) checkForStandaloneAgents(unified *confgenerator.UnifiedConfig) error {
Expand Down

0 comments on commit 4b3b749

Please sign in to comment.