mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-02-08 05:56:37 +00:00
service: fix inconsistent values for windows_service_start_mode (#2007)
This commit is contained in:
@@ -55,7 +55,7 @@ var (
|
|||||||
stopCh = make(chan struct{})
|
stopCh = make(chan struct{})
|
||||||
|
|
||||||
// serviceManagerFinishedCh is a channel to send a signal to the main function that the service manager has stopped the service.
|
// serviceManagerFinishedCh is a channel to send a signal to the main function that the service manager has stopped the service.
|
||||||
serviceManagerFinishedCh = make(chan struct{})
|
serviceManagerFinishedCh = make(chan struct{}, 1)
|
||||||
)
|
)
|
||||||
|
|
||||||
// IsService variable declaration allows initiating time-sensitive components like registering the Windows service
|
// IsService variable declaration allows initiating time-sensitive components like registering the Windows service
|
||||||
|
|||||||
@@ -422,15 +422,6 @@ func (c *Collector) getProcessStartTime(pid uint32) (uint64, error) {
|
|||||||
return 0, fmt.Errorf("failed to open process %w", err)
|
return 0, fmt.Errorf("failed to open process %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func(handle windows.Handle) {
|
|
||||||
err := windows.CloseHandle(handle)
|
|
||||||
if err != nil {
|
|
||||||
c.logger.Warn("failed to close process handle",
|
|
||||||
slog.Any("err", err),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}(handle)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
creation windows.Filetime
|
creation windows.Filetime
|
||||||
exit windows.Filetime
|
exit windows.Filetime
|
||||||
@@ -439,6 +430,14 @@ func (c *Collector) getProcessStartTime(pid uint32) (uint64, error) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
err = windows.GetProcessTimes(handle, &creation, &exit, &krn, &user)
|
err = windows.GetProcessTimes(handle, &creation, &exit, &krn, &user)
|
||||||
|
|
||||||
|
if err := windows.CloseHandle(handle); err != nil {
|
||||||
|
c.logger.LogAttrs(context.Background(), slog.LevelWarn, "failed to close process handle",
|
||||||
|
slog.Any("err", err),
|
||||||
|
slog.Uint64("pid", uint64(pid)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("failed to get process times %w", err)
|
return 0, fmt.Errorf("failed to get process times %w", err)
|
||||||
}
|
}
|
||||||
@@ -479,7 +478,7 @@ func (c *Collector) getServiceConfig(service *mgr.Service) (mgr.Config, error) {
|
|||||||
*buf = make([]byte, bytesNeeded)
|
*buf = make([]byte, bytesNeeded)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.serviceConfigPoolBytes.Put(buf)
|
defer c.serviceConfigPoolBytes.Put(buf)
|
||||||
|
|
||||||
return mgr.Config{
|
return mgr.Config{
|
||||||
BinaryPathName: windows.UTF16PtrToString(serviceConfig.BinaryPathName),
|
BinaryPathName: windows.UTF16PtrToString(serviceConfig.BinaryPathName),
|
||||||
|
|||||||
Reference in New Issue
Block a user