init: Fix chown and chmod for write-only files

Change-Id: I570b631ced11ab104aafe7ebfe71bae4e380d8af
This commit is contained in:
Benoit Goby 2012-03-28 18:15:56 -07:00 committed by Nick Kralevich
parent 09a96bef65
commit 93574c619c
1 changed files with 13 additions and 2 deletions

View File

@ -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;
}