*BSD News Article 25562


Return to BSD News archive

Xref: sserve comp.unix.shell:12832 comp.unix.questions:43783 comp.unix.misc:10778 comp.os.386bsd.questions:7709
Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!sgiblab!swrinde!cs.utexas.edu!utah-morgan!hellgate.utah.edu!fcom.cc.utah.edu!u.cc.utah.edu!cs.weber.edu!terry
From: terry@cs.weber.edu (A Wizard of Earth C)
Newsgroups: comp.unix.shell,comp.unix.questions,comp.unix.misc,comp.os.386bsd.questions
Subject: Re: How to direct cron output to a tty or pty ?
Date: 4 Jan 1994 19:06:58 GMT
Organization: Weber State University, Ogden, UT
Lines: 61
Message-ID: <2gceoi$d8k@u.cc.utah.edu>
References: <CJ38vz.1Hr@latcs1.lat.oz.au>
NNTP-Posting-Host: cs.weber.edu

In article <CJ38vz.1Hr@latcs1.lat.oz.au> wongm@ipc6.lat.oz.au (M.C. Wong) writes:
>  I am writing some sort of alarming utils run from within xterm only, ie 
>won't work on non-xterm environment. What happen is that, when a scheduled
>event is activated at the right time, it will simple write a message to
>the xterm's header as title , blinking and beeping, and at the moment I
>resort to using escape sequence, ie : echo -n "]2;message" to change the
>xterm header border! Also, I am using cron to do the stuff since the system
>I run doesn't have at, but crond will direct any output of a scheduled
>program to a file and mail it to the user, as a result my escape sequence
>can not reflect the changes onto my xterm.

This is a bad thing in general.

First, the cron jobs can redirect their output to a particular terminals
fairly easily.  You will want to not output to stdout unless you freopen()
it to the terminal you are interested in writing to.

The reason using "broadcast" escape sequences this way is a bad thing is
that you can not guarantee the current terminal state at the time of the
boradcast; this is primarily a problem with many applications (MS BASIC
for Xenix, for instance) which read the termcap themselves and output
the escape sequences themselves.  Secondly, since output is flushed on
block boundries for most curses apps, there is no guarantee that curses
itself will attempt to guarantee atomicity.  Finally, there is no
guarantee that the I/O will not be scheduled seperately within the tty
subsystem itself.

Boiled down, this means that you may send an escape sequence in the
middle of another program sending an escape sequence.  If you want
to look at it another way, terminals (including xterm and your console)
are finite state automatons which start in the ground state; when they
see an escape sequence, they go into other states until they see the
terminal character in the sequence, after which they drop back to the
ground state.  For a broadcast escape sequence to work:

(1)	It must be sent only if the terminal is in the ground state
	(not processing another sequence at the time).

(2)	It must be I/O atomic -- that is, it must contain the start,
	middle, and terminal character of the escape sequence, and
	these must be written to the device in a single I/O operation.

VMS gets around this problem by having automatons that act like the
terminal itself in the driver, and then controlling the I/O libraries
and the types of terminals which will work on the machine.  Then when
a second channel is opened to the device, I/O is blocked until the
internal automatons on the other channels are all at state 0.

A similar method is used in transparent printer drivers by Digiboard (I
don't know if other companies do this yet) to ensure print sequences and
data don't interrupt escape sequences from the terminal itself.

Anyway, you are looking at a lot more than simply "what to do with cron"
if you want broadcast escape sequences to work reliably.


					Terry Lambert
					terry@cs.weber.edu
---
Any opinions in this posting are my own and not those of my present
or previous employers.