am d98c87c9: Merge "init: Fix chown and chmod for write-only files"
* commit 'd98c87c95342ed6eade9f1239122dc9e90dcad67':
init: Fix chown and chmod for write-only files
diff --git a/init/builtins.c b/init/builtins.c
index 41fc03e..661c9b1 100644
--- a/init/builtins.c
+++ b/init/builtins.c
@@ -75,12 +75,23 @@
}
}
+static int _open(const char *path)
+{
+ int fd;
+
+ fd = open(path, O_RDONLY | O_NOFOLLOW);
+ if (fd < 0)
+ fd = open(path, O_WRONLY | O_NOFOLLOW);
+
+ return fd;
+}
+
static int _chown(const char *path, unsigned int uid, unsigned int gid)
{
int fd;
int ret;
- fd = open(path, O_RDONLY | O_NOFOLLOW);
+ fd = _open(path);
if (fd < 0) {
return -1;
}
@@ -103,7 +114,7 @@
int fd;
int ret;
- fd = open(path, O_RDONLY | O_NOFOLLOW);
+ fd = _open(path);
if (fd < 0) {
return -1;
}