Skip to content

Commit

Permalink
Merge pull request #1653 from eriksjolund/remove-dead-code
Browse files Browse the repository at this point in the history
linux, utils: remove dead code crun_ensure_file*()
  • Loading branch information
giuseppe authored Jan 31, 2025
2 parents c332fe4 + 490d550 commit a029af2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/libcrun/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -1815,7 +1815,7 @@ create_missing_devs (libcrun_container_t *container, bool binds, libcrun_error_t

if (container->container_def->process && container->container_def->process->terminal)
{
ret = crun_ensure_file_at (devfd, "console", 0620, true, err);
ret = create_file_if_missing_at (devfd, "console", 0620, err);
if (UNLIKELY (ret < 0))
return ret;
}
Expand Down
37 changes: 5 additions & 32 deletions src/libcrun/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,17 @@ get_file_type (mode_t *mode, bool nofollow, const char *path)
}

int
create_file_if_missing_at (int dirfd, const char *file, libcrun_error_t *err)
create_file_if_missing_at (int dirfd, const char *file, mode_t mode, libcrun_error_t *err)
{
cleanup_close int fd_write = openat (dirfd, file, O_CLOEXEC | O_CREAT | O_WRONLY, 0700);
cleanup_close int fd_write = openat (dirfd, file, O_CLOEXEC | O_CREAT | O_WRONLY, mode);
if (fd_write < 0)
{
mode_t mode;
mode_t tmp_mode;
int ret;

/* On errors, check if the file already exists. */
ret = get_file_type_at (dirfd, &mode, false, file);
if (ret == 0 && S_ISREG (mode))
ret = get_file_type_at (dirfd, &tmp_mode, false, file);
if (ret == 0 && S_ISREG (tmp_mode))
return 0;

return crun_make_error (err, errno, "creating file `%s`", file);
Expand Down Expand Up @@ -627,33 +627,6 @@ crun_ensure_directory (const char *path, int mode, bool nofollow, libcrun_error_
return crun_ensure_directory_at (AT_FDCWD, path, mode, nofollow, err);
}

int
crun_ensure_file_at (int dirfd, const char *path, int mode, bool nofollow, libcrun_error_t *err)
{
cleanup_free char *tmp = xstrdup (path);
size_t len = strlen (tmp);
char *it = tmp + len - 1;
int ret;

while (*it != '/' && it > tmp)
it--;
if (it > tmp)
{
*it = '\0';
ret = crun_ensure_directory_at (dirfd, tmp, mode, nofollow, err);
if (UNLIKELY (ret < 0))
return ret;
*it = '/';
}
return create_file_if_missing_at (dirfd, tmp, err);
}

int
crun_ensure_file (const char *path, int mode, bool nofollow, libcrun_error_t *err)
{
return crun_ensure_file_at (AT_FDCWD, path, mode, nofollow, err);
}

static int
get_file_size (int fd, off_t *size)
{
Expand Down
6 changes: 1 addition & 5 deletions src/libcrun/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,8 @@ int write_file_at_with_flags (int dirfd, int flags, mode_t mode, const char *nam

int crun_ensure_directory (const char *path, int mode, bool nofollow, libcrun_error_t *err);

int crun_ensure_file (const char *path, int mode, bool nofollow, libcrun_error_t *err);

int crun_ensure_directory_at (int dirfd, const char *path, int mode, bool nofollow, libcrun_error_t *err);

int crun_ensure_file_at (int dirfd, const char *path, int mode, bool nofollow, libcrun_error_t *err);

int crun_safe_create_and_open_ref_at (bool dir, int dirfd, const char *dirpath, size_t dirpath_len, const char *path, int mode, libcrun_error_t *err);

int crun_safe_ensure_directory_at (int dirfd, const char *dirpath, size_t dirpath_len, const char *path, int mode,
Expand All @@ -287,7 +283,7 @@ int crun_dir_p_at (int dirfd, const char *path, bool nofollow, libcrun_error_t *

int detach_process ();

int create_file_if_missing_at (int dirfd, const char *file, libcrun_error_t *err);
int create_file_if_missing_at (int dirfd, const char *file, mode_t mode, libcrun_error_t *err);

int check_running_in_user_namespace (libcrun_error_t *err);

Expand Down

0 comments on commit a029af2

Please sign in to comment.