Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bartoszWojciechO committed May 13, 2024
1 parent 3ffee74 commit 5086e0a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions norduser/service/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"log"
"os/exec"
"regexp"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -72,18 +71,20 @@ func getRunningNorduserPIDs() ([]int, error) {
}

func findPIDOfUID(uids string, desiredUID uint32) int {
re := regexp.MustCompile(`\s*(\d+)\s+(\d+)\s*`)

for _, uidPid := range strings.Split(uids, "\n") {
match := re.FindStringSubmatch(uidPid)
if len(match) != 3 {
log.Println(internal.ErrorPrefix+" invalid input line: ", uidPid)
var pid int
var uid int
n, err := fmt.Sscanf(uidPid, "%d%d", &uid, &pid)
if err != nil {
log.Println(internal.ErrorPrefix+" failed to parse uid pid line: ", err)
continue
}

uid, _ := strconv.Atoi(match[1])
if n != 2 {
log.Println(internal.ErrorPrefix+" invalid input line, expected <uid> <pid> format: ", uidPid)
}

if uid == int(desiredUID) {
pid, _ := strconv.Atoi(match[2])
return pid
}
}
Expand Down

0 comments on commit 5086e0a

Please sign in to comment.