[PATCH 9/9] add way to detect if an option was set or not

william.jon.mccann at gmail.com william.jon.mccann at gmail.com
Mon Feb 23 12:35:57 PST 2009


From: William Jon McCann <jmccann at redhat.com>

---
 src/client/plymouth.c           |   28 ++++++++++++++--------------
 src/libply/ply-command-parser.c |   16 ++++++++++++----
 src/libply/ply-command-parser.h |    3 ++-
 src/main.c                      |   17 +++++++++++------
 4 files changed, 39 insertions(+), 25 deletions(-)

diff --git a/src/client/plymouth.c b/src/client/plymouth.c
index fd8f948..3463498 100644
--- a/src/client/plymouth.c
+++ b/src/client/plymouth.c
@@ -699,20 +699,20 @@ main (int    argc,
     }
 
   ply_command_parser_get_options (state.command_parser,
-                                  "help", &should_help,
-                                  "debug", &should_be_verbose,
-                                  "newroot", &chroot_dir,
-                                  "quit", &should_quit,
-                                  "ping", &should_ping,
-                                  "sysinit", &should_sysinit,
-                                  "show-splash", &should_show_splash,
-                                  "hide-splash", &should_hide_splash,
-                                  "message", &message,
-                                  "ask-for-password", &should_ask_for_password,
-                                  "ignore-keystroke", &ignore_keystroke,
-                                  "update", &status,
-                                  "wait", &should_wait,
-                                  "details", &report_error,
+                                  "help", &should_help, NULL,
+                                  "debug", &should_be_verbose, NULL,
+                                  "newroot", &chroot_dir, NULL,
+                                  "quit", &should_quit, NULL,
+                                  "ping", &should_ping, NULL,
+                                  "sysinit", &should_sysinit, NULL,
+                                  "show-splash", &should_show_splash, NULL,
+                                  "hide-splash", &should_hide_splash, NULL,
+                                  "message", &message, NULL,
+                                  "ask-for-password", &should_ask_for_password, NULL,
+                                  "ignore-keystroke", &ignore_keystroke, NULL,
+                                  "update", &status, NULL,
+                                  "wait", &should_wait, NULL,
+                                  "details", &report_error, NULL,
                                   NULL);
 
   if (should_help || argc < 2)
diff --git a/src/libply/ply-command-parser.c b/src/libply/ply-command-parser.c
index 5d77e00..1427e95 100644
--- a/src/libply/ply-command-parser.c
+++ b/src/libply/ply-command-parser.c
@@ -46,7 +46,7 @@ typedef struct
   char *name;
   char *description;
   ply_command_option_type_t type;
-
+  bool was_set;
   ply_command_option_result_t result;
 } ply_command_option_t;
 
@@ -473,6 +473,7 @@ ply_command_parser_get_options_for_command (ply_command_parser_t *parser,
                                             const char *option_name,
                                             va_list args)
 {
+  bool *option_was_set;
 
   assert (parser != NULL);
   assert (command != NULL);
@@ -533,6 +534,10 @@ ply_command_parser_get_options_for_command (ply_command_parser_t *parser,
             }
         }
 
+      option_was_set = va_arg (args, bool *);
+      if (option_was_set != NULL)
+        *option_was_set = option->was_set;
+
       option_name = va_arg (args, const char *);
     }
 }
@@ -540,7 +545,8 @@ ply_command_parser_get_options_for_command (ply_command_parser_t *parser,
 void
 ply_command_parser_get_options (ply_command_parser_t *parser,
                                 const char *option_name, /*
-                                void *      option_result */
+                                void *      option_result,
+                                bool *      option_was_set */
                                 ...)
 {
   va_list args;
@@ -557,7 +563,8 @@ void
 ply_command_parser_get_command_options (ply_command_parser_t *parser,
                                         const char *command_name,
                                         const char *option_name, /*
-                                        void *      option_result */
+                                        void *      option_result,
+                                        bool *      option_was_set */
                                         ...)
 {
   ply_command_t *command;
@@ -763,7 +770,8 @@ ply_command_read_option (ply_command_t *command,
 
   ply_list_remove_node (arguments, node);
 
-  ply_command_option_read_arguments (option, arguments);
+  if (ply_command_option_read_arguments (option, arguments))
+    option->was_set = true;
 
   return option;
 }
diff --git a/src/libply/ply-command-parser.h b/src/libply/ply-command-parser.h
index 805b518..446f87a 100644
--- a/src/libply/ply-command-parser.h
+++ b/src/libply/ply-command-parser.h
@@ -64,7 +64,8 @@ void ply_command_parser_get_options (ply_command_parser_t *parser,
 void ply_command_parser_get_command_options (ply_command_parser_t *parser,
                                              const char *command_name,
                                              const char *option_name, /*
-                                             void *      option_result */
+                                             void *      option_result,
+                                             bool *      option_was_set */
                                              ...);
 void ply_command_parser_stop_parsing_arguments (ply_command_parser_t *parser);
 
diff --git a/src/main.c b/src/main.c
index ce482ad..eacde88 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1154,6 +1154,8 @@ main (int    argc,
   bool should_help = false;
   bool no_daemon = false;
   bool debug = false;
+  bool was_set = false;
+  long attach_to_session;
   ply_daemon_handle_t *daemon_handle;
   char *mode_string = NULL;
 
@@ -1182,11 +1184,11 @@ main (int    argc,
     }
 
   ply_command_parser_get_options (state.command_parser,
-                                  "help", &should_help,
-                                  "mode", &mode_string,
-                                  "no-daemon", &no_daemon,
-                                  "debug", &debug,
-                                  "attach-to-session", &state.ptmx,
+                                  "help", &should_help, NULL,
+                                  "mode", &mode_string, NULL,
+                                  "no-daemon", &no_daemon, NULL,
+                                  "debug", &debug, NULL,
+                                  "attach-to-session", &attach_to_session, &was_set,
                                   NULL);
   if (should_help)
     {
@@ -1216,6 +1218,9 @@ main (int    argc,
       free (mode_string);
     }
 
+  if (was_set)
+    state.ptmx = attach_to_session;
+
   if (geteuid () != 0)
     {
       ply_error ("plymouthd must be run as root user");
@@ -1259,7 +1264,7 @@ main (int    argc,
 
   state.boot_buffer = ply_buffer_new ();
 
-  if (state.ptmx != 0)
+  if (state.ptmx != -1)
     {
       if (!attach_to_running_session (&state))
         {
-- 
1.6.1.3



More information about the plymouth mailing list