Capture the Output of the SKI emulator

Introduction

Catching the output of the IA64 SKI emulator is easy but has lots of traps for new players. Described below is a method that may be of use.

Traps

Solution

We need a fake xterm wrapper to capture the output from SKI. Matthew Chapman wrote an xterm forwarder that relays a pseudo terminal which is available from http://www.cse.unsw.edu.au/~matthewc/files/fake-xterm.c

I wanted something slightly different to simply log output to a file.

  1. get the attached files/copy from this page below/download fake-xterm.c, xterm and Makefile

  2. run make and then make install as root. This will copy fake-xterm and xterm to /usr/local/bin/

  3. if you set the environment variable FAKE_XTERM=yes you will use the "fake" xterm. This must be provided with -S option.

  4. the variable FAKE_XTERM_OUT can be set to the file you wish to log to.
  5. use this in conjunction with an input file to ski, with the -i flag to ski. e.g.

FAKE_XTERM=yes FAKE_XTERM_OUT=/home/ianw/ski.out ski -i skicommands.in bootloader linux

Files

fake-xterm.c

/* fake-xterm
 * Behaves like xterm -S, but logs the output to a file.
 *
 * Original idea by Matthew Chapman <matthewc@cse.unsw.edu.au>
 * If you have problems with this you can email Ian Wienand <ianw@gelato.unsw.edu.au>
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <getopt.h>
#include <sys/types.h>
#include <sys/stat.h>

int main(int argc, char *argv[])
{
        int fd = 0;
        int c;
        char buf[BUFSIZ];
        int fileout_flag = 0;
        int fileout_fd = 1;

        opterr = 0;

        while ((c = getopt(argc, argv, "S:o:h")) != -1)
                switch (c) {
                case 'h':
                        fprintf(stdout,
                                "fake-xterm -o file [arguments to xterm, must include -S]\n");
                        return 0;
                case 'S':
                        /* the format of -S arg to xterm is 
                           -Sppnn
                           where 
                           pp is the pseduo terminal to use in slave mode.
                           nn is the file descriptor you get your input from
                         */
                        fd = atoi(&optarg[2]);
                        break;
                case 'o':
                        if (fileout_flag)       /* -geo 80x25 matches this too unfortunately */
                                continue;
                        fileout_flag = 1;
                        fileout_fd =
                            open(optarg, O_CREAT | O_RDWR | O_TRUNC,
                                 S_IRUSR | S_IWUSR);
                        if (fileout_fd == -1) {
                                perror("open file");
                                return 1;
                        }
                        break;
                case '?':
                        break;
                default:
                        abort();
                }

        if (fd <= 0) {
                fprintf(stderr, "fake-xterm: Must specifiy -S\n");
                return 1;
        }

        /* xterms write back their window id, apparently.
           (undocumented feature) */
        if (write(fd, "0000000\n\r", 9) == -1) {
                perror("writeback");
                return 1;
        }

        while ((c = read(fd, buf, sizeof(buf)))) {
                if (c == -1) {
                        perror("xread");
                        return 1;
                }

                if (write(fileout_fd, buf, c) == -1) {
                        perror("log write");
                        return 1;
                }

        }

        close(fileout_fd);
        close(fd);

        exit(0);

}

xterm shell script

#!/bin/bash
 
if [ ! $FAKE_XTERM_OUT ] ; then
        FAKE_XTERM_OUT=~/fake-xterm.out
fi
 
if [ $FAKE_XTERM ] ; then
        /usr/local/bin/fake-xterm -i -o $FAKE_XTERM_OUT "$@"  ;
else
        /usr/X11R6/bin/xterm "$@"
fi

Makefile

CFLAGS=-g -Wall
 
fake-xterm: fake-xterm.c
        $(CC) $(CFLAGS) -o fake-xterm fake-xterm.c
 
.PHONY : install
install:
        install --owner root --group root ./fake-xterm /usr/local/bin/fake-xterm
        install --owner root --group root ./xterm /usr/local/bin/xterm

IA64wiki: CaptureSkiOutput (last edited 2003-09-11 04:11:06 by mingus)

Gelato@UNSW is sponsored by
the University of New South Wales National ICT Australia The Gelato Federation Hewlett-Packard Company Australian Research Council
Please contact us with any questions or comments.