[lxc-devel] [PATCH] replace redundant creat() with open()

S.Çağlar Onur caglar at 10ur.org
Fri Nov 8 19:39:19 UTC 2013


creat() is equivalent to open() with flags equal to O_CREAT|O_WRONLY|O_TRUNC

Signed-off-by: S.Çağlar Onur <caglar at 10ur.org>
---
 src/lxc/bdev.c      | 2 +-
 src/lxc/conf.c      | 6 +++---
 src/lxc/lxc_start.c | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/lxc/bdev.c b/src/lxc/bdev.c
index c7e5e5e..0194ccd 100644
--- a/src/lxc/bdev.c
+++ b/src/lxc/bdev.c
@@ -1594,7 +1594,7 @@ static int do_loop_create(const char *path, unsigned long size, const char *fsty
 	int fd, ret;
 	// create the new loopback file.
 	process_lock();
-	fd = creat(path, S_IRUSR|S_IWUSR);
+	fd = open(path, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR);
 	process_unlock();
 	if (fd < 0)
 		return -1;
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index a756731..dc34568 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -909,7 +909,7 @@ static int setup_tty(const struct lxc_rootfs *rootfs,
 				return -1;
 			}
 			process_lock();
-			ret = creat(lxcpath, 0660);
+			ret = open(lxcpath, O_CREAT|O_WRONLY|O_TRUNC, 0660);
 			process_unlock();
 			if (ret==-1 && errno != EEXIST) {
 				SYSERROR("error creating %s\n", lxcpath);
@@ -945,7 +945,7 @@ static int setup_tty(const struct lxc_rootfs *rootfs,
 			/* If we populated /dev, then we need to create /dev/ttyN */
 			if (access(path, F_OK)) {
 				process_lock();
-				ret = creat(path, 0660);
+				ret = open(path, O_CREAT|O_WRONLY|O_TRUNC, 0660);
 				process_unlock();
 				if (ret==-1) {
 					SYSERROR("error creating %s\n", path);
@@ -1546,7 +1546,7 @@ static int setup_ttydir_console(const struct lxc_rootfs *rootfs,
 	}
 
 	process_lock();
-	ret = creat(lxcpath, 0660);
+	ret = open(lxcpath, O_CREAT|O_WRONLY|O_TRUNC, 0660);
 	process_unlock();
 	if (ret==-1 && errno != EEXIST) {
 		SYSERROR("error %d creating %s\n", errno, lxcpath);
diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c
index add2542..f8fc6d4 100644
--- a/src/lxc/lxc_start.c
+++ b/src/lxc/lxc_start.c
@@ -62,7 +62,7 @@ static int ensure_path(char **confpath, const char *path)
 
 	if (path) {
 		if (access(path, W_OK)) {
-			fd = creat(path, 0600);
+			fd = open(path, O_CREAT|O_WRONLY|O_TRUNC, 0600);
 			if (fd < 0 && errno != EEXIST) {
 				SYSERROR("failed to create '%s'", path);
 				goto err;
-- 
1.8.3.2





More information about the lxc-devel mailing list