Get rid of everything about directory switching and PLY_WORKING_DIRECTORY.

calculate-0.9.5
Peter Jones 16 years ago committed by Peter Jones
parent cb560ad782
commit 1836d8b52c

@ -55,7 +55,6 @@ struct _ply_terminal_session
uint32_t is_running : 1;
uint32_t console_is_redirected : 1;
uint32_t change_root_to_current_directory : 1;
};
static bool ply_terminal_session_open_console (ply_terminal_session_t *session);
@ -111,12 +110,6 @@ ply_terminal_session_execute (ply_terminal_session_t *session,
if (!ply_terminal_session_open_console (session))
return false;
if (session->change_root_to_current_directory)
{
if (chroot (".") < 0)
return false;
}
if (look_in_path)
execvp (session->argv[0], session->argv);
else
@ -138,7 +131,6 @@ ply_terminal_session_new (const char * const *argv)
session->logger = ply_logger_new ();
session->is_running = false;
session->console_is_redirected = false;
session->change_root_to_current_directory = false;
return session;
}
@ -245,9 +237,6 @@ ply_terminal_session_run (ply_terminal_session_t *session,
should_redirect_console =
(flags & PLY_TERMINAL_SESSION_FLAGS_REDIRECT_CONSOLE) != 0;
session->change_root_to_current_directory =
(flags & PLY_TERMINAL_SESSION_FLAGS_CHANGE_ROOT_TO_CURRENT_DIRECTORY) != 0;
ply_trace ("creating terminal device");
if (!ply_terminal_create_device (session->terminal))
return false;
@ -323,9 +312,6 @@ ply_terminal_session_attach (ply_terminal_session_t *session,
should_redirect_console =
(flags & PLY_TERMINAL_SESSION_FLAGS_REDIRECT_CONSOLE) != 0;
session->change_root_to_current_directory =
(flags & PLY_TERMINAL_SESSION_FLAGS_CHANGE_ROOT_TO_CURRENT_DIRECTORY) != 0;
ply_terminal_set_fd(session->terminal, ptmx);
if (should_redirect_console)

@ -45,7 +45,6 @@ typedef enum
PLY_TERMINAL_SESSION_FLAGS_RUN_IN_PARENT = 0x1,
PLY_TERMINAL_SESSION_FLAGS_LOOK_IN_PATH = 0x2,
PLY_TERMINAL_SESSION_FLAGS_REDIRECT_CONSOLE = 0x4,
PLY_TERMINAL_SESSION_FLAGS_CHANGE_ROOT_TO_CURRENT_DIRECTORY = 0x8,
} ply_terminal_session_flags_t;
#ifndef PLY_HIDE_FUNCTION_DECLARATIONS

@ -751,216 +751,6 @@ ply_create_directory (const char *directory)
return true;
}
static bool
ply_copy_subdirectory (const char *subdirectory,
const char *parent,
const char *destination)
{
char *source, *target;
source = NULL;
asprintf (&source, "%s/%s", parent, subdirectory);
target = NULL;
asprintf (&target, "%s/%s", destination, subdirectory);
if (!ply_copy_directory (source, target))
{
ply_save_errno ();
free (source);
free (target);
ply_restore_errno ();
return false;
}
free (source);
free (target);
return true;
}
bool
ply_copy_file (const char *source,
const char *destination)
{
char buffer[4096];
int source_fd, destination_fd;
struct stat file_info;
bool file_copied;
file_copied = false;
source_fd = -1;
destination_fd = -1;
ply_trace ("opening source '%s'", source);
source_fd = open (source, O_RDONLY | O_NOFOLLOW);
if (source_fd < 0)
goto out;
ply_trace ("stating fd %d", source_fd);
if (fstat (source_fd, &file_info) < 0)
goto out;
ply_trace ("opening dest '%s'", destination);
destination_fd = open (destination, O_WRONLY | O_NOFOLLOW | O_CREAT,
file_info.st_mode);
if (destination_fd < 0)
goto out;
while ("we want to copy the file")
{
size_t bytes_read;
bytes_read = read (source_fd, buffer, sizeof (buffer));
if (bytes_read < 0)
{
if (errno == EINTR)
continue;
goto out;
}
else if (bytes_read == 0)
break;
if (!ply_write (destination_fd, buffer, bytes_read))
goto out;
}
file_copied = true;
out:
ply_save_errno ();
close (source_fd);
close (destination_fd);
ply_restore_errno ();
return file_copied;
}
static bool
ply_copy_file_in_directory (const char *filename,
const char *parent,
const char *destination)
{
char *source, *target;
ply_trace ("copying '%s' in '%s' to '%s'", filename, parent, destination);
source = NULL;
asprintf (&source, "%s/%s", parent, filename);
target = NULL;
asprintf (&target, "%s/%s", destination, filename);
if (!ply_copy_file (source, target))
{
ply_save_errno ();
free (source);
free (target);
ply_restore_errno ();
return false;
}
free (source);
free (target);
return true;
}
bool
ply_copy_directory (const char *source,
const char *destination)
{
DIR *dir;
struct dirent *entry;
char *full_path;
assert (source != NULL);
assert (source[0] != '\0');
assert (destination != NULL);
assert (destination[0] != '\0');
dir = opendir (source);
if (dir == NULL)
return false;
if (!ply_create_directory (destination))
return false;
while ((entry = readdir (dir)) != NULL)
{
if (strcmp (entry->d_name, ".") == 0)
continue;
if (strcmp (entry->d_name, "..") == 0)
continue;
full_path = NULL;
asprintf (&full_path, "%s/%s", source, entry->d_name);
if (ply_directory_exists (full_path))
{
if (!ply_copy_subdirectory (entry->d_name, source, destination))
{
ply_save_errno ();
free (full_path);
ply_restore_errno ();
return false;
}
}
else if (ply_file_exists (full_path))
{
if (!ply_copy_file_in_directory (entry->d_name, source, destination))
{
ply_save_errno ();
free (full_path);
ply_restore_errno ();
return false;
}
}
free (full_path);
}
assert (entry == NULL);
closedir (dir);
return true;
}
bool
ply_unmount_filesystem (const char *directory)
{
if (umount2 (directory, PLY_SUPER_SECRET_LAZY_UNMOUNT_FLAG) < 0)
return false;
return true;
}
bool ply_mount_tmpfs (const char *directory)
{
assert (directory != NULL);
assert (directory[0] != '\0');
if (mount ("none", directory, "tmpfs", 0, NULL) < 0)
return false;
return true;
}
bool
ply_move_mount (const char *source, const char *destination)
{
int rc;
ply_trace ("moving mount at \"%s\" to \"%s\"", source, destination);
if (mount(source, destination, NULL, MS_MOVE, NULL) < 0)
{
ply_trace("mount(\"%s\", \"%s\", NULL, MS_MOVE, NULL): error: %m", source, destination);
return false;
}
return true;
}
ply_daemon_handle_t *
ply_create_daemon (void)
{

@ -83,11 +83,6 @@ 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_copy_file (const char *source, const char *destination);
bool ply_copy_directory (const char *source, const char *destination);
bool ply_unmount_filesystem (const char *directory);
bool ply_move_mount (const char *source, const char *destination);
bool ply_mount_tmpfs (const char *directory);
ply_daemon_handle_t *ply_create_daemon (void);
bool ply_detach_daemon (ply_daemon_handle_t *handle,

@ -22,7 +22,6 @@
#include "config.h"
#include <sys/stat.h>
#include <sys/mount.h>
#include <sys/types.h>
#include <limits.h>
#include <dirent.h>
@ -40,10 +39,6 @@
#include "ply-terminal-session.h"
#include "ply-utils.h"
#ifndef PLY_WORKING_DIRECTORY
#define PLY_WORKING_DIRECTORY "/var/run/plymouth"
#endif
#ifndef PLY_MAX_COMMAND_LINE_SIZE
#define PLY_MAX_COMMAND_LINE_SIZE 512
#endif
@ -111,11 +106,9 @@ static void
on_system_initialized (state_t *state)
{
ply_trace ("system now initialized, ready to mount root filesystem");
mknod ("/dev/root", 0600 | S_IFBLK, makedev (253, 0));
mount("/dev/root", "/sysroot", "ext3", 0, NULL);
ply_terminal_session_open_log (state->session,
"/sysroot/var/log/bootmessages.log");
ply_trace ("system now initialized, preparing for root filesystem switch");
chdir("/sysroot");
chroot(".");
}
static void
@ -140,16 +133,15 @@ on_show_splash (state_t *state)
static void
on_quit (state_t *state)
{
ply_trace ("time to quit, closing log");
ply_trace ("time to quit, writing boot.log");
ply_terminal_session_open_log (state->session,
"/var/log/boot.log");
ply_terminal_session_close_log (state->session);
ply_trace ("hiding splash");
if (state->boot_splash != NULL)
ply_boot_splash_hide (state->boot_splash);
ply_trace ("exiting event loop");
ply_event_loop_exit (state->loop, 0);
ply_trace ("unmounting temporary filesystem mounts");
ply_unmount_filesystem (PLY_WORKING_DIRECTORY);
}
static ply_boot_server_t *
@ -248,7 +240,6 @@ attach_to_running_session (state_t *state)
flags = 0;
flags |= PLY_TERMINAL_SESSION_FLAGS_REDIRECT_CONSOLE;
flags |= PLY_TERMINAL_SESSION_FLAGS_CHANGE_ROOT_TO_CURRENT_DIRECTORY;
ply_trace ("creating terminal session for current terminal");
session = ply_terminal_session_new (NULL);
@ -274,45 +265,6 @@ attach_to_running_session (state_t *state)
return session;
}
static bool
create_working_directory (state_t *state)
{
ply_trace ("creating working directory '%s'",
PLY_WORKING_DIRECTORY);
if (!ply_create_detachable_directory (PLY_WORKING_DIRECTORY))
return false;
ply_trace ("changing to working directory");
if (chdir (PLY_WORKING_DIRECTORY) < 0)
return false;
ply_trace ("creating proc subdirectory");
if (!ply_create_directory ("proc"))
return false;
ply_trace ("creating dev subdirectory");
if (!ply_create_directory ("dev"))
return false;
ply_trace ("creating dev/pts subdirectory");
if (!ply_create_directory ("dev/pts"))
return false;
ply_trace ("creating usr/share/plymouth subdirectory");
if (!ply_create_directory ("usr/share/plymouth"))
return false;
ply_trace ("creating " PLYMOUTH_PLUGIN_PATH " subdirectory");
if (!ply_create_directory (PLYMOUTH_PLUGIN_PATH + 1))
return false;
ply_trace ("creating sysroot subdirectory");
if (!ply_create_directory ("sysroot"))
return false;
return true;
}
static bool
get_kernel_command_line (state_t *state)
{
@ -338,44 +290,6 @@ get_kernel_command_line (state_t *state)
return true;
}
static bool
copy_data_files (state_t *state)
{
char *logo_dir, *p;
ply_trace ("copying data files");
if (!ply_copy_directory ("/usr/share/plymouth",
"usr/share/plymouth"))
return false;
ply_trace ("copied data files");
ply_trace ("copying plugins");
if (!ply_copy_directory (PLYMOUTH_PLUGIN_PATH,
PLYMOUTH_PLUGIN_PATH + 1))
return false;
ply_trace ("copying logo");
logo_dir = strdup (PLYMOUTH_LOGO_FILE);
p = strrchr (logo_dir, '/');
if (p != NULL)
*p = '\0';
if (!ply_create_directory (logo_dir + 1))
{
free (logo_dir);
return false;
}
free (logo_dir);
if (!ply_copy_file (PLYMOUTH_LOGO_FILE,
PLYMOUTH_LOGO_FILE + 1))
return false;
ply_trace ("copied plugins files");
return true;
}
static void
check_verbosity (state_t *state)
{
@ -439,11 +353,6 @@ static bool
initialize_environment (state_t *state)
{
ply_trace ("initializing minimal work environment");
if (!create_working_directory (state))
return false;
if (!copy_data_files (state))
return false;
if (!get_kernel_command_line (state))
return false;
@ -501,14 +410,11 @@ main (int argc,
state.loop = ply_event_loop_new ();
/* before do anything we need to make sure we have a working
* environment. /proc needs to be mounted and certain devices need
* to be accessible (like the framebuffer device, pseudoterminal
* devices, etc)
* environment.
*/
if (!initialize_environment (&state))
{
ply_error ("could not setup basic operating environment: %m");
ply_list_directory (PLY_WORKING_DIRECTORY);
ply_detach_daemon (daemon_handle, EX_OSERR);
return EX_OSERR;
}

Loading…
Cancel
Save