diff options
| author | Benoit Goby <benoit@android.com> | 2012-03-28 18:15:56 -0700 |
|---|---|---|
| committer | Nick Kralevich <nnk@google.com> | 2012-05-04 16:29:41 -0700 |
| commit | 93574c619c96bec7e7e42468ce8573f630c78b21 (patch) | |
| tree | 07434cbc1caa297e9964ff24dfdf4047b4325bbc /init/builtins.c | |
| parent | 09a96bef654d58d5100353a1aa7239aae12d9bf3 (diff) | |
| download | system_core-93574c619c96bec7e7e42468ce8573f630c78b21.tar.gz system_core-93574c619c96bec7e7e42468ce8573f630c78b21.tar.bz2 system_core-93574c619c96bec7e7e42468ce8573f630c78b21.zip | |
init: Fix chown and chmod for write-only files
Change-Id: I570b631ced11ab104aafe7ebfe71bae4e380d8af
Diffstat (limited to 'init/builtins.c')
| -rw-r--r-- | init/builtins.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/init/builtins.c b/init/builtins.c index 41fc03e1..661c9b18 100644 --- a/init/builtins.c +++ b/init/builtins.c @@ -75,12 +75,23 @@ static int write_file(const char *path, const char *value) } } +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 @@ static int _chmod(const char *path, mode_t mode) int fd; int ret; - fd = open(path, O_RDONLY | O_NOFOLLOW); + fd = _open(path); if (fd < 0) { return -1; } |
