MCPcopy
hub / github.com/safing/portmaster / CleanProcessStorage

Function CleanProcessStorage

service/process/database.go:129–175  ·  view source on GitHub ↗

CleanProcessStorage cleans the storage from old processes.

(activePIDs map[int]struct{})

Source from the content-addressed store, hash-verified

127
128// CleanProcessStorage cleans the storage from old processes.
129func CleanProcessStorage(activePIDs map[int]struct{}) {
130 // add system table of processes
131 pids, err := processInfo.Pids()
132 if err != nil {
133 log.Warningf("process: failed to get list of active PIDs: %s", err)
134 } else {
135 for _, pid := range pids {
136 activePIDs[int(pid)] = struct{}{}
137 }
138 }
139
140 processesCopy := All()
141 threshold := time.Now().Add(-deleteProcessesThreshold).Unix()
142
143 // clean primary processes
144 for _, p := range processesCopy {
145 // The PID of a process does not change.
146
147 // Check if this is a special process.
148 switch p.Pid {
149 case UnidentifiedProcessID, UnsolicitedProcessID, SystemProcessID:
150 p.profile.MarkStillActive()
151 continue
152 }
153
154 // Check if process is active.
155 _, active := activePIDs[p.Pid]
156 if active {
157 p.profile.MarkStillActive()
158 continue
159 }
160
161 // Process is inactive, start deletion process
162 lastSeen := p.GetLastSeen()
163 switch {
164 case lastSeen == 0:
165 // add last seen timestamp
166 p.SetLastSeen(time.Now().Unix())
167 case lastSeen > threshold:
168 // within keep period
169 default:
170 // delete now
171 p.Delete()
172 log.Tracef("process: cleaned %s", p.DatabaseKey())
173 }
174 }
175}
176
177// SetDBController sets the database controller and allows the package to push database updates on a save. It must be set by the package that registers the "network" database.
178func SetDBController(controller *database.Controller) {

Callers 1

connectionCleanerFunction · 0.92

Calls 9

WarningfFunction · 0.92
TracefFunction · 0.92
AllFunction · 0.85
SetLastSeenMethod · 0.80
DeleteMethod · 0.65
DatabaseKeyMethod · 0.65
AddMethod · 0.45
MarkStillActiveMethod · 0.45
GetLastSeenMethod · 0.45

Tested by

no test coverage detected