Skip to content

Commit

Permalink
Merge pull request #107 from rosskirkpat/bug/fix-tags
Browse files Browse the repository at this point in the history
go fmt and gitignore additions
  • Loading branch information
luthermonson authored Apr 26, 2022
2 parents c3be1f8 + 2f41ce0 commit 95938d4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ bin/*

# Rancher
Dockerfile.Dapper[0-9]*
Dockerfile.dapper[0-9]*
.cache/

# MAC file
.DS_Store

dist/
*.tgz
6 changes: 3 additions & 3 deletions pkg/concierge/concierge.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ func New(name, path string, cfg *Config) (*Concierge, error) {
}

if path == "" {
return nil, errors.New("path isn't set and can't be empty.")
return nil, errors.New("path isn't set and can't be empty")
}
if cfg == nil {
return nil, errors.New("cfg is nil, please provide at least an empty config.")
return nil, errors.New("cfg is nil, please provide at least an empty config")
}

cfg.registryKey = fmt.Sprintf(`SYSTEM\CurrentControlSet\Services\%s`, name)
Expand Down Expand Up @@ -157,7 +157,7 @@ func (c *Concierge) ServiceExists() (bool, error) {

services, err := m.ListServices()
if err != nil {
return false, errors.Wrap(err, "could not list services.")
return false, errors.Wrap(err, "could not list services")
}

for _, service := range services {
Expand Down
28 changes: 14 additions & 14 deletions pkg/profilings/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,51 @@ import (
func StackDump() (err error) {
err = callStackDump()
if err != nil {
logrus.Errorf("StackDump: failed to call wins stack dump")
logrus.Errorf("[StackDump] failed to call wins stack dump: %v", err)
return err
}
return nil
}

func findWinsProcess() (uint32, error) {
h, e := windows.CreateToolhelp32Snapshot(windows.TH32CS_SNAPPROCESS, 0)
if e != nil {
panic(e)
h, err := windows.CreateToolhelp32Snapshot(windows.TH32CS_SNAPPROCESS, 0)
if err != nil {
panic(err)
}
var p windows.ProcessEntry32
p.Size = uint32(reflect.TypeOf(p).Size())

for {
e := windows.Process32Next(h, &p)
if e != nil {
logrus.Errorf("findWinsProcess: error finding next process [%v]", e)
err := windows.Process32Next(h, &p)
if err != nil {
logrus.Errorf("[findWinsProcess] error finding next process: %v", err)
break
}
ps := getProcessName(windows.UTF16ToString(p.ExeFile[:]))
logrus.Debugf("findWinsProcess: found trimmed process [%v]", ps)
logrus.Debugf("[findWinsProcess] found trimmed process: %v", ps)
if ps == defaults.WindowsProcessName {
pid := p.ProcessID
logrus.Debugf("Found process [%s] with pid [%d]", ps, pid)
logrus.Debugf("[findWinsProcess] found process [%s] with pid [%d]", ps, pid)
return pid, nil
}
logrus.Warnf("no process matching [%s] was found", defaults.WindowsProcessName)
}
logrus.Warnf("[findWinsProcess] no process matching [%s] was found", defaults.WindowsProcessName)
}
return 0, nil
}

func callStackDump() (err error) {

winsProcessID, err := findWinsProcess()
if err != nil {
return fmt.Errorf("callStackDump: error returned when getting wins process id:\n[%v]", err)
return fmt.Errorf("[callStackDump]: error returned when getting wins process id: %v", err)
}

event := fmt.Sprintf("Global\\stackdump-%d", winsProcessID)
ev, _ := windows.UTF16PtrFromString(event)

// verify that wins is running before trying to send stackdump signal
if syscall.Signal(syscall.Signal(0)) == 0 {
logrus.Debugf("Confirmed that process %d is running.", winsProcessID)
logrus.Debugf("[callStackDump] confirmed that wins process %d is running", winsProcessID)
}

sd, err := windows.SecurityDescriptorFromString(defaults.PermissionBuiltinAdministratorsAndLocalSystem)
Expand All @@ -84,7 +84,7 @@ func callStackDump() (err error) {
defer windows.CloseHandle(h)

if err := windows.SetEvent(h); err != nil {
return fmt.Errorf("callStackDump: error setting win32 event [%v]", err)
return fmt.Errorf("[callStackDump] error setting win32 event: %v", err)
}

return windows.ResetEvent(h)
Expand Down

0 comments on commit 95938d4

Please sign in to comment.