Add per-user locking option to portmaster-start run cmds
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -13,8 +14,22 @@ import (
|
||||
processInfo "github.com/shirou/gopsutil/process"
|
||||
)
|
||||
|
||||
func checkAndCreateInstanceLock(path, name string) (pid int32, err error) {
|
||||
lockFilePath := filepath.Join(dataRoot.Path, path, fmt.Sprintf("%s-lock.pid", name))
|
||||
func checkAndCreateInstanceLock(path, name string, perUser bool) (pid int32, err error) {
|
||||
var lockFilePath string
|
||||
if perUser {
|
||||
// Get user ID for per-user lock file.
|
||||
var userID string
|
||||
usr, err := user.Current()
|
||||
if err != nil {
|
||||
log.Printf("failed to get current user: %s\n", err)
|
||||
userID = "no-user"
|
||||
} else {
|
||||
userID = usr.Uid
|
||||
}
|
||||
lockFilePath = filepath.Join(dataRoot.Path, path, fmt.Sprintf("%s-%s-lock.pid", name, userID))
|
||||
} else {
|
||||
lockFilePath = filepath.Join(dataRoot.Path, path, fmt.Sprintf("%s-lock.pid", name))
|
||||
}
|
||||
|
||||
// read current pid file
|
||||
data, err := ioutil.ReadFile(lockFilePath)
|
||||
|
||||
Reference in New Issue
Block a user