Skip to content

Commit a029af2

Browse files
authored
Merge pull request #1653 from eriksjolund/remove-dead-code
linux, utils: remove dead code crun_ensure_file*()
2 parents c332fe4 + 490d550 commit a029af2

File tree

3 files changed

+7
-38
lines changed

3 files changed

+7
-38
lines changed

src/libcrun/linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1815,7 +1815,7 @@ create_missing_devs (libcrun_container_t *container, bool binds, libcrun_error_t
18151815

18161816
if (container->container_def->process && container->container_def->process->terminal)
18171817
{
1818-
ret = crun_ensure_file_at (devfd, "console", 0620, true, err);
1818+
ret = create_file_if_missing_at (devfd, "console", 0620, err);
18191819
if (UNLIKELY (ret < 0))
18201820
return ret;
18211821
}

src/libcrun/utils.c

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,17 @@ get_file_type (mode_t *mode, bool nofollow, const char *path)
234234
}
235235

236236
int
237-
create_file_if_missing_at (int dirfd, const char *file, libcrun_error_t *err)
237+
create_file_if_missing_at (int dirfd, const char *file, mode_t mode, libcrun_error_t *err)
238238
{
239-
cleanup_close int fd_write = openat (dirfd, file, O_CLOEXEC | O_CREAT | O_WRONLY, 0700);
239+
cleanup_close int fd_write = openat (dirfd, file, O_CLOEXEC | O_CREAT | O_WRONLY, mode);
240240
if (fd_write < 0)
241241
{
242-
mode_t mode;
242+
mode_t tmp_mode;
243243
int ret;
244244

245245
/* On errors, check if the file already exists. */
246-
ret = get_file_type_at (dirfd, &mode, false, file);
247-
if (ret == 0 && S_ISREG (mode))
246+
ret = get_file_type_at (dirfd, &tmp_mode, false, file);
247+
if (ret == 0 && S_ISREG (tmp_mode))
248248
return 0;
249249

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

630-
int
631-
crun_ensure_file_at (int dirfd, const char *path, int mode, bool nofollow, libcrun_error_t *err)
632-
{
633-
cleanup_free char *tmp = xstrdup (path);
634-
size_t len = strlen (tmp);
635-
char *it = tmp + len - 1;
636-
int ret;
637-
638-
while (*it != '/' && it > tmp)
639-
it--;
640-
if (it > tmp)
641-
{
642-
*it = '\0';
643-
ret = crun_ensure_directory_at (dirfd, tmp, mode, nofollow, err);
644-
if (UNLIKELY (ret < 0))
645-
return ret;
646-
*it = '/';
647-
}
648-
return create_file_if_missing_at (dirfd, tmp, err);
649-
}
650-
651-
int
652-
crun_ensure_file (const char *path, int mode, bool nofollow, libcrun_error_t *err)
653-
{
654-
return crun_ensure_file_at (AT_FDCWD, path, mode, nofollow, err);
655-
}
656-
657630
static int
658631
get_file_size (int fd, off_t *size)
659632
{

src/libcrun/utils.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,8 @@ int write_file_at_with_flags (int dirfd, int flags, mode_t mode, const char *nam
267267

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

270-
int crun_ensure_file (const char *path, int mode, bool nofollow, libcrun_error_t *err);
271-
272270
int crun_ensure_directory_at (int dirfd, const char *path, int mode, bool nofollow, libcrun_error_t *err);
273271

274-
int crun_ensure_file_at (int dirfd, const char *path, int mode, bool nofollow, libcrun_error_t *err);
275-
276272
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);
277273

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

288284
int detach_process ();
289285

290-
int create_file_if_missing_at (int dirfd, const char *file, libcrun_error_t *err);
286+
int create_file_if_missing_at (int dirfd, const char *file, mode_t mode, libcrun_error_t *err);
291287

292288
int check_running_in_user_namespace (libcrun_error_t *err);
293289

0 commit comments

Comments
 (0)