[PATCH 5/9] add a mode commandline option
william.jon.mccann at gmail.com
william.jon.mccann at gmail.com
Mon Feb 23 12:35:53 PST 2009
From: William Jon McCann <jmccann at redhat.com>
Initially supports modes: boot, shutdown. This allows the
progress cache to be loaded from the appropriate file.
---
src/main.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 126 insertions(+), 12 deletions(-)
diff --git a/src/main.c b/src/main.c
index 708191f..fe4df58 100644
--- a/src/main.c
+++ b/src/main.c
@@ -50,7 +50,13 @@
#define PLY_MAX_COMMAND_LINE_SIZE 512
#endif
-#define BOOT_DURATION_FILE PLYMOUTH_TIME_DIRECTORY "/boot-duration"
+#define BOOT_DURATION_FILE PLYMOUTH_TIME_DIRECTORY "/boot-duration"
+#define SHUTDOWN_DURATION_FILE PLYMOUTH_TIME_DIRECTORY "/shutdown-duration"
+
+enum {
+ PLY_MODE_BOOT,
+ PLY_MODE_SHUTDOWN
+} type;
typedef struct
{
@@ -81,6 +87,7 @@ typedef struct
ply_buffer_t *entry_buffer;
ply_command_parser_t *command_parser;
long ptmx;
+ int mode;
char kernel_command_line[PLY_MAX_COMMAND_LINE_SIZE];
uint32_t no_boot_log : 1;
@@ -241,8 +248,14 @@ on_progress_unpause (state_t *state)
static void
on_newroot (state_t *state,
- const char *root_dir)
+ const char *root_dir)
{
+ if (state->mode != PLY_MODE_BOOT)
+ {
+ ply_trace ("new root is only supported in boot mode ");
+ return;
+ }
+
ply_trace ("new root mounted at \"%s\", switching to it", root_dir);
chdir(root_dir);
chroot(".");
@@ -252,30 +265,114 @@ on_newroot (state_t *state,
ply_boot_splash_root_mounted (state->boot_splash);
}
+static const char *
+get_cache_file_for_mode (int mode)
+{
+ const char *filename;
+
+ switch (mode)
+ {
+ case PLY_MODE_BOOT:
+ filename = BOOT_DURATION_FILE;
+ break;
+ case PLY_MODE_SHUTDOWN:
+ filename = SHUTDOWN_DURATION_FILE;
+ break;
+ default:
+ fprintf (stderr, "Unhandled case in %s line %d\n", __FILE__, __LINE__);
+ abort ();
+ break;
+ }
+
+ return filename;
+}
+
+static const char *
+get_log_file_for_mode (int mode)
+{
+ const char *filename;
+
+ switch (mode)
+ {
+ case PLY_MODE_BOOT:
+ filename = PLYMOUTH_LOG_DIRECTORY "/boot.log";
+ break;
+ case PLY_MODE_SHUTDOWN:
+ filename = PLYMOUTH_LOG_DIRECTORY "/shutdown.log";
+ break;
+ default:
+ fprintf (stderr, "Unhandled case in %s line %d\n", __FILE__, __LINE__);
+ abort ();
+ break;
+ }
+
+ return filename;
+}
+
+static const char *
+get_log_spool_file_for_mode (int mode)
+{
+ const char *filename;
+
+ switch (mode)
+ {
+ case PLY_MODE_BOOT:
+ filename = PLYMOUTH_SPOOL_DIRECTORY "/boot.log";
+ break;
+ case PLY_MODE_SHUTDOWN:
+ filename = PLYMOUTH_SPOOL_DIRECTORY "/shutdown.log";
+ break;
+ default:
+ fprintf (stderr, "Unhandled case in %s line %d\n", __FILE__, __LINE__);
+ abort ();
+ break;
+ }
+
+ return filename;
+}
+
static void
spool_error (state_t *state)
{
+ const char *logfile;
+ const char *logspool;
+
ply_trace ("spooling error for viewer");
- unlink (PLYMOUTH_SPOOL_DIRECTORY "/boot.log");
+ logfile = get_log_file_for_mode (state->mode);
+ logspool = get_log_spool_file_for_mode (state->mode);
- ply_create_file_link (PLYMOUTH_LOG_DIRECTORY "/boot.log",
- PLYMOUTH_SPOOL_DIRECTORY "/boot.log");
+ unlink (logspool);
+
+ ply_create_file_link (logfile, logspool);
}
static void
-on_system_initialized (state_t *state)
+prepare_logging (state_t *state)
{
- ply_trace ("system now initialized, opening boot.log");
- state->system_initialized = true;
+ if (!state->system_initialized)
+ return;
+
+ if (state->session == NULL)
+ return;
+
ply_terminal_session_open_log (state->session,
- PLYMOUTH_LOG_DIRECTORY "/boot.log");
+ get_log_file_for_mode (state->mode));
if (state->number_of_errors > 0)
spool_error (state);
}
static void
+on_system_initialized (state_t *state)
+{
+ ply_trace ("system now initialized, opening log");
+ state->system_initialized = true;
+
+ prepare_logging (state);
+}
+
+static void
on_error (state_t *state)
{
ply_trace ("encountered error during boot up");
@@ -509,7 +606,7 @@ static void
on_quit (state_t *state,
bool retain_splash)
{
- ply_trace ("time to quit, closing boot.log");
+ ply_trace ("time to quit, closing log");
if (state->session != NULL)
ply_terminal_session_close_log (state->session);
ply_trace ("unloading splash");
@@ -1048,6 +1145,7 @@ main (int argc,
int exit_code;
bool should_help = false;
ply_daemon_handle_t *daemon_handle;
+ char *mode_string = NULL;
state.command_parser = ply_command_parser_new ("plymouthd", "Boot splash control server");
@@ -1055,6 +1153,7 @@ main (int argc,
ply_command_parser_add_options (state.command_parser,
"help", "This help message", PLY_COMMAND_OPTION_TYPE_FLAG,
+ "mode", "Mode is one of: boot, shutdown", PLY_COMMAND_OPTION_TYPE_STRING,
"attach-to-session", "pty_master_fd", PLY_COMMAND_OPTION_TYPE_LONG,
NULL);
@@ -1072,6 +1171,7 @@ main (int argc,
ply_command_parser_get_options (state.command_parser,
"help", &should_help,
+ "mode", &mode_string,
"attach-to-session", &state.ptmx,
NULL);
if (should_help)
@@ -1089,6 +1189,16 @@ main (int argc,
return 0;
}
+ if (mode_string != NULL)
+ {
+ if (strcmp (mode_string, "shutdown") == 0)
+ state.mode = PLY_MODE_SHUTDOWN;
+ else
+ state.mode = PLY_MODE_BOOT;
+
+ free (mode_string);
+ }
+
if (geteuid () != 0)
{
ply_error ("plymouthd must be run as root user");
@@ -1153,12 +1263,16 @@ main (int argc,
}
state.progress = ply_progress_new ();
- ply_progress_load_cache (state.progress, BOOT_DURATION_FILE);
+
+ ply_progress_load_cache (state.progress,
+ get_cache_file_for_mode (state.mode));
+
ply_trace ("entering event loop");
exit_code = ply_event_loop_run (state.loop);
ply_trace ("exited event loop");
- ply_progress_save_cache (state.progress, BOOT_DURATION_FILE);
+ ply_progress_save_cache (state.progress,
+ get_cache_file_for_mode (state.mode));
ply_boot_splash_free (state.boot_splash);
state.boot_splash = NULL;
--
1.6.1.3
More information about the plymouth
mailing list