Skip to content

Commit

Permalink
Do not chmod +r if we don't need to
Browse files Browse the repository at this point in the history
If the inode is a mountpoint, chmod may just fail.

(See project-stacker/stacker#450)

Signed-off-by: Serge Hallyn <serge@hallyn.com>
  • Loading branch information
hallyn committed Sep 13, 2023
1 parent f74280b commit 77aaf33
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/unpriv/unpriv.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,13 @@ func Open(path string) (*os.File, error) {
return errors.Wrap(err, "lstat file")
}

// Add +r permissions to the file.
if err := os.Chmod(path, fi.Mode()|0400); err != nil {
return errors.Wrap(err, "chmod +r")
if fi.Mode() & 0400 != 0400 {
// Add +r permissions to the file.
if err := os.Chmod(path, fi.Mode()|0400); err != nil {
return errors.Wrap(err, "chmod +r")
}
defer fiRestore(path, fi)
}
defer fiRestore(path, fi)

// Open the damn thing.
fh, err = os.Open(path)
Expand Down

0 comments on commit 77aaf33

Please sign in to comment.