Ejemplo n.º 1
0
TEST_F(Fd, does_not_close_if_construction_doesnt_intend_to_transfer_ownership)
{
    EXPECT_TRUE(fd_is_open(raw_fd));
    {
        mir::Fd fd(mir::IntOwnedFd{raw_fd});
    }
    EXPECT_TRUE(fd_is_open(raw_fd));
}
Ejemplo n.º 2
0
TEST_F(Fd, moves_around)
{
    EXPECT_TRUE(fd_is_open(raw_fd));
    mir::Fd fd0(-1);
    fd0 = mir::Fd(raw_fd);
    mir::Fd fd1(std::move(fd0));
    mir::Fd fd2(fd1);

    EXPECT_TRUE(fd_is_open(raw_fd));
    fd1 = mir::Fd(-1);
    EXPECT_TRUE(fd_is_open(raw_fd));
    fd2 = mir::Fd(-1);
    EXPECT_FALSE(fd_is_open(raw_fd));
}
Ejemplo n.º 3
0
TEST_F(Fd, closes_when_refcount_is_zero)
{
    EXPECT_TRUE(fd_is_open(raw_fd));
    mir::Fd fd2(-1);
    {
        mir::Fd fd(raw_fd);
        {
            mir::Fd fd1(fd);
            fd2 = fd1;
        }
    }

    EXPECT_TRUE(fd_is_open(raw_fd));
    fd2 = mir::Fd(-1);
    EXPECT_FALSE(fd_is_open(raw_fd));
}
Ejemplo n.º 4
0
/**
 * this function will unlink (remove) a specified path file from file system.
 *
 * @param path the specified path file to be unlinked.
 *
 * @return 0 on successful, -1 on failed.
 */
int dfs_file_unlink(const char *path)
{
    int result;
    char *fullpath;
    struct dfs_filesystem *fs;

    /* Make sure we have an absolute path */
    fullpath = dfs_normalize_path(RT_NULL, path);
    if (fullpath == RT_NULL)
    {
        return -DFS_STATUS_EINVAL;
    }

    /* get filesystem */
    if ((fs = dfs_filesystem_lookup(fullpath)) == RT_NULL)
    {
        result = -DFS_STATUS_ENOENT;
        goto __exit;
    }

    /* Check whether file is already open */
    if (fd_is_open(fullpath) == 0)
    {
        result = -DFS_STATUS_EBUSY;
        goto __exit;
    }

    if (fs->ops->unlink != RT_NULL)
    {
        if (!(fs->ops->flags & DFS_FS_FLAG_FULLPATH))
        {
            if (dfs_subdir(fs->path, fullpath) == RT_NULL)
                result = fs->ops->unlink(fs, "/");
            else
                result = fs->ops->unlink(fs, dfs_subdir(fs->path, fullpath));
        }
        else
            result = fs->ops->unlink(fs, fullpath);
    }
    else result = -DFS_STATUS_ENOSYS;

__exit:
    rt_free(fullpath);
    return result;
}
Ejemplo n.º 5
0
static int
move_fd(int fd)
{
    int new_fd;
    int end_fd;

    if (socket_fd_region.order == 0) {
        return (fd);
    }

    // Start with lowest or highest number in range
    if (socket_fd_region.order == 1) {
        new_fd = socket_fd_region.lo;
        end_fd = socket_fd_region.hi;
    }
    else {
        new_fd = socket_fd_region.hi;
        end_fd = socket_fd_region.lo;
    }

    while (true) {
        if (!fd_is_open(new_fd)) {
            int dup_fd;
            dup_fd = fcntl(fd, F_DUPFD, new_fd);
            if (dup_fd == new_fd) {
                close(fd);
                return (dup_fd);
            }
        }
        new_fd += socket_fd_region.order;
        if (new_fd * socket_fd_region.order > end_fd * socket_fd_region.order) {
            teprintf("Ran out of file descriptors in range %d..%d\n",
                    socket_fd_region.lo, socket_fd_region.hi);
            if (opt_svc_trace) {
                show_xports();
            }
            svc_die();
        }
    }

    return (-1);
}
Ejemplo n.º 6
0
/*
 * The additional architecture-specific notes for Cell are various
 * context files in the spu context.
 *
 * This function iterates over all open file descriptors and sees
 * if they are a directory in spufs.  In that case we use spufs
 * internal functionality to dump them without needing to actually
 * open the files.
 */
static struct spu_context *coredump_next_context(int *fd)
{
	struct fdtable *fdt = files_fdtable(current->files);
	struct file *file;
	struct spu_context *ctx = NULL;

	for (; *fd < fdt->max_fds; (*fd)++) {
		if (!fd_is_open(*fd, fdt))
			continue;

		file = fcheck(*fd);

		if (!file || file->f_op != &spufs_context_fops)
			continue;

		ctx = SPUFS_I(file->f_dentry->d_inode)->i_ctx;
		if (ctx->flags & SPU_CREATE_NOSCHED)
			continue;

		break;
	}

	return ctx;
}