]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
add start of a program to eat a sessions output
authorRay Strode <rstrode@redhat.com>
Wed, 23 May 2007 18:29:14 +0000 (14:29 -0400)
committerRay Strode <rstrode@redhat.com>
Wed, 23 May 2007 18:29:14 +0000 (14:29 -0400)
src/Makefile.am
src/main.c

index feef70ccbe44c6cd84cf061a430a3ad8b4b86bf9..267f46dbb93a5864fca81534cf2c3f23cf3b1a91 100644 (file)
@@ -4,12 +4,19 @@ INCLUDES = -I$(top_srcdir)                                                    \
 
 plymouth_CFLAGS =
 plymouth_LDADD = 
-plymouth_SOURCES = ply-utils.h                                                \
-                   ply-utils.c                                                \
+plymouth_SOURCES =                                                            \
                    ply-list.h                                                 \
                    ply-list.c                                                 \
+                   ply-logger.h                                               \
+                   ply-logger.c                                               \
                    ply-event-loop.h                                           \
                    ply-event-loop.c                                           \
+                  ply-terminal.h                                             \
+                  ply-terminal.c                                             \
+                  ply-terminal-session.h                                     \
+                  ply-terminal-session.c                                     \
+                  ply-utils.h                                                \
+                   ply-utils.c                                                \
                    main.c
 
 noinst_PROGRAMS = plymouth
index d7a5823f09b7ad800607dd32bb3b16b28383965a..01c825d407569dc55ab70c4e95fdc2a331ad0d1d 100644 (file)
@@ -1,7 +1,6 @@
-/* main.c - graphical boot splash screen
+/* main.c - boot messages monitor
  *
  * Copyright (C) 2007 Red Hat, Inc
- * All rights reserved.
  *
  * This file is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published
  *
  * Written by: Ray Strode <rstrode@redhat.com>
  */
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <sysexits.h>
+
+#include "ply-event-loop.h"
+#include "ply-logger.h"
+#include "ply-terminal-session.h"
+#include "ply-utils.h"
+
+typedef struct
+{
+  ply_event_loop_t *loop;
+  ply_terminal_session_t *session;
+} state_t;
+
+static void
+on_session_finished (state_t *state)
+{
+  ply_flush_log ();
+  ply_event_loop_exit (state->loop, 0);
+} 
+
+static ply_terminal_session_t *
+spawn_session (state_t  *state, 
+               char    **argv)
+{
+  ply_terminal_session_t *session;
+  ply_terminal_session_flags_t flags;
+
+  flags = 0;
+  flags |= PLY_TERMINAL_SESSION_FLAGS_RUN_IN_PARENT;
+  flags |= PLY_TERMINAL_SESSION_FLAGS_LOOK_IN_PATH;
+
+  session = ply_terminal_session_new ((const char * const *) argv);
+  ply_terminal_session_attach_to_event_loop (session, state->loop);
+
+  if (!ply_terminal_session_run (session, flags,
+                                 (ply_terminal_session_done_handler_t)
+                                 on_session_finished, state))
+    {
+      ply_save_errno ();
+      ply_terminal_session_free (session);
+      ply_restore_errno ();
+      return NULL;
+    }
+
+  return session;
+}
+
 int
 main (int    argc,
       char **argv)
 {
-  return 0;
+  state_t state;
+  int exit_code;
+
+  if (argc <= 1)
+    {
+      ply_error ("%s other-command [other-command-args]", argv[0]);
+      return EX_USAGE;
+    }
+
+  state.loop = ply_event_loop_new ();
+  state.session = spawn_session (&state, argv + 1);
+
+  if (state.session == NULL)
+    {
+      ply_error ("could not run '%s': %m", argv[0]);
+      return EX_UNAVAILABLE;
+    }
+
+  ply_terminal_session_start_logging (state.session);
+  exit_code = ply_event_loop_run (state.loop);
+  ply_terminal_session_stop_logging (state.session);
+
+  ply_terminal_session_free (state.session);
+  ply_event_loop_free (state.loop);
+
+  return exit_code;
 }
 /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */