aboutsummaryrefslogtreecommitdiffstats
path: root/init/builtins.c
diff options
context:
space:
mode:
authorRicardo Cerqueira <cyanogenmod@cerqueira.org>2012-11-19 16:28:39 +0000
committerRicardo Cerqueira <cyanogenmod@cerqueira.org>2012-11-19 16:28:39 +0000
commit7fe624e655044ed8f9d9cdb4322cf765e40a7910 (patch)
tree20d66993746bb58335bb7aabe0e2b56a9f3eb400 /init/builtins.c
parent5827cc4bd7b381f2734d0b958f96f4cf81090f42 (diff)
downloadsystem_core-7fe624e655044ed8f9d9cdb4322cf765e40a7910.tar.gz
system_core-7fe624e655044ed8f9d9cdb4322cf765e40a7910.tar.bz2
system_core-7fe624e655044ed8f9d9cdb4322cf765e40a7910.zip
Revert "init: Check for symlinks with lstat() not open()"
This reverts commit f3e86113ceae0e58735ca99754d77b1b9d1a83b5.
Diffstat (limited to 'init/builtins.c')
-rw-r--r--init/builtins.c46
1 files changed, 30 insertions, 16 deletions
diff --git a/init/builtins.c b/init/builtins.c
index 7f04ea3c..a2d73475 100644
--- a/init/builtins.c
+++ b/init/builtins.c
@@ -80,47 +80,61 @@ 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;
- struct stat p_statbuf;
-
- ret = lstat(path, &p_statbuf);
- if (ret < 0) {
+ fd = _open(path);
+ if (fd < 0) {
return -1;
}
- if (S_ISLNK(p_statbuf.st_mode) == 1) {
- errno = EINVAL;
+ ret = fchown(fd, uid, gid);
+ if (ret < 0) {
+ int errno_copy = errno;
+ close(fd);
+ errno = errno_copy;
return -1;
}
- ret = chown(path, uid, gid);
+ close(fd);
- return ret;
+ return 0;
}
static int _chmod(const char *path, mode_t mode)
{
+ int fd;
int ret;
- struct stat p_statbuf;
-
- ret = lstat(path, &p_statbuf);
- if (ret < 0) {
+ fd = _open(path);
+ if (fd < 0) {
return -1;
}
- if (S_ISLNK(p_statbuf.st_mode) == 1) {
- errno = EINVAL;
+ ret = fchmod(fd, mode);
+ if (ret < 0) {
+ int errno_copy = errno;
+ close(fd);
+ errno = errno_copy;
return -1;
}
- ret = chmod(path, mode);
+ close(fd);
- return ret;
+ return 0;
}
static int insmod(const char *filename, char *options)