diff options
| author | Ray Strode <rstrode@redhat.com> | 2007-11-03 23:30:16 -0400 |
|---|---|---|
| committer | Ray Strode <rstrode@redhat.com> | 2007-11-03 23:30:16 -0400 |
| commit | 92c2bf0f4bd8aa575689b96276bec6b65d330d10 (patch) | |
| tree | 55fb493100ef13b42a51e2b1b1adb538c28ced87 /src | |
| parent | 0bd33efd8b9417736b295edc4724c8d04a0ba2cb (diff) | |
| parent | ab84465fa71f47044784d0d4f7d90c8016a7994e (diff) | |
| download | plymouth-92c2bf0f4bd8aa575689b96276bec6b65d330d10.tar.gz plymouth-92c2bf0f4bd8aa575689b96276bec6b65d330d10.tar.xz plymouth-92c2bf0f4bd8aa575689b96276bec6b65d330d10.zip | |
Merge branch 'main-refactor'
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile.am | 2 | ||||
| -rw-r--r-- | src/libply/ply-logger.h | 1 | ||||
| -rw-r--r-- | src/libply/ply-terminal-session.c | 38 | ||||
| -rw-r--r-- | src/libply/ply-terminal-session.h | 8 | ||||
| -rw-r--r-- | src/libply/ply-terminal.c | 20 | ||||
| -rw-r--r-- | src/libply/ply-utils.c | 87 | ||||
| -rw-r--r-- | src/libply/ply-utils.h | 2 | ||||
| -rw-r--r-- | src/libply/tests/Makefile.am | 2 | ||||
| -rw-r--r-- | src/libply/tests/ply-copy-dir-test.am | 11 | ||||
| -rw-r--r-- | src/libply/tests/ply-copy-dir-test.c | 74 | ||||
| -rw-r--r-- | src/libply/tests/ply-copy-test.am | 11 | ||||
| -rw-r--r-- | src/libply/tests/ply-copy-test.c | 58 | ||||
| -rw-r--r-- | src/libply/tests/ply-terminal-test.am | 2 | ||||
| -rw-r--r-- | src/main.c | 230 | ||||
| -rw-r--r-- | src/rhgb-client/Makefile.am | 11 | ||||
| -rw-r--r-- | src/splash-plugins/fedora-fade-in/fedora-fade-in.c | 63 | ||||
| -rw-r--r-- | src/tests/Makefile.am | 2 |
17 files changed, 570 insertions, 52 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 16eb948..c5a3f9e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,7 +5,7 @@ INCLUDES = -I$(top_srcdir) \ plymouthbindir = $(libexecdir)/plymouth plymouthbin_PROGRAMS = plymouth -plymouth_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLYMOUTH_PLUGIN_PATH=\"$(prefix)/\$${LIB}/plymouth/\" +plymouth_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLYMOUTH_PLUGIN_PATH=\"$(libdir)/plymouth/\" plymouth_LDADD = $(PLYMOUTH_LIBS) libply/libply.la plymouth_SOURCES = \ ply-boot-protocol.h \ diff --git a/src/libply/ply-logger.h b/src/libply/ply-logger.h index ad62236..eca2fbf 100644 --- a/src/libply/ply-logger.h +++ b/src/libply/ply-logger.h @@ -87,6 +87,7 @@ do \ "|pid: %d| <%.4f> [%s] %45.45s:" format "\n", \ _pid, _timestamp, __FILE__, __func__, ##args); \ ply_logger_flush (logger); \ + errno = _old_errno; \ } \ } \ while (0) diff --git a/src/libply/ply-terminal-session.c b/src/libply/ply-terminal-session.c index 22da67a..f0dc4e7 100644 --- a/src/libply/ply-terminal-session.c +++ b/src/libply/ply-terminal-session.c @@ -49,11 +49,12 @@ struct _ply_terminal_session ply_event_loop_t *loop; char **argv; - ply_terminal_session_done_handler_t done_handler; - void *done_handler_user_data; + ply_terminal_session_done_handler_t done_handler; + void *done_handler_user_data; 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); @@ -109,6 +110,12 @@ 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 @@ -132,6 +139,7 @@ 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; } @@ -220,6 +228,7 @@ ply_terminal_session_unredirect_console (ply_terminal_session_t *session) bool ply_terminal_session_run (ply_terminal_session_t *session, ply_terminal_session_flags_t flags, + ply_terminal_session_begin_handler_t begin_handler, ply_terminal_session_done_handler_t done_handler, void *user_data) { @@ -236,22 +245,36 @@ 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; + ply_trace ("done creating terminal device"); + if (should_redirect_console) + ply_trace ("redirecting system console to terminal device"); if (should_redirect_console && !ply_terminal_session_redirect_console (session)) { + ply_save_errno (); ply_terminal_destroy_device (session->terminal); + ply_restore_errno (); return false; } + if (should_redirect_console) + ply_trace ("done redirecting system console to terminal device"); + ply_trace ("creating subprocess"); pid = fork (); if (pid < 0) { + ply_save_errno (); ply_terminal_session_unredirect_console (session); ply_terminal_destroy_device (session->terminal); + ply_restore_errno (); return false; } @@ -266,6 +289,14 @@ ply_terminal_session_run (ply_terminal_session_t *session, return true; } + if (begin_handler != NULL) + { + ply_trace ("running 'begin handler'"); + begin_handler (user_data, session); + ply_trace ("ran 'begin handler'"); + } + + ply_trace ("beginning session"); ply_terminal_session_execute (session, look_in_path); _exit (errno); @@ -421,7 +452,8 @@ main (int argc, ply_terminal_session_attach_to_event_loop (session, loop); if (!ply_terminal_session_run (session, flags, - (ply_terminal_session_done_handler_t) + (ply_terminal_session_begin_handler_t) NULL, + (ply_terminal_session_done_handler_t) on_finished, loop)) { perror ("could not start terminal session"); diff --git a/src/libply/ply-terminal-session.h b/src/libply/ply-terminal-session.h index 3a35a45..d30d436 100644 --- a/src/libply/ply-terminal-session.h +++ b/src/libply/ply-terminal-session.h @@ -29,6 +29,10 @@ #include "ply-event-loop.h" typedef struct _ply_terminal_session ply_terminal_session_t; + +typedef void (* ply_terminal_session_begin_handler_t) + (void *user_data, ply_terminal_session_t *session); + typedef void (* ply_terminal_session_done_handler_t) (void *user_data, ply_terminal_session_t *session); @@ -37,7 +41,8 @@ typedef enum PLY_TERMINAL_SESSION_FLAGS_NONE = 0x0, 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_REDIRECT_CONSOLE = 0x4, + PLY_TERMINAL_SESSION_FLAGS_CHANGE_ROOT_TO_CURRENT_DIRECTORY = 0x8, } ply_terminal_session_flags_t; #ifndef PLY_HIDE_FUNCTION_DECLARATIONS @@ -48,6 +53,7 @@ void ply_terminal_session_attach_to_event_loop (ply_terminal_session_t *session, ply_event_loop_t *loop); bool ply_terminal_session_run (ply_terminal_session_t *session, ply_terminal_session_flags_t flags, + ply_terminal_session_begin_handler_t begin_handler, ply_terminal_session_done_handler_t done_handler, void *user_data); int ply_terminal_session_get_fd (ply_terminal_session_t *session); diff --git a/src/libply/ply-terminal.c b/src/libply/ply-terminal.c index b0ca9d9..b6dc64c 100644 --- a/src/libply/ply-terminal.c +++ b/src/libply/ply-terminal.c @@ -36,6 +36,7 @@ #include <sys/types.h> #include <unistd.h> +#include "ply-logger.h" #include "ply-utils.h" struct _ply_terminal @@ -72,31 +73,36 @@ ply_terminal_create_device (ply_terminal_t *terminal) assert (terminal != NULL); assert (!ply_terminal_has_device (terminal)); -#if 0 + ply_trace ("opening device '/dev/ptmx'"); terminal->fd = posix_openpt (O_RDWR | O_NOCTTY); -#endif - terminal->fd = open ("/dev/ptmx", O_RDWR | O_NOCTTY); if (terminal->fd < 0) return false; + ply_trace (" opened device '/dev/ptmx'"); + ply_trace ("creating pseudoterminal"); if (grantpt (terminal->fd) < 0) { - saved_errno = errno; + ply_save_errno (); + ply_trace ("could not create psuedoterminal: %m"); ply_terminal_destroy_device (terminal); - errno = saved_errno; + ply_restore_errno (); return false; } + ply_trace ("done creating pseudoterminal"); + ply_trace ("unlocking pseudoterminal"); if (unlockpt (terminal->fd) < 0) { - saved_errno = errno; + ply_save_errno (); ply_terminal_destroy_device (terminal); - errno = saved_errno; + ply_restore_errno (); return false; } + ply_trace ("unlocked pseudoterminal"); terminal->name = strdup (ptsname (terminal->fd)); + ply_trace ("pseudoterminal '%s' ready for action", terminal->name); return true; } diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c index 0467b78..58a3862 100644 --- a/src/libply/ply-utils.c +++ b/src/libply/ply-utils.c @@ -42,6 +42,8 @@ #include <dlfcn.h> +#include "ply-logger.h" + #ifndef PLY_OPEN_FILE_DESCRIPTORS_DIR #define PLY_OPEN_FILE_DESCRIPTORS_DIR "/proc/self/fd" #endif @@ -569,6 +571,44 @@ ply_file_exists (const char *file) return S_ISREG (file_info.st_mode); } +void +ply_list_directory (const char *path) +{ + DIR *dir; + struct dirent *entry; + static int level = 0; + + dir = opendir (path); + + if (dir == NULL) + return; + + if (level > 5) + return; + + int index = 0; + while ((entry = readdir (dir)) != NULL) + { + char *subdir; + + index++; + + if (index > 10) + break; + + subdir = NULL; + asprintf (&subdir, "%s/%s", path, entry->d_name); + ply_error ("%s ", subdir); + level++; + if (entry->d_name[0] != '.') + ply_list_directory (subdir); + level--; + free (subdir); + } + + closedir (dir); +} + ply_module_handle_t * ply_open_module (const char *module_path) { @@ -624,10 +664,14 @@ ply_create_directory (const char *directory) assert (directory[0] != '\0'); if (ply_directory_exists (directory)) - return true; + { + ply_trace ("directory '%s' already exists", directory); + return true; + } if (ply_file_exists (directory)) { + ply_trace ("file '%s' is in the way", directory); errno = EEXIST; return false; } @@ -636,22 +680,27 @@ ply_create_directory (const char *directory) { char *parent_directory; char *last_path_component; - bool parent_is_created; + bool is_created; - parent_is_created = false; + is_created = errno == EEXIST; if (errno == ENOENT) { parent_directory = strdup (directory); last_path_component = strrchr (parent_directory, '/'); *last_path_component = '\0'; - parent_is_created = ply_create_directory (parent_directory); + + ply_trace ("parent directory '%s' doesn't exist, creating it first", parent_directory); + if (ply_create_directory (parent_directory) + && ((mkdir (directory, 0755) == 0) || errno == EEXIST)) + is_created = true; ply_save_errno (); free (parent_directory); ply_restore_errno (); + } - return parent_is_created; + return is_created; } @@ -665,6 +714,7 @@ ply_create_detachable_directory (const char *directory) assert (directory != NULL); assert (directory[0] != '\0'); + ply_trace ("trying to create directory '%s'", directory); if (!ply_create_directory (directory)) return false; @@ -689,14 +739,13 @@ ply_detach_directory (const char *directory) return dir_fd; } - if (umount2 (directory, PLY_SUPER_SECRET_LAZY_UNMOUNT_FLAG) < 0) + if (!ply_unmount_filesystem (directory)) { ply_save_errno (); umount (directory); ply_restore_errno (); return false; } - rmdir (directory); /* return a file descriptor to the directory because it's now been @@ -746,14 +795,18 @@ ply_copy_file (const char *source, 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); @@ -781,19 +834,22 @@ ply_copy_file (const char *source, 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_direcetory (const char *filename, - const char *parent, - const char *destination) +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); @@ -855,7 +911,7 @@ ply_copy_directory (const char *source, } else if (ply_file_exists (full_path)) { - if (!ply_copy_file_in_direcetory (entry->d_name, source, destination)) + if (!ply_copy_file_in_directory (entry->d_name, source, destination)) { ply_save_errno (); free (full_path); @@ -873,4 +929,13 @@ ply_copy_directory (const char *source, return true; } +bool +ply_unmount_filesystem (const char *directory) +{ + if (umount2 (directory, PLY_SUPER_SECRET_LAZY_UNMOUNT_FLAG) < 0) + return false; + + return true; +} + /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/libply/ply-utils.h b/src/libply/ply-utils.h index ec46fef..91d01ca 100644 --- a/src/libply/ply-utils.h +++ b/src/libply/ply-utils.h @@ -69,6 +69,7 @@ void ply_restore_errno (void); bool ply_directory_exists (const char *dir); bool ply_file_exists (const char *file); +void ply_list_directory (const char *dir); 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, @@ -80,6 +81,7 @@ 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); +bool ply_unmount_filesystem (const char *directory); #endif #endif /* PLY_UTILS_H */ diff --git a/src/libply/tests/Makefile.am b/src/libply/tests/Makefile.am index e4ecfe6..58a26ef 100644 --- a/src/libply/tests/Makefile.am +++ b/src/libply/tests/Makefile.am @@ -11,6 +11,8 @@ include $(srcdir)/ply-terminal-session-test.am include $(srcdir)/ply-logger-test.am include $(srcdir)/ply-list-test.am include $(srcdir)/ply-event-loop-test.am +include $(srcdir)/ply-copy-test.am +include $(srcdir)/ply-copy-dir-test.am noinst_PROGRAMS = $(TESTS) diff --git a/src/libply/tests/ply-copy-dir-test.am b/src/libply/tests/ply-copy-dir-test.am new file mode 100644 index 0000000..2d97937 --- /dev/null +++ b/src/libply/tests/ply-copy-dir-test.am @@ -0,0 +1,11 @@ +TESTS += ply-copy-dir-test + +ply_copy_dir_test_CFLAGS = $(PLYMOUTH_CFLAGS) +ply_copy_dir_test_LDADD = $(PLYMOUTH_LIBS) + +ply_copy_dir_test_SOURCES = \ + $(srcdir)/../ply-logger.h \ + $(srcdir)/../ply-logger.c \ + $(srcdir)/../ply-utils.h \ + $(srcdir)/../ply-utils.c \ + $(srcdir)/ply-copy-dir-test.c diff --git a/src/libply/tests/ply-copy-dir-test.c b/src/libply/tests/ply-copy-dir-test.c new file mode 100644 index 0000000..75f0e1e --- /dev/null +++ b/src/libply/tests/ply-copy-dir-test.c @@ -0,0 +1,74 @@ +/* ply-copy-dir-test.c - tests some of the copy utility functions + * + * Copyright (C) 2007 Red Hat, Inc. + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by: Ray Strode <rstrode@redhat.com> + */ +#include "config.h" + +#include <stdbool.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> + +#include "ply-utils.h" + +bool +test_dir_copy (void) +{ + int dir_fd; + + if (!ply_create_directory ("test-dir-copy-source")) + return false; + + system ("cp ../* test-dir-copy-source"); + + if (!ply_create_directory ("test-dir-copy-dest")) + return false; + + if (!ply_copy_directory ("test-dir-copy-source", "test-dir-copy-dest")) + return false; + + if (!ply_create_detachable_directory ("/foo/test-dir-copy-scratch")) + return false; + + if (!ply_copy_directory ("test-dir-copy-dest", "/foo/test-dir-copy-scratch")) + return false; + + system ("ls /foo/test-dir-copy-scratch"); + + dir_fd = ply_detach_directory ("/foo/test-dir-copy-scratch"); + + if (fchdir (dir_fd) != 0) + return false; + + system ("ls"); + + return true; +} + +int +main (int argc, + char **argv) +{ + if (!test_dir_copy ()) + return 1; + + return 0; +} +/* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/libply/tests/ply-copy-test.am b/src/libply/tests/ply-copy-test.am new file mode 100644 index 0000000..3da1b7b --- /dev/null +++ b/src/libply/tests/ply-copy-test.am @@ -0,0 +1,11 @@ +TESTS += ply-copy-test + +ply_copy_test_CFLAGS = $(PLYMOUTH_CFLAGS) +ply_copy_test_LDADD = $(PLYMOUTH_LIBS) + +ply_copy_test_SOURCES = \ + $(srcdir)/../ply-logger.h \ + $(srcdir)/../ply-logger.c \ + $(srcdir)/../ply-utils.h \ + $(srcdir)/../ply-utils.c \ + $(srcdir)/ply-copy-test.c diff --git a/src/libply/tests/ply-copy-test.c b/src/libply/tests/ply-copy-test.c new file mode 100644 index 0000000..76f36ae --- /dev/null +++ b/src/libply/tests/ply-copy-test.c @@ -0,0 +1,58 @@ +/* ply-copy-test.c - tests some of the copy utility functions + * + * Copyright (C) 2007 Red Hat, Inc. + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by: Ray Strode <rstrode@redhat.com> + */ +#include "config.h" + +#include <stdbool.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> + +#include "ply-utils.h" + +bool +test_file_copy (void) +{ + bool file_is_copied; + + if (!ply_copy_file ("../ply-utils.c", "./ply-utils.c")) + return false; + + file_is_copied = system ("diff -u ../ply-utils.c ./ply-utils.c") == 0; + + unlink ("./ply-utils.c"); + + return file_is_copied; +} + +int +main (int argc, + char **argv) +{ + if (!test_file_copy ()) + { + fprintf (stderr, "could not complete test: %m"); + return 1; + } + + return 0; +} +/* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/libply/tests/ply-terminal-test.am b/src/libply/tests/ply-terminal-test.am index 66f3c41..9262413 100644 --- a/src/libply/tests/ply-terminal-test.am +++ b/src/libply/tests/ply-terminal-test.am @@ -4,6 +4,8 @@ ply_terminal_test_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLY_TERMINAL_ENABLE_TEST ply_terminal_test_LDADD = $(PLYMOUTH_LIBS) ply_terminal_test_SOURCES = \ + $(srcdir)/../ply-logger.h \ + $(srcdir)/../ply-logger.c \ $(srcdir)/../ply-utils.h \ $(srcdir)/../ply-utils.c \ $(srcdir)/../ply-terminal.h \ @@ -38,15 +38,33 @@ #include "ply-terminal-session.h" #include "ply-utils.h" +#ifndef PLY_WORKING_DIRECTORY +#define PLY_WORKING_DIRECTORY "/var/run/plymouth" +#endif + typedef struct { ply_event_loop_t *loop; ply_boot_server_t *boot_server; ply_boot_splash_t *boot_splash; ply_terminal_session_t *session; + int original_root_dir_fd; } state_t; static void +on_session_start (state_t *state) +{ + ply_trace ("changing to original root fs"); + + if (fchdir (state->original_root_dir_fd) < 0) + { + ply_trace ("Could not change to original root directory " + "to start session: %m"); + return; + } +} + +static void on_session_finished (state_t *state) { ply_log ("\nSession finished...exiting logger\n"); @@ -75,9 +93,16 @@ static void on_quit (state_t *state) { ply_terminal_session_close_log (state->session); - umount ("/sysroot"); ply_boot_splash_hide (state->boot_splash); ply_event_loop_exit (state->loop, 0); + + fchdir (state->original_root_dir_fd); + chroot ("."); + ply_unmount_filesystem (PLY_WORKING_DIRECTORY "/sysroot"); + ply_unmount_filesystem (PLY_WORKING_DIRECTORY "/sysroot"); + ply_unmount_filesystem (PLY_WORKING_DIRECTORY "/proc"); + ply_unmount_filesystem (PLY_WORKING_DIRECTORY "/dev/pts"); + ply_unmount_filesystem (PLY_WORKING_DIRECTORY); } static ply_boot_server_t * @@ -109,10 +134,14 @@ start_boot_splash (state_t *state, { ply_boot_splash_t *splash; - mknod ("/dev/fb", 0600 | S_IFCHR, makedev (29, 0)); + ply_trace ("Loading boot splash plugin '%s'", + module_path); splash = ply_boot_splash_new (module_path); + + ply_trace ("attaching plugin to event loop"); ply_boot_splash_attach_to_event_loop (splash, state->loop); + ply_trace ("showing plugin"); if (!ply_boot_splash_show (splash)) { ply_save_errno (); @@ -135,11 +164,17 @@ spawn_session (state_t *state, flags |= PLY_TERMINAL_SESSION_FLAGS_RUN_IN_PARENT; flags |= PLY_TERMINAL_SESSION_FLAGS_LOOK_IN_PATH; flags |= PLY_TERMINAL_SESSION_FLAGS_REDIRECT_CONSOLE; + flags |= PLY_TERMINAL_SESSION_FLAGS_CHANGE_ROOT_TO_CURRENT_DIRECTORY; + ply_trace ("opening terminal session for '%s'", argv[0]); session = ply_terminal_session_new ((const char * const *) argv); + ply_trace ("attaching terminal session to event loop"); ply_terminal_session_attach_to_event_loop (session, state->loop); + ply_trace ("running '%s'", argv[0]); if (!ply_terminal_session_run (session, flags, + (ply_terminal_session_begin_handler_t) + on_session_start, (ply_terminal_session_done_handler_t) on_session_finished, state)) { @@ -152,6 +187,166 @@ spawn_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 +change_to_working_directory (state_t *state) +{ + ply_trace ("changing to working directory"); + + state->original_root_dir_fd = open ("/", O_RDONLY); + + if (state->original_root_dir_fd < 0) + return false; + + if (chdir (PLY_WORKING_DIRECTORY) < 0) + return false; + + if (chroot (".") < 0) + return false; + + ply_trace ("now successfully in working directory"); + return true; +} + +static bool +mount_proc_filesystem (state_t *state) +{ + ply_trace ("mounting proc filesystem"); + if (mount ("none", PLY_WORKING_DIRECTORY "/proc", "proc", 0, NULL) < 0) + return false; + + open (PLY_WORKING_DIRECTORY "/proc/.", O_RDWR); + + ply_trace ("mounted proc filesystem"); + return true; +} + +static bool +create_device_nodes (state_t *state) +{ + ply_trace ("creating device nodes"); + + if (mknod ("./dev/root", 0600 | S_IFBLK, makedev (253, 0)) < 0) + return false; + + if (mknod ("./dev/null", 0600 | S_IFCHR, makedev (1, 3)) < 0) + return false; + + if (mknod ("./dev/console", 0600 | S_IFCHR, makedev (5, 1)) < 0) + return false; + + if (mknod ("./dev/tty", 0600 | S_IFCHR, makedev (5, 0)) < 0) + return false; + + if (mknod ("./dev/tty0", 0600 | S_IFCHR, makedev (4, 0)) < 0) + return false; + + if (mknod ("./dev/ptmx", 0600 | S_IFCHR, makedev (5, 2)) < 0) + return false; + + if (mknod ("./dev/fb", 0600 | S_IFCHR, makedev (29, 0)) < 0) + return false; + + ply_trace ("created device nodes"); + return true; +} + +static bool +mount_devpts_filesystem (state_t *state) +{ + ply_trace ("mounting devpts filesystem"); + if (mount ("none", PLY_WORKING_DIRECTORY "/dev/pts", "devpts", 0, + "gid=5,mode=620") < 0) + return false; + + open (PLY_WORKING_DIRECTORY "/dev/pts/.", O_RDWR); + + ply_trace ("mounted devpts filesystem"); + return true; +} + +static bool +copy_data_files (state_t *state) +{ + 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 ("copied plugins files"); + + return true; +} + +static bool +initialize_environment (state_t *state) +{ + ply_trace ("initializing minimal work environment"); + if (!create_working_directory (state)) + return false; + + if (!create_device_nodes (state)) + return false; + + if (!copy_data_files (state)) + return false; + + if (!mount_proc_filesystem (state)) + return false; + + if (!mount_devpts_filesystem (state)) + return false; + + if (!change_to_working_directory (state)) + return false; + + ply_trace ("initialized minimal work environment"); + return true; +} + int main (int argc, char **argv) @@ -165,7 +360,30 @@ main (int argc, return EX_USAGE; } + ply_toggle_tracing (); + 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) + */ + if (!initialize_environment (&state)) + { + ply_error ("could not setup basic operating environment: %m"); + ply_list_directory (PLY_WORKING_DIRECTORY); + return EX_OSERR; + } + + state.session = spawn_session (&state, argv + 1); + + if (state.session == NULL) + { + ply_error ("could not run '%s': %m", argv[1]); + return EX_UNAVAILABLE; + } + state.boot_server = start_boot_server (&state); if (state.boot_server == NULL) @@ -183,14 +401,6 @@ main (int argc, return EX_UNAVAILABLE; } - state.session = spawn_session (&state, argv + 1); - - if (state.session == NULL) - { - ply_error ("could not run '%s': %m", argv[1]); - return EX_UNAVAILABLE; - } - exit_code = ply_event_loop_run (state.loop); ply_terminal_session_free (state.session); diff --git a/src/rhgb-client/Makefile.am b/src/rhgb-client/Makefile.am index 39c5024..8cad7df 100644 --- a/src/rhgb-client/Makefile.am +++ b/src/rhgb-client/Makefile.am @@ -1,12 +1,11 @@ -SUBDIRS = tests INCLUDES = -I$(top_srcdir) \ - -I$(srcdir)/../libply \ - -I$(srcdir)/.. \ + -I$(top_srcdir)/src \ + -I$(top_srcdir)/src/libply \ -I$(srcdir) +rhgb_clientdir = $(bindir) +rhgb_client_PROGRAMS = rhgb-client -bin_PROGRAMS = rhgb-client - -rhgb_client_CFLAGS = $(PLYMOUTH_CFLAGS) +rhgb_client_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLYMOUTH_PLUGIN_PATH=\"$(prefix)/\$${LIB}/plymouth/\" rhgb_client_LDADD = $(PLYMOUTH_LIBS) ../libply/libply.la rhgb_client_SOURCES = \ $(srcdir)/../ply-boot-protocol.h \ diff --git a/src/splash-plugins/fedora-fade-in/fedora-fade-in.c b/src/splash-plugins/fedora-fade-in/fedora-fade-in.c index ada73db..924e064 100644 --- a/src/splash-plugins/fedora-fade-in/fedora-fade-in.c +++ b/src/splash-plugins/fedora-fade-in/fedora-fade-in.c @@ -41,10 +41,12 @@ #include "ply-boot-splash-plugin.h" #include "ply-event-loop.h" #include "ply-list.h" +#include "ply-logger.h" #include "ply-frame-buffer.h" #include "ply-image.h" #include "ply-utils.h" + #include <linux/kd.h> #ifndef FRAMES_PER_SECOND @@ -224,15 +226,6 @@ animate_at_time (ply_boot_splash_plugin_t *plugin, star = (star_t *) ply_list_node_get_data (node); next_node = ply_list_get_next_node (plugin->stars, node); - if (((star->x >= logo_area.x) - && (star->x + star_area.width <= logo_area.x + logo_area.width)) - && ((star->y >= logo_area.y) - && (star->y + star_area.height <= logo_area.y + logo_area.height))) - { - node = next_node; - continue; - } - star_area.x = star->x; star_area.y = star->y; @@ -366,18 +359,23 @@ show_splash_screen (ply_boot_splash_plugin_t *plugin) assert (plugin->logo_image != NULL); assert (plugin->frame_buffer != NULL); + ply_trace ("loading logo image"); if (!ply_image_load (plugin->logo_image)) return false; + ply_trace ("loading star image"); if (!ply_image_load (plugin->star_image)) return false; + ply_trace ("opening frame buffer"); if (!ply_frame_buffer_open (plugin->frame_buffer)) return false; + ply_trace ("opening console"); if (!open_console (plugin)) return false; + ply_trace ("settings graphics mode"); if (!set_graphics_mode (plugin)) { ply_save_errno (); @@ -391,6 +389,7 @@ show_splash_screen (ply_boot_splash_plugin_t *plugin) (ply_event_handler_t) on_interrupt, plugin); + ply_trace ("starting boot animation"); start_animation (plugin); return true; @@ -399,16 +398,56 @@ show_splash_screen (ply_boot_splash_plugin_t *plugin) static void add_star (ply_boot_splash_plugin_t *plugin) { - ply_frame_buffer_area_t area; + ply_frame_buffer_area_t area, logo_area; star_t *star; int x, y; + int width, height; + ply_list_node_t *node; assert (plugin != NULL); + ply_frame_buffer_get_size (plugin->frame_buffer, &logo_area); + width = ply_image_get_width (plugin->logo_image); + height = ply_image_get_height (plugin->logo_image); + logo_area.x = (logo_area.width / 2) - (width / 2); + logo_area.y = (logo_area.height / 2) - (height / 2); + logo_area.width = width; + logo_area.height = height; + ply_frame_buffer_get_size (plugin->frame_buffer, &area); + width = ply_image_get_width (plugin->star_image); + height = ply_image_get_height (plugin->star_image); + + node = NULL; + do + { + x = rand () % area.width; + y = rand () % area.height; + + if (((x + width >= logo_area.x) + && (x <= logo_area.x + logo_area.width)) + && ((y + height >= logo_area.y) + && (y <= logo_area.y + logo_area.height))) + continue; + + node = ply_list_get_first_node (plugin->stars); + while (node != NULL) + { + ply_list_node_t *next_node; + + star = (star_t *) ply_list_node_get_data (node); + next_node = ply_list_get_next_node (plugin->stars, node); + + if (((x + width >= star->x) + && (x <= star->x + width)) + && ((y + height >= star->y) + && (y <= star->y + height))) + break; + + node = next_node; + } - x = rand () % area.width; - y = rand () % area.height; + } while (node != NULL); star = star_new (x, y, (double) ((rand () % 50) + 1)); ply_list_append_data (plugin->stars, star); diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index 3cc1429..7fc5eef 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -3,7 +3,7 @@ INCLUDES = \ -I$(srcdir)/.. \ -I$(srcdir)/../libply \ -I$(srcdir) -TESTS = +TESTS = include $(srcdir)/ply-boot-server-test.am include $(srcdir)/ply-boot-splash-test.am |
