From: Ray Strode Date: Wed, 23 May 2007 18:29:14 +0000 (-0400) Subject: add start of a program to eat a sessions output X-Git-Tag: 0.1.0~255 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=23aad9450761ff34aff7b5ddda2f98987cd3bdbb;p=thirdparty%2Fplymouth.git add start of a program to eat a sessions output --- diff --git a/src/Makefile.am b/src/Makefile.am index feef70cc..267f46db 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/main.c b/src/main.c index d7a5823f..01c825d4 100644 --- a/src/main.c +++ b/src/main.c @@ -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 @@ -20,10 +19,86 @@ * * Written by: Ray Strode */ +#include "config.h" + +#include +#include +#include + +#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: */