Skip to content

Commit ca890c0

Browse files
committed
feat(agent): lock process memory with mlockall
1 parent 69a2138 commit ca890c0

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

agent.go

+12
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ func (cmd *RestartCmd) Run(config *Config) error {
3030
printRepr(cmd)
3131
}
3232

33+
if err := lockMemory(); err != nil {
34+
return err
35+
}
36+
3337
_, _ = messageAgent(config.Socket, "SHUTDOWN")
3438

3539
identitiesText, err := decryptIdentities(config.Identities)
@@ -45,6 +49,10 @@ func (cmd *RunCmd) Run(config *Config) error {
4549
printRepr(cmd)
4650
}
4751

52+
if err := lockMemory(); err != nil {
53+
return err
54+
}
55+
4856
return runAgent(config.Socket)
4957
}
5058

@@ -53,6 +61,10 @@ func (cmd *StartCmd) Run(config *Config) error {
5361
printRepr(cmd)
5462
}
5563

64+
if err := lockMemory(); err != nil {
65+
return err
66+
}
67+
5668
if err := pingAgent(config.Socket); err == nil {
5769
return fmt.Errorf("found agent responding on socket")
5870
}

mlockall.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// pago - a command-line password manager.
2+
//
3+
// License: MIT.
4+
// See the file LICENSE.
5+
6+
package main
7+
8+
import (
9+
"fmt"
10+
11+
"golang.org/x/sys/unix"
12+
)
13+
14+
func lockMemory() error {
15+
if err := unix.Mlockall(unix.MCL_CURRENT | unix.MCL_FUTURE); err != nil {
16+
return fmt.Errorf("failed to lock memory: %v", err)
17+
}
18+
19+
return nil
20+
}

0 commit comments

Comments
 (0)