]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
Allow details plugin to work without window
authorRay Strode <rstrode@redhat.com>
Tue, 19 Aug 2008 18:32:33 +0000 (14:32 -0400)
committerRay Strode <rstrode@redhat.com>
Tue, 19 Aug 2008 18:44:13 +0000 (14:44 -0400)
If it's NULL send a NOANSWER reply to any
questions asked by the client and make the
client handle NOANSWER by asking the user
itself.

src/client/ply-boot-client.c
src/client/plymouth.c
src/ply-boot-protocol.h
src/ply-boot-server.c
src/ply-boot-splash.c
src/splash-plugins/details/plugin.c

index 2b1d075ae33e0bde4906396e6f43ecbc43abef4e..c6b307514d04d122d41115d76d588e5950de3e13 100644 (file)
@@ -282,6 +282,10 @@ ply_boot_client_process_incoming_replies (ply_boot_client_t *client)
 
       ((ply_boot_client_answer_handler_t) request->handler) (request->user_data, answer, client);
     }
+  else if (memcmp (byte, PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NO_ANSWER, sizeof (uint8_t)) == 0)
+    {
+      ((ply_boot_client_answer_handler_t) request->handler) (request->user_data, NULL, client);
+    }
   else
     goto out;
 
index c343378710da347f9faa878edd9bc4aba72ed56c..33deb2435a89310cb3b443353610e5e441e43e82 100644 (file)
@@ -102,9 +102,16 @@ answer_via_command (answer_state_t *answer_state,
   pid_t pid;
   int command_input_sender_fd, command_input_receiver_fd;
 
+  /* answer may be NULL which means,
+   * "The daemon can't ask the user questions,
+   *   do all the prompting from the client"
+   */
+
   gave_answer = false;
-  if (!ply_open_unidirectional_pipe (&command_input_sender_fd,
-                                     &command_input_receiver_fd))  return false;
+  if (answer != NULL &&
+    !ply_open_unidirectional_pipe (&command_input_sender_fd,
+                                   &command_input_receiver_fd))
+    return false;
 
   pid = fork (); 
 
@@ -114,21 +121,29 @@ answer_via_command (answer_state_t *answer_state,
   if (pid == 0)
     {
       char **args;
-      close (command_input_sender_fd);
       args = split_string (answer_state->command, ' ');
-      dup2 (command_input_receiver_fd, STDIN_FILENO);
+      if (answer != NULL)
+        {
+          close (command_input_sender_fd);
+          dup2 (command_input_receiver_fd, STDIN_FILENO);
+        }
       execvp (args[0], args); 
       ply_trace ("could not run command: %m");
       _exit (127);
     }
-  close (command_input_receiver_fd);
 
-  if (write (command_input_sender_fd, answer, strlen (answer)) < 0)
-    goto out;
+  if (answer != NULL)
+    {
+      close (command_input_receiver_fd);
+
+      if (write (command_input_sender_fd, answer, strlen (answer)) < 0)
+        goto out;
+    }
 
   gave_answer = true;
 out:
-  close (command_input_sender_fd);
+  if (answer != NULL)
+    close (command_input_sender_fd);
   waitpid (pid, exit_status, 0); 
 
   return gave_answer;
index 594064a9810635f7b4cb7dbc5fdb1309b9473b91..852b9d9d9c465c2493a1f64fca71558b1c772e80 100644 (file)
@@ -35,6 +35,7 @@
 #define PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ACK "\x6"
 #define PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NAK "\x15"
 #define PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ANSWER "\x2"
+#define PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NO_ANSWER "\x5"
 
 #endif /* PLY_BOOT_PROTOCOL_H */
 /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */
index 29f402ed2b117496fd3435e905f18a9902612b23..6e39f86434f7d0bd8206658c2630dc7c962c477b 100644 (file)
@@ -197,21 +197,34 @@ ply_boot_connection_on_password_answer (ply_boot_connection_t *connection,
 
   size_t size;
 
-  /* FIXME: support up to 4 billion
+  /* splash plugin isn't able to ask for password,
+   * punt to client
    */
-  if (strlen (password) > 255)
-    ply_error ("password to long to fit in buffer");
-
-  size = (uint8_t) strlen (password);
-
-  if (!ply_write (connection->fd,
-                  PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ANSWER,
-                  strlen (PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ANSWER)) ||
-      !ply_write (connection->fd,
-                  &size, sizeof (uint8_t)) ||
-      !ply_write (connection->fd,
-                  password, size))
-    ply_error ("could not write bytes: %m");
+  if (password == NULL)
+    {
+      if (!ply_write (connection->fd,
+                      PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NO_ANSWER,
+                      strlen (PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NO_ANSWER)))
+        ply_error ("could not write bytes: %m");
+    }
+  else
+    {
+      /* FIXME: support up to 4 billion
+      */
+      if (strlen (password) > 255)
+          ply_error ("password to long to fit in buffer");
+
+      size = (uint8_t) strlen (password);
+
+      if (!ply_write (connection->fd,
+                      PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ANSWER,
+                      strlen (PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ANSWER)) ||
+          !ply_write (connection->fd,
+                      &size, sizeof (uint8_t)) ||
+          !ply_write (connection->fd,
+                      password, size))
+          ply_error ("could not write bytes: %m");
+    }
 
   ply_answer_free (answer);
 }
index 8ccaf6c41dab2590b84bdbbee3dc52fe5bbcaf27..3fd63318ca3fc4863a6dd3b4f42fccb5e4108594 100644 (file)
@@ -226,7 +226,7 @@ ply_boot_splash_ask_for_password (ply_boot_splash_t *splash,
 
   if (splash->plugin_interface->ask_for_password == NULL)
     {
-      ply_answer_with_string (answer, "");
+      ply_answer_unknown (answer);
       return;
     }
 
index 3bfb14d670a092dbbf31010be02422a2ea45fb45..ae52b15217f5bf3e67a473a1d6086fdd1cabaf5b 100644 (file)
 #define CLEAR_LINE_SEQUENCE "\033[2K\r\n"
 #define BACKSPACE "\b\033[0K"
 
+void ask_for_password (ply_boot_splash_plugin_t *plugin,
+                       ply_answer_t             *answer);
+
+ply_boot_splash_plugin_interface_t *ply_boot_splash_plugin_get_interface (void);
 struct _ply_boot_splash_plugin
 {
   ply_event_loop_t *loop;
@@ -136,17 +140,26 @@ show_splash_screen (ply_boot_splash_plugin_t *plugin,
 
   assert (plugin != NULL);
 
-  ply_window_set_mode (window, PLY_WINDOW_MODE_TEXT);
+  if (window != NULL)
+    {
+      ply_boot_splash_plugin_interface_t *interface;
+
+      ply_window_set_mode (window, PLY_WINDOW_MODE_TEXT);
 
-  ply_window_set_keyboard_input_handler (window,
-                                         (ply_window_keyboard_input_handler_t)
-                                         on_keyboard_input, plugin);
-  ply_window_set_backspace_handler (window,
-                                    (ply_window_backspace_handler_t)
-                                    on_backspace, plugin);
-  ply_window_set_enter_handler (window,
-                                (ply_window_enter_handler_t)
-                                on_enter, plugin);
+      ply_window_set_keyboard_input_handler (window,
+                                             (ply_window_keyboard_input_handler_t)
+                                             on_keyboard_input, plugin);
+      ply_window_set_backspace_handler (window,
+                                        (ply_window_backspace_handler_t)
+                                        on_backspace, plugin);
+      ply_window_set_enter_handler (window,
+                                    (ply_window_enter_handler_t)
+                                    on_enter, plugin);
+
+      interface = ply_boot_splash_plugin_get_interface ();
+
+      interface->ask_for_password = ask_for_password;
+    }
 
   plugin->loop = loop;
 
@@ -223,7 +236,6 @@ ply_boot_splash_plugin_get_interface (void)
       .update_status = update_status,
       .on_boot_output = on_boot_output,
       .hide_splash_screen = hide_splash_screen,
-      .ask_for_password = ask_for_password,
     };
 
   return &plugin_interface;