[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Lost] [Patch] getterm
Da unser vterm ja jetzt wunderschöne virtuelle Terminals unterstützt sollten
die auch benutzt werden können. Damit das möglich wird, müssen Programme so
gestartet werden können, dass sie auf einem anderen virtuellen Terminal
laufen. Und genau das bewerkstelligt getterm.
Index: src/modules/c/getterm/Makefile.all
===================================================================
--- src/modules/c/getterm/Makefile.all (Revision 0)
+++ src/modules/c/getterm/Makefile.all (Revision 0)
@@ -0,0 +1,8 @@
+shopt -s extglob
+source $LOST_BUILDMK_ROOT/config.sh
+
+echo "LD $1/apps/getterm"
+
+$LOST_TOOLS_LD -ogetterm -Ttext=0x40000000 --start-group *.o $2 --end-group
+
+mv getterm $1/apps/
Index: build/default.cfg
===================================================================
--- build/default.cfg (Revision 700)
+++ build/default.cfg (Arbeitskopie)
@@ -9,5 +9,6 @@
module /kbc.mgz
module /cmos.mgz
module /pci.mgz
-module /apps/sh
+module /apps/getterm vterm:/vterm0/in vterm:/vterm0/out vterm:/vterm0/out /apps/sh
+module /apps/getterm vterm:/vterm1/in vterm:/vterm1/out vterm:/vterm1/out /apps/sh
boot
Index: src/modules/c/getterm/main.c
===================================================================
--- src/modules/c/getterm/main.c (Revision 0)
+++ src/modules/c/getterm/main.c (Revision 0)
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2007 The LOST Project. All rights reserved.
+ *
+ * This code is derived from software contributed to the LOST Project
+ * by Antoine Kaufmann.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the LOST Project
+ * and its contributors.
+ * 4. Neither the name of the LOST Project nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <stdio.h>
+#include <rpc.h>
+#include <syscall.h>
+#include <stdint.h>
+#include <sleep.h>
+#include <sys/wait.h>
+
+#define _USE_START_
+#include "init.h"
+#undef _USE_START_
+
+// Aufruf an Console zum aendern der Terminal-Optionen
+typedef enum {STDIN, STDOUT, STDERR} console_handle_t;
+typedef struct {
+ pid_t pid;
+ console_handle_t type;
+ char path[];
+} __attribute__((packed)) console_ctrl_t;
+
+/**
+ * Pfad fuer Terminal aendern
+ */
+static void console_set_handle(console_handle_t handle, const char* path)
+{
+ size_t path_len = strlen(path);
+ size_t size = sizeof(console_ctrl_t) + path_len + 1;
+
+ // Buffer vorbereiten
+ uint8_t buffer[size];
+ console_ctrl_t* ctrl = (console_ctrl_t*) buffer;
+
+ // Befehlsstruktur auffuellen
+ ctrl->pid = -1;
+ ctrl->type = handle;
+ memcpy(ctrl->path, path, path_len + 1);
+
+ // RPC durchfuehren
+ pid_t console_pid = init_service_get("console");
+ dword result = rpc_get_dword(console_pid, "CONS_SET",
+ size, (char*) buffer);
+ if (result == 0) {
+ printf("Fehler beim setzen des Pfades fuer die I/O-Handles.");
+ exit(-1);
+ }
+}
+
+/**
+ * Hauptfunktion
+ */
+int main(int argc, char* argv[])
+{
+ // Wenn die Anzahl der Argumente nicht stimmt wird abgebrochen
+ if (argc != 5) {
+ puts("Aufruf: getterm <stdin> <stdout> <stderr> <Programm>");
+ return -1;
+ }
+
+ // Ein bisschen warten, bis vterm und co bereit sind;
+ msleep(2000);
+
+ // Pfade bei console aendern
+ console_set_handle(STDIN, argv[1]);
+ console_set_handle(STDOUT, argv[2]);
+ console_set_handle(STDERR, argv[3]);
+
+ // Lokale Ein- und Ausgabehandles auch anpassen
+ stdio_init();
+
+ while (TRUE) {
+ char input = 0;
+ printf("\n\nEingabetaste druecken um eine Shell zu starten...\n");
+ // Auf Druecken der Eingabetaste warten
+ while((fread(&input, 1, 1, stdin) != 1) || (input != '\n')) {
+ msleep(100);
+ }
+
+ pid_t pid = init_execute(argv[4]);
+
+ // Fehler ist aufgetreten
+ if (pid == 0) {
+ printf("Fehler beim ausfuehren von '%s'\n", argv[4]);
+ return -1;
+ }
+
+ // Jetzt wird gewartet, bis der Prozess terminiert
+ waitpid(pid, NULL, 0);
+ }
+
+ return 0;
+}
+