1
0

Added some more comments.

This commit is contained in:
Alexander Andreev 2023-02-04 20:33:26 +04:00
parent d0a19ff9aa
commit 620c9874c2
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F
3 changed files with 7 additions and 4 deletions

View File

@ -8,7 +8,7 @@ import (
"strings" "strings"
) )
// Configuration holds a list of process names to be tracked and a listen address. // Configuration holds a configuration for the service.
type Configuration struct { type Configuration struct {
ListenAddress string ListenAddress string
IndentedOutput bool IndentedOutput bool
@ -51,7 +51,7 @@ func LoadConfiguration(path string) (conf *Configuration, err error) {
return conf, nil return conf, nil
} }
// StoreConfiguration writes Configuration into a file. // StoreConfiguration writes configuration into a file.
func (conf *Configuration) StoreConfiguration(path string) (err error) { func (conf *Configuration) StoreConfiguration(path string) (err error) {
var config strings.Builder var config strings.Builder

View File

@ -17,6 +17,9 @@ func GetProcessPIDs(name string) ([]int, error) {
} }
for _, entry := range dir { for _, entry := range dir {
// This line demands a little clarification. Here we are making sure
// that the first character of a directory name is numeric. In ASCII
// all numerals are laying within 0x30-0x39 range.
if entry.IsDir() && entry.Name()[0]>>0x4&0xf == 0x3 { if entry.IsDir() && entry.Name()[0]>>0x4&0xf == 0x3 {
cmdline, err := os.ReadFile("/proc/" + entry.Name() + "/cmdline") cmdline, err := os.ReadFile("/proc/" + entry.Name() + "/cmdline")
if err != nil { if err != nil {

View File

@ -4,10 +4,10 @@ import (
"encoding/xml" "encoding/xml"
) )
// ProcessList is a map of processes' statuses. // ProcessList is a map of processes' names and its statuses.
type ProcessList map[string]bool type ProcessList map[string]bool
// MarshalXML implements Marshaler interface for a ProcessList. // MarshalXML implements XML Marshaler interface for a ProcessList.
func (l *ProcessList) MarshalXML(e *xml.Encoder, start xml.StartElement) error { func (l *ProcessList) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
if len(*l) == 0 { if len(*l) == 0 {
return nil return nil