From: Ray Strode Date: Wed, 13 Jun 2007 22:15:27 +0000 (-0400) Subject: change ply_create_scratch directory to be a two step, X-Git-Tag: 0.1.0~146 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e06a88f7363804b0ab8b548f29b06206f144272;p=thirdparty%2Fplymouth.git change ply_create_scratch directory to be a two step, ply_create_detachable_directory/ply_detach_directory process, because the former semantics couldn't actually work --- diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c index f98f21a6..0467b78e 100644 --- a/src/libply/ply-utils.c +++ b/src/libply/ply-utils.c @@ -659,21 +659,37 @@ ply_create_directory (const char *directory) } bool -ply_create_scratch_directory (const char *directory) +ply_create_detachable_directory (const char *directory) { - int dir_fd; + assert (directory != NULL); assert (directory[0] != '\0'); if (!ply_create_directory (directory)) return false; - if (mount ("none", directory, "ramfs", 0, NULL) < 0) + if (mount ("none", directory, "tmpfs", 0, NULL) < 0) return false; + return true; +} + +int +ply_detach_directory (const char *directory) +{ + int dir_fd; + dir_fd = open (directory, O_RDONLY); if (dir_fd < 0) + { + ply_save_errno (); + umount (directory); + ply_restore_errno (); + return dir_fd; + } + + if (umount2 (directory, PLY_SUPER_SECRET_LAZY_UNMOUNT_FLAG) < 0) { ply_save_errno (); umount (directory); @@ -681,16 +697,14 @@ ply_create_scratch_directory (const char *directory) return false; } - umount2 (directory, PLY_SUPER_SECRET_LAZY_UNMOUNT_FLAG); + rmdir (directory); - /* contents of directory will remain visible to process - * (and children) until the file descriptor is closed. - * - * We're leaking the file descriptor below, so it will - * remain around until the process exits + /* return a file descriptor to the directory because it's now been + * detached from the filesystem. The user can fchdir to this + * directory and work from it that way */ - return true; + return dir_fd; } static bool diff --git a/src/libply/ply-utils.h b/src/libply/ply-utils.h index ff545dd1..ec46fef2 100644 --- a/src/libply/ply-utils.h +++ b/src/libply/ply-utils.h @@ -69,8 +69,6 @@ void ply_restore_errno (void); bool ply_directory_exists (const char *dir); bool ply_file_exists (const char *file); -bool ply_file_system_is_mounted (const char *type, - const char *path); ply_module_handle_t *ply_open_module (const char *module_path); ply_module_function_t ply_module_look_up_function (ply_module_handle_t *handle, @@ -78,8 +76,10 @@ ply_module_function_t ply_module_look_up_function (ply_module_handle_t *handle, void ply_close_module (ply_module_handle_t *handle); bool ply_create_directory (const char *directory); -bool ply_create_scratch_directory (const char *directory); - +bool ply_create_detachable_directory (const char *directory); +int ply_detach_directory (const char *directory); +bool ply_copy_file (const char *source, const char *destination); +bool ply_copy_directory (const char *source, const char *destination); #endif #endif /* PLY_UTILS_H */