Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 


Quelle  xterm.c   Sprache: C

 
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (C) 2001 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
 */


#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <termios.h>
#include "chan_user.h"
#include <os.h>
#include <um_malloc.h>
#include "xterm.h"

struct xterm_chan {
 int pid;
 int helper_pid;
 int chan_fd;
 char *title;
 int device;
 int raw;
 struct termios tt;
};

static void *xterm_init(char *str, int device, const struct chan_opts *opts)
{
 struct xterm_chan *data;

 data = uml_kmalloc(sizeof(*data), UM_GFP_KERNEL);
 if (data == NULL)
  return NULL;
 *data = ((struct xterm_chan) { .pid   = -1,
           .helper_pid  = -1,
           .chan_fd  = -1,
           .device   = device,
           .title   = opts->xterm_title,
           .raw    = opts->raw } );
 return data;
}

/* Only changed by xterm_setup, which is a setup */
static char *terminal_emulator = CONFIG_XTERM_CHAN_DEFAULT_EMULATOR;
static char *title_switch = "-T";
static char *exec_switch = "-e";

static int __init xterm_setup(char *line, int *add)
{
 *add = 0;
 terminal_emulator = line;

 line = strchr(line, ',');
 if (line == NULL)
  return 0;

 *line++ = '\0';
 if (*line)
  title_switch = line;

 line = strchr(line, ',');
 if (line == NULL)
  return 0;

 *line++ = '\0';
 if (*line)
  exec_switch = line;

 return 0;
}

__uml_setup("xterm=", xterm_setup,
"xterm=,,<exec switch>\n"</span><br> <span style='color:blue'>" Specifies an alternate terminal emulator to use for the debugger,\n"</span><br> <span style='color:blue'>" consoles, and serial lines when they are attached to the xterm channel.\n"</span><br> <span style='color:blue'>" The values are the terminal emulator binary, the switch it uses to set\n"</span><br> <span style='color:blue'>" its title, and the switch it uses to execute a subprocess,\n"</span><br> <span style='color:blue'>" respectively. The title switch must have the form '<switch> title',\n"</span><br> <span style='color:blue'>" not '<switch>=title'. Similarly, the exec switch must have the form\n"</span><br> <span style='color:blue'>" '<switch> command arg1 arg2 ...'.\n"</span><br> <span style='color:blue'>" The default values are 'xterm="</span> CONFIG_XTERM_CHAN_DEFAULT_EMULATOR<br>      <span style='color:blue'>",-T,-e'.\n"</span><br> <span style='color:blue'>" Values for gnome-terminal are 'xterm=gnome-terminal,-t,--'.\n\n"</span><br> );<br> <br> <span style='color:red'>static</span> <span style='color:red'>int</span> xterm_open(<span style='color:red'>int</span> input, <span style='color:red'>int</span> output, <span style='color:red'>int</span> primary, <span style='color:red'>void</span> *d,<br>         <span style='color:red'>char</span> **dev_out)<br> {<br>  <span style='color:red'>struct</span> xterm_chan *data = d;<br>  <span style='color:red'>int</span> pid, fd, <span style='color:red'>new</span>, err;<br>  <span style='color:red'>char</span> title[256], file[] = <span style='color:blue'>"/tmp/xterm-pipeXXXXXX"</span>;<br>  <span style='color:red'>char</span> *argv[] = { terminal_emulator, title_switch, title, exec_switch,<br>     OS_LIB_PATH <span style='color:blue'>"/uml/port-helper"</span>, <span style='color:blue'>"-uml-socket"</span>,<br>     file, NULL };<br> <br>  <span style='color:red'>if</span> (access(argv[4], X_OK) < 0)<br>   argv[4] = <span style='color:blue'>"port-helper"</span>;<br> <br>  <span style='color:green'>/* Ensure we are running on Xorg or Wayland. */</span><br>  <span style='color:red'>if</span> (!getenv(<span style='color:blue'>"DISPLAY"</span>) && !getenv(<span style='color:blue'>"WAYLAND_DISPLAY"</span>)) {<br>   printk(UM_KERN_ERR <span style='color:blue'>"xterm_open : neither $DISPLAY nor $WAYLAND_DISPLAY is set.\n"</span><wbr>);<br>   <span style='color:red'>return</span> -ENODEV;<br>  }<br> <br>  <span style='color:green'>/*<br> <span style='color:green'>  * This business of getting a descriptor to a temp file,</span><br> <span style='color:green'>  * deleting the file and closing the descriptor is just to get</span><br> <span style='color:green'>  * a known-unused name for the Unix socket that we really</span><br> <span style='color:green'>  * want.</span><br>  */</span><br>  fd = mkstemp(file);<br>  <span style='color:red'>if</span> (fd < 0) {<br>   err = -errno;<br>   printk(UM_KERN_ERR <span style='color:blue'>"xterm_open : mkstemp failed, errno = %d\n"</span>,<br>          errno);<br>   <span style='color:red'>return</span> err;<br>  }<br> <br>  <span style='color:red'>if</span> (unlink(file)) {<br>   err = -errno;<br>   printk(UM_KERN_ERR <span style='color:blue'>"xterm_open : unlink failed, errno = %d\n"</span>,<br>          errno);<br>   close(fd);<br>   <span style='color:red'>return</span> err;<br>  }<br>  close(fd);<br> <br>  fd = os_create_unix_socket(file, <span style='color:red'>sizeof</span>(file), 1);<br>  <span style='color:red'>if</span> (fd < 0) {<br>   printk(UM_KERN_ERR <span style='color:blue'>"xterm_open : create_unix_socket failed, "</span><br>          <span style='color:blue'>"errno = %d\n"</span>, -fd);<br>   <span style='color:red'>return</span> fd;<br>  }<br> <br>  sprintf(title, data->title, data->device);<br>  pid = run_helper(NULL, NULL, argv);<br>  <span style='color:red'>if</span> (pid < 0) {<br>   err = pid;<br>   printk(UM_KERN_ERR <span style='color:blue'>"xterm_open : run_helper failed, "</span><br>          <span style='color:blue'>"errno = %d\n"</span>, -err);<br>   <span style='color:red'>goto</span> out_close1;<br>  }<br> <br>  err = os_set_fd_block(fd, 0);<br>  <span style='color:red'>if</span> (err < 0) {<br>   printk(UM_KERN_ERR <span style='color:blue'>"xterm_open : failed to set descriptor "</span><br>          <span style='color:blue'>"non-blocking, err = %d\n"</span>, -err);<br>   <span style='color:red'>goto</span> out_kill;<br>  }<br> <br>  data->chan_fd = fd;<br>  <span style='color:red'>new</span> = xterm_fd(fd, &data->helper_pid);<br>  <span style='color:red'>if</span> (<span style='color:red'>new</span> < 0) {<br>   err = <span style='color:red'>new</span>;<br>   printk(UM_KERN_ERR <span style='color:blue'>"xterm_open : xterm_fd failed, err = %d\n"</span>,<br>          -err);<br>   <span style='color:red'>goto</span> out_kill;<br>  }<br> <br>  err = os_set_fd_block(<span style='color:red'>new</span>, 0);<br>  <span style='color:red'>if</span> (err) {<br>   printk(UM_KERN_ERR <span style='color:blue'>"xterm_open : failed to set xterm "</span><br>          <span style='color:blue'>"descriptor non-blocking, err = %d\n"</span>, -err);<br>   <span style='color:red'>goto</span> out_close2;<br>  }<br> <br>  CATCH_EINTR(err = tcgetattr(<span style='color:red'>new</span>, &data->tt));<br>  <span style='color:red'>if</span> (err) {<br>   <span style='color:red'>new</span> = err;<br>   <span style='color:red'>goto</span> out_close2;<br>  }<br> <br>  <span style='color:red'>if</span> (data->raw) {<br>   err = raw(<span style='color:red'>new</span>);<br>   <span style='color:red'>if</span> (err) {<br>    <span style='color:red'>new</span> = err;<br>    <span style='color:red'>goto</span> out_close2;<br>   }<br>  }<br> <br>  unlink(file);<br>  data->pid = pid;<br>  *dev_out = NULL;<br> <br>  <span style='color:red'>return</span> <span style='color:red'>new</span>;<br> <br>  out_close2:<br>  close(<span style='color:red'>new</span>);<br>  out_kill:<br>  os_kill_process(pid, 1);<br>  out_close1:<br>  close(fd);<br> <br>  <span style='color:red'>return</span> err;<br> }<br> <br> <span style='color:red'>static</span> <span style='color:red'>void</span> xterm_close(<span style='color:red'>int</span> fd, <span style='color:red'>void</span> *d)<br> {<br>  <span style='color:red'>struct</span> xterm_chan *data = d;<br> <br>  <span style='color:red'>if</span> (data->pid != -1)<br>   os_kill_process(data->pid, 1);<br>  data->pid = -1;<br> <br>  <span style='color:red'>if</span> (data->helper_pid != -1)<br>   os_kill_process(data->helper_pid, 0);<br>  data->helper_pid = -1;<br> <br>  <span style='color:red'>if</span> (data->chan_fd != -1)<br>   os_close_file(data->chan_fd);<br>  os_close_file(fd);<br> }<br> <br> <span style='color:red'>const</span> <span style='color:red'>struct</span> chan_ops xterm_ops = {<br>  .type  = <span style='color:blue'>"xterm"</span>,<br>  .init  = xterm_init,<br>  .open  = xterm_open,<br>  .close  = xterm_close,<br>  .read  = generic_read,<br>  .write  = generic_write,<br>  .console_write = generic_console_write,<br>  .window_size = generic_window_size,<br>  .free  = generic_free,<br>  .winch  = 1,<br> };<br> </div><div align=center><br><table border=1 style='border: 1px solid black; border-collapse: collapse;'><tr><th colspan=3>Messung V0.5</th></tr><tr><td> <svg height='38' width='38' > <circle cx='19' cy='19' r='16' stroke='grey' fill='purple' fill-opacity='30%' stroke-linecap='round' stroke-width='3' stroke-dasharray='360' stroke-dashoffset='36' /> <text x='12' y='22' fill='red' font-size=6>C=95</text> </svg> </td><td> <svg height='38' width='38' > <circle cx='19' cy='19' r='16' stroke='grey' fill='purple' fill-opacity='30%' stroke-linecap='round' stroke-width='3' stroke-dasharray='360' stroke-dashoffset='43' /> <text x='12' y='22' fill='red' font-size=6>H=94</text> </svg> </td><td> <svg height='56' width='56' > <circle cx='28' cy='28' r='24' stroke='green' fill='purple' fill-opacity='30%' stroke-linecap='round' stroke-width='4' stroke-dasharray='360' stroke-dashoffset='43' /> <text x='18' y='32' fill='red' font-size=8>G=94</text> </svg> </td></tr></table></div></span><br> <h3><b>¤</b> Dauer der Verarbeitung: 0.3 Sekunden  <b>¤</b></h3> <p height="2" colspan="2" align="center"><span style="font-size: 3px;">*© Formatika GbR, Deutschland</span></p> </div> </td> <td valign="top" align="center" class="greenscreensmall"> <br><br><br> <br> <table width="20%"> <tr><td align="center"> <a href="index.jsp?content=directory"> <br>Wurzel<br> <img border="0" src="/Images/penguin.jpg" height=36 alt="" title="Wurzel"> </a> </td> </tr> <tr><td align="center"> <a href="index.jsp?content=search" title="Suchen"> <br>Suchen<br> <img src="/Images/find.png" height="48" alt="" border="0"> </a> </td> </tr> <tr><td align="left"><a href="index.jsp?content=directory&detail=products/Sources/formale%20Sprachen/PVS/" title="Projekt "><br>Beweissystem der NASA</a></td></tr> <tr><td align="left"><a href="index.jsp?content=directory&detail=products/Sources/formale%20Sprachen/Isabelle/" title="Projekt "><br>Beweissystem Isabelle</a></td></tr> <tr><td align="left"><a href="index.jsp?content=directory&detail=products/Sources/formale%20Sprachen/Cobol/Test-Suite/" title="Projekt "><br>NIST Cobol Testsuite</a></td></tr> <tr><td align="left"><a href="index.jsp?content=directory&detail=products/Sources/formale%20Sprachen/Fortran/f90gl-1.2.15/" title="Projekt "><br>Cephes Mathematical Library</a></td></tr> <tr><td align="left"><a href="index.jsp?content=directory&detail=products/Sources/formale%20Sprachen/VDM/" title="Projekt "><br>Wiener Entwicklungsmethode</a></td></tr> <tr><td align="center"> <br> <h2>Haftungshinweis</h2> <div align="justify" class="featuresmall">Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.</div> <br> <h2>Bemerkung:</h2> <div align="justify" class="featuresmall"> Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.</div> <br> </td> </tr> </table> <br><br> <div> <br> <script src="https://formatika.de/base/formcheck.js"></script> <script> function checkform(form) { var res = true; res = res && isnotempty(form.file); res = res && isurl(form.file); return res; } </script> </div><br> <br> </td> </tr> </table> </div> <div class="printelement"> <script> warningpreview(); </script> </div> <p align=right class=hidden>2026-04-04</p> </td> </tr> <tr> <td width="100%" class="content"> <p>                                                                                                                                                                                                                                                                                                                                                                                                       </p> </td> </tr> </table> </td> <td width="17%" valign="top" class="storysmall"> <div> <table class="headlines"> <tr><td> <table border="0"> <tr><td><hr align="left" width="70%%"/></td></tr> <tr><td><h2 align="left">Neuigkeiten</h2></td></tr> <tr><td>     <a title="letzte Meldungen über diese Firma" href="index.jsp?content=aktuelles">Aktuelles</a></td></tr> <tr><td>     <a title="Spruch des Tages" href="index.jsp?content=motto">Motto des Tages</a></td></tr> <tr><td><hr align="left" width="70%%"/></td></tr> <tr><td><h2 align="left">Software</h2></td></tr> <tr><td>     <a title="Windows-Programme und andere" href="index.jsp?content=products">Produkte</a></td></tr> <tr><td>     <a title="Sammlung von Quellcodes" href="index.jsp?content=directory">Quellcodebibliothek</a></td></tr> <tr><td><hr align="left" width="70%%"/></td></tr> <tr><td><h2 align="left">Aktivitäten</h2></td></tr> <tr><td>     <a href='index.jsp?content=mobiles'>Artikel über Sicherheit</a></td></tr> <tr><td>     <a href='index.jsp?content=sslhelp'>Anleitung zur Aktivierung von SSL</a></td></tr> <tr><td><hr align="left" width="70%%"/></td></tr> <tr><td><h2 align="left">Muße</h2></td></tr> <tr><td>     <a title="kleine Reime" href="index.jsp?content=gedichte">Gedichte</a></td></tr> <tr><td>     <a title="einige Melodien" href="index.jsp?content=musik">Musik</a></td></tr> <tr><td>     <a title="einige Melodien" href="index.jsp?content=bilder">Bilder</a></td></tr> <tr><td><hr align="left" width="70%%"/></td></tr> <tr><td> <strong>Jenseits des Üblichen ....</strong> <br><a title="Anleitung zur Erforschung der Natur" href="index.jsp?content=fauna">    <img src='/Images/Biber.png' width='100' vspace='7' alt='' title='Der fleißige Biber' ></a> </td></tr> <tr><td><hr align="left" width="90%%"/></td></tr> <tr><td><h2>Besucherstatistik</h2></td></tr> <tr> <td><a href="index.jsp?content=stats&detail=chart" target="_self"> <img width="168" src="/Images/Googlemap.png" border="0" alt="Besucherstatistik" title="Besucherstatistik" > </a> </td> </tr> <tr><td><hr align="left" width="90%%"/></td></tr> <tr><td><h2>Monitoring</h2></td></tr> <tr> <td><a href="https://uelk2599jehr.montastic.io" target="_blank"> <img src="https://uelk2599jehr.montastic.io/badge" width=96 alt="Montastic status badge"> </a> </td> </tr> </table> </td></tr> </table> </div> </td> </tr> </table> </td> <td width="3%"> </td> </tr> <tr> <td colspan="3" align="center"> <div> <br><br><br> <div> <table width="45%" align="center" class="screenelement"> <tr><td width="80%"><hr class="ruler" /></td></tr> <tr><td width="80%" align="center"> <span class="feature"> <a title="über den Urheber dieser Seite" href="index.jsp?content=impressum">Impressum</a>  | <a title="etwas mehr zur Ethik" href="index.jsp?content=gesellschaft&detail=ethik">Ethik und Gesetz</a>  | <a title="diese Dinge liegen außhalb unserer Verantwortung" href="index.jsp?content=haftung" class="style6">Haftungsausschluß</a>  | <a title="hier können Sie eine Nachricht absetzen" href="index.jsp?content=contact">Kontakt</a>  | <a title="ein Bild über den Seitenaufbau" href="index.jsp?content=sitemap">Seitenstruktur</a>  </span> | <span class="featuresmall"><sup>©</sup> 2026 JDD</span> | <img src='/Images/unknown.jpg' alt='' title="Seite erzeugt: Seite erzeugt: 2026-04-05 10:00:35" ontouchend="alert('Seite erzeugt: 2026-04-05 10:00:35');" onclick="alert('Seite erzeugt: 2026-04-05 10:00:35');" width=12 valign='middle'> </td></tr> </table> </div> </div> </td> </tr> </table> </body> </html>