if (ret < 0 || (size_t)ret >= sizeof(lxcpath))
return -1;
- ret = mknod(path, S_IFREG, 0);
+ ret = mknod(path, S_IFREG | 0000, 0);
if (ret < 0 && errno != EEXIST) {
SYSERROR("Failed to create \"%s\"", lxcpath);
return -1;
can_mknod = 0;
}
- ret = mknod(path, S_IFREG, 0);
+ ret = mknod(path, S_IFREG | 0000, 0);
if (ret < 0 && errno != EEXIST) {
SYSERROR("Failed to create file \"%s\"", path);
return -1;
}
/* Create dummy /dev/ptmx file as bind mountpoint for /dev/pts/ptmx. */
- ret = open("/dev/ptmx", O_CREAT, 0666);
- if (ret < 0) {
+ ret = mknod("/dev/ptmx", S_IFREG | 0000, 0);
+ if (ret < 0 && errno != EEXIST) {
SYSERROR("Failed to create dummy \"/dev/ptmx\" file as bind mount target");
return -1;
}
- close(ret);
DEBUG("Created dummy \"/dev/ptmx\" file as bind mount target");
/* Fallback option: create symlink /dev/ptmx -> /dev/pts/ptmx */
* taken care of creating /dev/console.
*/
ret = mknod(path, S_IFREG | 0000, 0);
- if (ret < 0) {
- if (errno != EEXIST) {
- SYSERROR("Failed to create console");
- return -errno;
- }
+ if (ret < 0 && errno != EEXIST) {
+ SYSERROR("Failed to create console");
+ return -errno;
}
ret = fchmod(console->slave, S_IXUSR | S_IXGRP | S_IXOTH);
const struct lxc_terminal *console,
char *ttydir)
{
- int ret, fd;
+ int ret;
char path[MAXPATHLEN], lxcpath[MAXPATHLEN];
char *rootfs_path = rootfs->path ? rootfs->mount : "";
if (ret < 0 || (size_t)ret >= sizeof(lxcpath))
return -1;
- ret = creat(lxcpath, 0660);
- if (ret == -1 && errno != EEXIST) {
+ ret = mknod(lxcpath, S_IFREG | 0000, 0);
+ if (ret < 0 && errno != EEXIST) {
SYSERROR("Failed to create \"%s\"", lxcpath);
return -errno;
}
- if (ret >= 0)
- close(ret);
ret = snprintf(path, sizeof(path), "%s/dev/console", rootfs_path);
if (ret < 0 || (size_t)ret >= sizeof(path))
}
}
- fd = open(path, O_CREAT | O_EXCL, S_IXUSR | S_IXGRP | S_IXOTH);
- if (fd < 0) {
- if (errno != EEXIST) {
- SYSERROR("Failed to create console");
- return -errno;
- }
- } else {
- close(fd);
+ ret = mknod(path, S_IFREG | 0000, 0);
+ if (ret < 0 && errno != EEXIST) {
+ SYSERROR("Failed to create console");
+ return -errno;
}
- ret = chmod(console->name, S_IXUSR | S_IXGRP | S_IXOTH);
+ ret = fchmod(console->slave, S_IXUSR | S_IXGRP | S_IXOTH);
if (ret < 0) {
SYSERROR("Failed to set mode \"0%o\" to \"%s\"",
S_IXUSR | S_IXGRP | S_IXOTH, console->name);
const struct lxc_rootfs *rootfs,
const char *lxc_name, const char *lxc_path)
{
- int fd, ret;
+ int ret;
char *p1, *p2;
if (strncmp(mntent->mnt_type, "overlay", 7) == 0) {
return -1;
}
- fd = open(path, O_CREAT, 0644);
- if (fd < 0)
- return -1;
- close(fd);
+ ret = mknod(path, S_IFREG | 0000, 0);
+ if (ret < 0 && errno != EEXIST)
+ return -errno;
return 0;
}