Send plymouth mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://lists.freedesktop.org/mailman/listinfo/plymouth
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of plymouth digest..."


Today's Topics:

   1. [PATCH 5/9] add a mode commandline option
      ([email protected])
   2. [PATCH 2/9] allow the progress cache file to be configurable
      ([email protected])
   3. [PATCH 1/9] improve the layout of the help output
      ([email protected])
   4. [PATCH 4/9] add command line parsing to daemon
      ([email protected])
   5. [PATCH 3/9] add support for long data types
      ([email protected])


----------------------------------------------------------------------

Message: 1
Date: Mon, 23 Feb 2009 15:35:53 -0500
From: [email protected]
Subject: [PATCH 5/9] add a mode commandline option
To: [email protected]
Cc: William Jon McCann <[email protected]>
Message-ID:
        <[email protected]>

From: William Jon McCann <[email protected]>

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



------------------------------

Message: 2
Date: Mon, 23 Feb 2009 15:35:50 -0500
From: [email protected]
Subject: [PATCH 2/9] allow the progress cache file to be configurable
To: [email protected]
Cc: William Jon McCann <[email protected]>
Message-ID:
        <[email protected]>

From: William Jon McCann <[email protected]>

This will enable using separate cache files for different plymouth modes.
---
 src/Makefile.am           |    1 +
 src/libply/ply-progress.c |   20 ++++++++++----------
 src/libply/ply-progress.h |    4 ++--
 src/main.c                |   10 ++++++----
 4 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 57c5a36..a905317 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,6 +5,7 @@ INCLUDES = -I$(top_srcdir)                                      
              \
            -I$(srcdir)                                                        \
            -DPLYMOUTH_LOG_DIRECTORY=\"$(localstatedir)/log\"                  \
            -DPLYMOUTH_SPOOL_DIRECTORY=\"$(localstatedir)/spool/plymouth\"     \
+           -DPLYMOUTH_TIME_DIRECTORY=\"$(localstatedir)/lib/plymouth/\"       \
            -DPLYMOUTH_LOGO_FILE=\"$(logofile)\"
 
 plymouthdbindir = $(plymouthdaemondir)
diff --git a/src/libply/ply-progress.c b/src/libply/ply-progress.c
index 9dca766..8dd1f10 100644
--- a/src/libply/ply-progress.c
+++ b/src/libply/ply-progress.c
@@ -46,8 +46,6 @@
 #define DEFAULT_BOOT_DURATION 60.0
 #endif
 
-#define BOOT_DURATION_FILE PLYMOUTH_TIME_DIRECTORY "/boot-duration"
-
 
 struct _ply_progress
 {
@@ -131,11 +129,12 @@ ply_progress_message_search_next (ply_list_t 
*message_list, double time)
 }
 
 void
-ply_progress_load_cache (ply_progress_t* progress)
+ply_progress_load_cache (ply_progress_t* progress,
+                         const char *filename)
 {
   FILE *fp;
-  
-  fp = fopen (BOOT_DURATION_FILE,"r"); 
+
+  fp = fopen (filename,"r");
   if (fp == NULL)
     return;
 
@@ -178,13 +177,14 @@ ply_progress_load_cache (ply_progress_t* progress)
 }
 
 void
-ply_progress_save_cache (ply_progress_t* progress)
+ply_progress_save_cache (ply_progress_t* progress,
+                         const char *filename)
 {
   FILE *fp;
   ply_list_node_t *node;
   double cur_time = ply_progress_get_time(progress);
-  
-  fp = fopen (BOOT_DURATION_FILE,"w");
+
+  fp = fopen (filename,"w");
   if (fp == NULL)
     return;
 
@@ -325,7 +325,7 @@ main (int    argc,
       printf("Time:%f   \t Percentage: %f%%\n", time, percent*100);
     }
   printf("Load cache\n");
-  ply_progress_load_cache (progress);
+  ply_progress_load_cache (progress, PLYMOUTH_TIME_DIRECTORY "/boot-duration");
 
   for (i=0; i<10; i++)
     {
@@ -336,7 +336,7 @@ main (int    argc,
       printf("Time:%f   \t Percentage: %f%% \tScalar:%f\n", time, percent*100, 
progress->scalar);
     }
   printf("Save and free cache\n");
-  ply_progress_save_cache (progress);
+  ply_progress_save_cache (progress, PLYMOUTH_TIME_DIRECTORY "/boot-duration");
   ply_progress_free(progress);
   return 0;
 }
diff --git a/src/libply/ply-progress.h b/src/libply/ply-progress.h
index 5e896db..f18c9b6 100644
--- a/src/libply/ply-progress.h
+++ b/src/libply/ply-progress.h
@@ -30,10 +30,10 @@ typedef struct _ply_progress ply_progress_t;
 ply_progress_t *ply_progress_new (void);
 ply_progress_t* ply_progress_new (void);
 void ply_progress_free (ply_progress_t* progress);
-void ply_progress_load_cache (ply_progress_t* progress);
+void ply_progress_load_cache (ply_progress_t* progress, const char *filename);
 double ply_progress_get_percentage (ply_progress_t* progress);
 double ply_progress_get_time (ply_progress_t* progress);
-void ply_progress_save_cache (ply_progress_t* progress);
+void ply_progress_save_cache (ply_progress_t* progress, const char *filename);
 void ply_progress_status_update (ply_progress_t* progress, const char  
*status);
 
 #endif /* PLY_PROGRESS_H */
diff --git a/src/main.c b/src/main.c
index fa612ed..d08b268 100644
--- a/src/main.c
+++ b/src/main.c
@@ -49,6 +49,8 @@
 #define PLY_MAX_COMMAND_LINE_SIZE 512
 #endif
 
+#define BOOT_DURATION_FILE PLYMOUTH_TIME_DIRECTORY "/boot-duration"
+
 typedef struct 
 {
   const char    *keys;
@@ -243,7 +245,7 @@ on_newroot (state_t    *state,
   chdir(root_dir);
   chroot(".");
   chdir("/");
-  ply_progress_load_cache (state->progress);
+  ply_progress_load_cache (state->progress, BOOT_DURATION_FILE);
   if (state->boot_splash != NULL)
     ply_boot_splash_root_mounted (state->boot_splash);
 }
@@ -1130,13 +1132,13 @@ main (int    argc,
     }
 
   state.progress = ply_progress_new ();
-  ply_progress_load_cache (state.progress);
+  ply_progress_load_cache (state.progress, BOOT_DURATION_FILE);
   ply_trace ("entering event loop");
   exit_code = ply_event_loop_run (state.loop);
   ply_trace ("exited event loop");
 
-  ply_progress_save_cache (state.progress);
-  
+  ply_progress_save_cache (state.progress, BOOT_DURATION_FILE);
+
   ply_boot_splash_free (state.boot_splash);
   state.boot_splash = NULL;
 
-- 
1.6.1.3



------------------------------

Message: 3
Date: Mon, 23 Feb 2009 15:35:49 -0500
From: [email protected]
Subject: [PATCH 1/9] improve the layout of the help output
To: [email protected]
Cc: William Jon McCann <[email protected]>
Message-ID:
        <[email protected]>

From: William Jon McCann <[email protected]>

Left align descriptions and group subcommands.
---
 src/libply/ply-command-parser.c |  124 ++++++++++++++++++++++++---------------
 1 files changed, 76 insertions(+), 48 deletions(-)

diff --git a/src/libply/ply-command-parser.c b/src/libply/ply-command-parser.c
index c6adf32..29d47fa 100644
--- a/src/libply/ply-command-parser.c
+++ b/src/libply/ply-command-parser.c
@@ -139,26 +139,37 @@ append_usage_line_to_buffer (ply_command_parser_t *parser,
 
   ply_buffer_append (buffer, "%s\n",
                      parser->main_command->description);
-  ply_buffer_append (buffer, "USAGE: %s", parser->main_command->name);
+  ply_buffer_append (buffer, "USAGE: %s [OPTION...]", 
parser->main_command->name);
 
-  option_node = ply_list_get_first_node (parser->main_command->options);
-  while (option_node != NULL)
-    {
-      ply_command_option_t *option;
+  if (ply_list_get_length (parser->available_subcommands) > 0)
+    ply_buffer_append (buffer, " [subcommand [options]...]\n");
+}
 
-      option = (ply_command_option_t *) ply_list_node_get_data (option_node);
-      ply_buffer_append (buffer, " [--%s%s] ", option->name,
-                         option->type == PLY_COMMAND_OPTION_TYPE_BOOLEAN?
-                         "={true|false}":
-                         option->type == PLY_COMMAND_OPTION_TYPE_STRING?
-                         "=<string>":
-                         option->type == PLY_COMMAND_OPTION_TYPE_INTEGER?
-                         "=<integer>": "");
-      option_node = ply_list_get_next_node (parser->main_command->options, 
option_node);
+static const char *
+get_type_string (int type)
+{
+  const char *option_type_string;
+
+  switch (type)
+    {
+    case PLY_COMMAND_OPTION_TYPE_FLAG:
+      option_type_string = "";
+      break;
+    case PLY_COMMAND_OPTION_TYPE_BOOLEAN:
+      option_type_string = "={true|false}";
+      break;
+    case PLY_COMMAND_OPTION_TYPE_STRING:
+      option_type_string = "=<string>";
+      break;
+    case PLY_COMMAND_OPTION_TYPE_INTEGER:
+      option_type_string = "=<integer>";
+      break;
+    default:
+      option_type_string = "";
+      break;
     }
 
-  if (ply_list_get_length (parser->available_subcommands) > 0)
-    ply_buffer_append (buffer, "[subcommand [options]...]\n");
+  return option_type_string;
 }
 
 static void
@@ -179,35 +190,21 @@ append_command_options_to_buffer (ply_command_parser_t 
*parser,
 
       option = (ply_command_option_t *) ply_list_node_get_data (option_node);
 
-      switch (option->type)
-        {
-          case PLY_COMMAND_OPTION_TYPE_FLAG:
-              option_type_string = "";
-              break;
-          case PLY_COMMAND_OPTION_TYPE_BOOLEAN:
-              option_type_string = "={true|false}";
-              break;
-          case PLY_COMMAND_OPTION_TYPE_STRING:
-              option_type_string = "=<string>";
-              break;
-          case PLY_COMMAND_OPTION_TYPE_INTEGER:
-              option_type_string = "=<integer>";
-              break;
-          default:
-              option_type_string = "";
-              break;
-        }
+      option_type_string = get_type_string (option->type);
+
+      option_width = command->longest_option_length + 2 -
+        (strlen(option->name) + strlen(option_type_string));
 
-      option_width = command->longest_option_length - strlen (option->name) +
-                     strlen ("={true|false}");
-      description_width = MAX (80 - 10 - command->longest_option_length -
-                               strlen ("--") - strlen ("={true|false}"), 0);
       ply_buffer_append (buffer,
-                         "%-10.10s--%s%-*.*s%*s\n",
-                         "", option->name, option_width, option_width,
-                         option_type_string,
-                         description_width,
-                         option->description);
+                         "  --%s%s",
+                         option->name,
+                         option_type_string);
+
+      ply_buffer_append (buffer, "%*s %s\n",
+                         option_width,
+                         "",
+                         option->description ? option->description : "");
+
       option_node = ply_list_get_next_node (command->options, option_node);
     }
 }
@@ -218,16 +215,30 @@ ply_command_parser_get_help_string (ply_command_parser_t 
*parser)
   ply_buffer_t *buffer;
   ply_list_node_t *command_node;
   char *help_string;
+  int longest_subcommand;
 
   buffer = ply_buffer_new ();
 
   append_usage_line_to_buffer (parser, buffer);
   ply_buffer_append (buffer, "\n");
+  ply_buffer_append (buffer, "Options:\n");
   append_command_options_to_buffer (parser, parser->main_command, buffer);
   ply_buffer_append (buffer, "\n");
 
   if (ply_list_get_length (parser->available_subcommands) > 0)
     ply_buffer_append (buffer, "Available subcommands:\n");
+
+  /* get longest subcommand */
+  longest_subcommand = -1;
+  command_node = ply_list_get_first_node (parser->available_subcommands);
+  while (command_node != NULL)
+    {
+      ply_command_t *command;
+      command = (ply_command_t *) ply_list_node_get_data (command_node);
+      longest_subcommand = MAX (longest_subcommand, (int)strlen 
(command->name));
+      command_node = ply_list_get_next_node (parser->available_subcommands,
+                                             command_node);
+    }
   command_node = ply_list_get_first_node (parser->available_subcommands);
   while (command_node != NULL)
     {
@@ -235,14 +246,29 @@ ply_command_parser_get_help_string (ply_command_parser_t 
*parser)
 
       command = (ply_command_t *) ply_list_node_get_data (command_node);
 
-      ply_buffer_append (buffer, "\n%s%*s%-*s\n\n",
+      ply_buffer_append (buffer, "  %s%*s %s\n",
                          command->name,
-                         (int)(80 - strlen (command->name) - strlen 
(command->description)),
+                         longest_subcommand + 2 - strlen (command->name),
                          "",
-                         (int) strlen (command->name),
                          command->description);
 
-      append_command_options_to_buffer (parser, command, buffer);
+      command_node = ply_list_get_next_node (parser->available_subcommands,
+                                             command_node);
+    }
+
+  command_node = ply_list_get_first_node (parser->available_subcommands);
+  while (command_node != NULL)
+    {
+      ply_command_t *command;
+
+      command = (ply_command_t *) ply_list_node_get_data (command_node);
+
+      if (ply_list_get_first_node (command->options) != NULL)
+        {
+          ply_buffer_append (buffer, "\nSubcommand Options (%s):\n", 
command->name);
+
+          append_command_options_to_buffer (parser, command, buffer);
+        }
 
       command_node = ply_list_get_next_node (parser->available_subcommands,
                                              command_node);
@@ -267,7 +293,9 @@ ply_command_add_option (ply_command_t *command,
   ply_list_append_data (command->options, option);
 
   command->longest_option_length = MAX (command->longest_option_length,
-                                        strlen (name));
+                                        strlen (name)
+                                        + 1
+                                        + strlen (get_type_string (type)));
 }
 
 static ply_command_option_t *
-- 
1.6.1.3



------------------------------

Message: 4
Date: Mon, 23 Feb 2009 15:35:52 -0500
From: [email protected]
Subject: [PATCH 4/9] add command line parsing to daemon
To: [email protected]
Cc: William Jon McCann <[email protected]>
Message-ID:
        <[email protected]>

From: William Jon McCann <[email protected]>

If for no other reason than to handle --help.
---
 src/main.c |   53 +++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/src/main.c b/src/main.c
index d08b268..708191f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -35,6 +35,7 @@
 
 #include <linux/kd.h>
 
+#include "ply-command-parser.h"
 #include "ply-boot-server.h"
 #include "ply-boot-splash.h"
 #include "ply-event-loop.h"
@@ -78,6 +79,7 @@ typedef struct
   ply_list_t *keystroke_triggers;
   ply_list_t *entry_triggers;
   ply_buffer_t *entry_buffer;
+  ply_command_parser_t *command_parser;
   long ptmx;
 
   char kernel_command_line[PLY_MAX_COMMAND_LINE_SIZE];
@@ -1044,26 +1046,47 @@ main (int    argc,
       .ptmx = -1,
   };
   int exit_code;
-  bool attach_to_session = false;
+  bool should_help = false;
   ply_daemon_handle_t *daemon_handle;
 
-  if (argc >= 2 && !strcmp(argv[1], "--attach-to-session"))
-      attach_to_session = true;
+  state.command_parser = ply_command_parser_new ("plymouthd", "Boot splash 
control server");
 
-  if (attach_to_session && argc == 3)
+  state.loop = ply_event_loop_new ();
+
+  ply_command_parser_add_options (state.command_parser,
+                                  "help", "This help message", 
PLY_COMMAND_OPTION_TYPE_FLAG,
+                                  "attach-to-session", "pty_master_fd", 
PLY_COMMAND_OPTION_TYPE_LONG,
+                                  NULL);
+
+  if (!ply_command_parser_parse_arguments (state.command_parser, state.loop, 
argv, argc))
     {
-      state.ptmx = strtol(argv[2], NULL, 0);
-      if ((state.ptmx == LONG_MIN || state.ptmx == LONG_MAX) && errno != 0)
-        {
-          ply_error ("%s: could not parse ptmx string \"%s\": %m", argv[0], 
argv[2]);
-          return EX_OSERR;
-        }
+      char *help_string;
+
+      help_string = ply_command_parser_get_help_string (state.command_parser);
+
+      ply_error ("%s", help_string);
+
+      free (help_string);
+      return EX_USAGE;
     }
 
-  if ((attach_to_session && argc != 3) || (attach_to_session && state.ptmx == 
-1))
+  ply_command_parser_get_options (state.command_parser,
+                                  "help", &should_help,
+                                  "attach-to-session", &state.ptmx,
+                                  NULL);
+  if (should_help)
     {
-      ply_error ("%s [--attach-to-session <pty_master_fd>]", argv[0]);
-      return EX_USAGE;
+      char *help_string;
+
+      help_string = ply_command_parser_get_help_string (state.command_parser);
+
+      if (argc < 2)
+        fprintf (stderr, "%s", help_string);
+      else
+        printf ("%s", help_string);
+
+      free (help_string);
+      return 0;
     }
 
   if (geteuid () != 0)
@@ -1086,8 +1109,6 @@ main (int    argc,
   signal (SIGABRT, on_crash);
   signal (SIGSEGV, on_crash);
 
-  state.loop = ply_event_loop_new ();
-
   /* before do anything we need to make sure we have a working
    * environment.
    */
@@ -1106,7 +1127,7 @@ main (int    argc,
 
   state.boot_buffer = ply_buffer_new ();
 
-  if (attach_to_session)
+  if (state.ptmx != 0)
     {
       if (!attach_to_running_session (&state))
         {
-- 
1.6.1.3



------------------------------

Message: 5
Date: Mon, 23 Feb 2009 15:35:51 -0500
From: [email protected]
Subject: [PATCH 3/9] add support for long data types
To: [email protected]
Cc: William Jon McCann <[email protected]>
Message-ID:
        <[email protected]>

From: William Jon McCann <[email protected]>

---
 src/libply/ply-command-parser.c |   37 +++++++++++++++++++++++++++++++++++++
 src/libply/ply-command-parser.h |    3 ++-
 2 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/src/libply/ply-command-parser.c b/src/libply/ply-command-parser.c
index 29d47fa..5d77e00 100644
--- a/src/libply/ply-command-parser.c
+++ b/src/libply/ply-command-parser.c
@@ -38,6 +38,7 @@ typedef union
   bool as_boolean;
   char *as_string;
   int as_integer;
+  int as_long;
 } ply_command_option_result_t;
 
 typedef struct
@@ -164,6 +165,9 @@ get_type_string (int type)
     case PLY_COMMAND_OPTION_TYPE_INTEGER:
       option_type_string = "=<integer>";
       break;
+    case PLY_COMMAND_OPTION_TYPE_LONG:
+      option_type_string = "=<long>";
+      break;
     default:
       option_type_string = "";
       break;
@@ -516,6 +520,16 @@ ply_command_parser_get_options_for_command 
(ply_command_parser_t *parser,
                   *option_result = option->result.as_integer;
                 }
               break;
+
+              case PLY_COMMAND_OPTION_TYPE_LONG:
+                {
+                  long *option_result;
+
+                  option_result = va_arg (args, long *);
+
+                  *option_result = option->result.as_long;
+                }
+              break;
             }
         }
 
@@ -678,6 +692,29 @@ ply_command_option_read_arguments (ply_command_option_t 
*option,
          ply_list_remove_node (arguments, node);
          return true;
         }
+
+      case PLY_COMMAND_OPTION_TYPE_LONG:
+        {
+         char *end;
+         long argument_as_long;
+
+         if (argument[0] == '\0')
+           return false;
+
+         argument_as_long = strtol (argument, &end, 0);
+
+         if (*end != '\0')
+           return false;
+
+         if ((argument_as_long == LONG_MIN
+              || argument_as_long == LONG_MAX) &&
+             errno == ERANGE)
+           return false;
+
+         option->result.as_long = argument_as_long;
+         ply_list_remove_node (arguments, node);
+         return true;
+        }
     }
 
   return option;
diff --git a/src/libply/ply-command-parser.h b/src/libply/ply-command-parser.h
index 38078e4..805b518 100644
--- a/src/libply/ply-command-parser.h
+++ b/src/libply/ply-command-parser.h
@@ -35,7 +35,8 @@ typedef enum
   PLY_COMMAND_OPTION_TYPE_FLAG = 0,
   PLY_COMMAND_OPTION_TYPE_BOOLEAN,
   PLY_COMMAND_OPTION_TYPE_STRING,
-  PLY_COMMAND_OPTION_TYPE_INTEGER
+  PLY_COMMAND_OPTION_TYPE_INTEGER,
+  PLY_COMMAND_OPTION_TYPE_LONG
 } ply_command_option_type_t;
 
 #ifndef PLY_HIDE_FUNCTION_DECLARATIONS
-- 
1.6.1.3



------------------------------

_______________________________________________
plymouth mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/plymouth


End of plymouth Digest, Vol 5, Issue 1
**************************************

Reply via email to