diff options
author | Fabricio Voznika <fvoznika@google.com> | 2018-05-10 12:37:46 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-05-10 12:38:36 -0700 |
commit | 5a509c47a20e0b81b95bb4932e8b19dfc6a402e2 (patch) | |
tree | 6c7e78b4d2c2d888ed0f68a993107e8272b010d8 /runsc/fsgofer/fsgofer.go | |
parent | 2d3c6dc2efb1d9957836d70d1a59634b96ea74d4 (diff) |
Open file as read-write when mount points to a file
This is to allow files mapped directly, like /etc/hosts, to be writable.
Closes #40
PiperOrigin-RevId: 196155920
Change-Id: Id2027e421cef5f94a0951c3e18b398a77c285bbd
Diffstat (limited to 'runsc/fsgofer/fsgofer.go')
-rw-r--r-- | runsc/fsgofer/fsgofer.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/runsc/fsgofer/fsgofer.go b/runsc/fsgofer/fsgofer.go index be2ac5f3c..11dd28cef 100644 --- a/runsc/fsgofer/fsgofer.go +++ b/runsc/fsgofer/fsgofer.go @@ -98,7 +98,17 @@ func (a *attachPoint) Attach(appPath string) (p9.File, error) { } root := filepath.Join(a.prefix, appPath) - f, err := os.OpenFile(root, openFlags|syscall.O_RDONLY, 0) + fi, err := os.Stat(root) + if err != nil { + return nil, err + } + + mode := syscall.O_RDWR + if a.conf.ROMount || fi.IsDir() { + mode = syscall.O_RDONLY + } + + f, err := os.OpenFile(root, mode|openFlags, 0) if err != nil { return nil, fmt.Errorf("unable to open file %q, err: %v", root, err) } |