Skip to content

Commit

Permalink
Start function names with lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Dec 31, 2024
1 parent 88f97b6 commit c49fec0
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions restartable.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ var (
regexExecMap = regexp.MustCompile(`^[0-9a-f]+-[0-9a-f]+ r(w|-)x`)
)

// GetDeleted retrieves deleted file mappings for a process
func GetDeleted(fs ProcPidFS) ([]string, error) {
// getDeleted retrieves deleted file mappings for a process
func getDeleted(fs ProcPidFS) ([]string, error) {
maps, err := fs.ReadFile("maps")
if err != nil {
if errors.Is(err, unix.EACCES) {
Expand All @@ -111,16 +111,16 @@ func GetDeleted(fs ProcPidFS) ([]string, error) {
for _, line := range strings.Split(string(maps), "\n") {
file := regexDeleted.FindString(line)
if file != "" && regexExecMap.MatchString(line) && !regexIgnored.MatchString(file) {
files = append(files, QuoteString(strings.TrimSuffix(file, " (deleted)")))
files = append(files, quoteString(strings.TrimSuffix(file, " (deleted)")))
}
}
sort.Strings(files)

return files, nil
}

// GetService retrieves the service name
func GetService(fs ProcPidFS, userService bool) string {
// getService retrieves the service name
func getService(fs ProcPidFS, userService bool) string {
data, err := fs.ReadFile("cgroup")
if err != nil {
return "-"
Expand All @@ -139,8 +139,8 @@ func GetService(fs ProcPidFS, userService bool) string {
return "-"
}

// GetCommand retrieves the command
func GetCommand(fs ProcPidFS, fullPath bool, statusName string) (string, error) {
// getCommand retrieves the command
func getCommand(fs ProcPidFS, fullPath bool, statusName string) (string, error) {
data, err := fs.ReadFile("cmdline")
if err != nil {
return "", err
Expand Down Expand Up @@ -215,9 +215,9 @@ type ProcessInfo struct {
Service string
}

// GetProcessInfo gets process information
func GetProcessInfo(fs ProcPidFS, fullPath bool, userService bool) (*ProcessInfo, error) {
deleted, err := GetDeleted(fs)
// getProcessInfo gets process information
func getProcessInfo(fs ProcPidFS, fullPath bool, userService bool) (*ProcessInfo, error) {
deleted, err := getDeleted(fs)
if err != nil {
return nil, err
} else if len(deleted) == 0 {
Expand All @@ -242,22 +242,22 @@ func GetProcessInfo(fs ProcPidFS, fullPath bool, userService bool) (*ProcessInfo
panic(err)
}

command, err := GetCommand(fs, fullPath, statusName)
command, err := getCommand(fs, fullPath, statusName)
if err != nil {
return nil, err
}

return &ProcessInfo{
Command: QuoteString(command),
Command: quoteString(command),
Deleted: deleted,
Ppid: ppid,
Uid: uid,
Service: GetService(fs, userService),
Service: getService(fs, userService),
}, nil
}

// Quote special characters
func QuoteString(str string) string {
func quoteString(str string) string {
if len(str) > 0 {
str = strconv.Quote(str)
return str[1 : len(str)-1]
Expand All @@ -266,7 +266,7 @@ func QuoteString(str string) string {
}

// Get username from UID
func GetUser(uid int) string {
func getUser(uid int) string {
if info, err := user.LookupId(strconv.Itoa(uid)); err != nil {
return "-"
} else {
Expand Down Expand Up @@ -303,7 +303,7 @@ type Opts struct {
version bool
}

func RunProcessMonitor(lister ProcessLister, opts Opts, openProc func(int) (ProcPidFS, error)) {
func runProcessMonitor(lister ProcessLister, opts Opts, openProc func(int) (ProcPidFS, error)) {
pids, err := lister.ListProcesses()
if err != nil {
log.Fatal(err)
Expand All @@ -328,7 +328,7 @@ func RunProcessMonitor(lister ProcessLister, opts Opts, openProc func(int) (Proc
return
}
defer fs.Close()
info, err := GetProcessInfo(fs, opts.verbose, opts.user)
info, err := getProcessInfo(fs, opts.verbose, opts.user)
if err != nil {
log.Print(err)
}
Expand All @@ -345,7 +345,7 @@ func RunProcessMonitor(lister ProcessLister, opts Opts, openProc func(int) (Proc
}
close(channel[pid])
if opts.short < 3 {
fmt.Printf("%d\t%d\t%d\t%-20s\t%20s\t%s\n", pid, proc.Ppid, proc.Uid, GetUser(proc.Uid), proc.Service, proc.Command)
fmt.Printf("%d\t%d\t%d\t%-20s\t%20s\t%s\n", pid, proc.Ppid, proc.Uid, getUser(proc.Uid), proc.Service, proc.Command)
} else if proc.Service != "-" {
services[proc.Service] = true
}
Expand Down Expand Up @@ -395,7 +395,7 @@ func main() {
fmt.Fprintln(os.Stderr, "WARN: Run this program as root")
}

RunProcessMonitor(DefaultProcessLister{}, opts, func(pid int) (ProcPidFS, error) {
runProcessMonitor(DefaultProcessLister{}, opts, func(pid int) (ProcPidFS, error) {
return OpenProcPid(pid)
})
}

0 comments on commit c49fec0

Please sign in to comment.