summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/socket/rpcinet/conn/conn.go
diff options
context:
space:
mode:
authorBrian Geffon <bgeffon@google.com>2018-06-05 15:43:55 -0700
committerShentubot <shentubot@google.com>2018-06-05 15:45:35 -0700
commitff7b4a156f95a587b5df4de89a22c200fceabb96 (patch)
treedbf2206d66db40f71c1d92784cbc60126a59e1d3 /pkg/sentry/socket/rpcinet/conn/conn.go
parent343020ca275298fe9ea3320628454cad5f0052aa (diff)
Add support for rpcinet owned procfs files.
This change will add support for /proc/sys/net and /proc/net which will be managed and owned by rpcinet. This will allow these inodes to be forward as rpcs. PiperOrigin-RevId: 199370799 Change-Id: I2c876005d98fe55dd126145163bee5a645458ce4
Diffstat (limited to 'pkg/sentry/socket/rpcinet/conn/conn.go')
-rw-r--r--pkg/sentry/socket/rpcinet/conn/conn.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/pkg/sentry/socket/rpcinet/conn/conn.go b/pkg/sentry/socket/rpcinet/conn/conn.go
index ea6ec87ed..f4c8489b1 100644
--- a/pkg/sentry/socket/rpcinet/conn/conn.go
+++ b/pkg/sentry/socket/rpcinet/conn/conn.go
@@ -147,6 +147,26 @@ func (c *RPCConnection) RPCReadFile(path string) ([]byte, *syserr.Error) {
return res.(*pb.ReadFileResponse_Data).Data, nil
}
+// RPCWriteFile will execute the WriteFile helper RPC method which avoids the
+// common pattern of open(2), write(2), write(2), close(2) by doing all
+// operations as a single RPC.
+func (c *RPCConnection) RPCWriteFile(path string, data []byte) (int64, *syserr.Error) {
+ req := &pb.SyscallRequest_WriteFile{&pb.WriteFileRequest{
+ Path: path,
+ Content: data,
+ }}
+
+ id, ch := c.NewRequest(pb.SyscallRequest{Args: req}, false /* ignoreResult */)
+ <-ch
+
+ res := c.Request(id).Result.(*pb.SyscallResponse_WriteFile).WriteFile
+ if e := res.ErrorNumber; e != 0 {
+ return int64(res.Written), syserr.FromHost(syscall.Errno(e))
+ }
+
+ return int64(res.Written), nil
+}
+
// Request retrieves the request corresponding to the given request ID.
//
// The channel returned by NewRequest must have been closed before Request can