mirror of
				https://github.com/ClusterCockpit/cc-metric-collector.git
				synced 2025-10-31 17:05:07 +01:00 
			
		
		
		
	Fix: Create lock file if it does not exist in likwidMetric.go (#120)
Co-authored-by: exterr2f <Robert.Externbrink@rub.de>
This commit is contained in:
		| @@ -374,10 +374,21 @@ func (m *LikwidCollector) takeMeasurement(evidx int, evset LikwidEventsetConfig, | ||||
| 	} | ||||
| 	defer watcher.Close() | ||||
| 	if len(m.config.LockfilePath) > 0 { | ||||
| 		// Check if the lock file exists | ||||
| 		info, err := os.Stat(m.config.LockfilePath) | ||||
| 		if os.IsNotExist(err) { | ||||
| 			// Create the lock file if it does not exist | ||||
| 			file, createErr := os.Create(m.config.LockfilePath) | ||||
| 			if createErr != nil { | ||||
| 				return true, fmt.Errorf("failed to create lock file: %v", createErr) | ||||
| 			} | ||||
| 			file.Close() | ||||
| 			info, err = os.Stat(m.config.LockfilePath) // Recheck the file after creation | ||||
| 		} | ||||
| 		if err != nil { | ||||
| 			return true, err | ||||
| 		} | ||||
| 		// Check file ownership | ||||
| 		uid := info.Sys().(*syscall.Stat_t).Uid | ||||
| 		if uid != uint32(os.Getuid()) { | ||||
| 			usr, err := user.LookupId(fmt.Sprint(uid)) | ||||
| @@ -387,6 +398,7 @@ func (m *LikwidCollector) takeMeasurement(evidx int, evset LikwidEventsetConfig, | ||||
| 				return true, fmt.Errorf("Access to performance counters locked by %d", uid) | ||||
| 			} | ||||
| 		} | ||||
| 		// Add the lock file to the watcher | ||||
| 		err = watcher.Add(m.config.LockfilePath) | ||||
| 		if err != nil { | ||||
| 			cclog.ComponentError(m.name, err.Error()) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user