cu receive redir. ?

Rob Warnock rpw3 at redwood.UUCP
Tue Sep 18 10:32:43 AEST 1984


I also use 'cu' to talk to certain non-UNIX systems, most (all?) of
which have command prompts which do NOT leave the cursor at the beginning
of the line. Now on those systems where I am permitted to write programs
(or even to create & type out files), a trivial program (file) can be
used to turn logging on/off. But on the others...?

I tried the "cu | tee" approach, and found it very UNsatisfactory, since
shell escapes (such as "vi replyfile") have all of their output going through
the "tee", and also since stdout is a pipe, programs which use "termcap/curses"
screw up.

Fortunately, (1) the operating system on my machine has the 4.1bsd IOCTL
for stuffing characters back INTO a tty input, and (2) I have priviledges
for making programs setuid root (needed for the IOCTL). A simple program
(attached, below) which uses this IOCTL can then be run from "~!culog [file]"
to turn logging on/off/on-again, as desired. This has been quite satisfactory.

I have fallen into a style of use which consists of a shell script of the
following general form:

	: call system "x", log to file "cu.log"
	CUDEV=${CUDEV-/dev/cul0}
	(stty raw -echo		# so "culog" doesn't echo to the dialer
	 sleep 5		# long enough for "cu" so say "Connected"
	 culog cu.log		# stuff the "~>>cu.log" into the pipe
	 echo			# Cermetek modem needs <LF><CR><LF><CR>
	 echo -n '
'		#   to wake up
	 echo
	 echo -n '
'
	 echo			# some delay for dialer to say "what number?"
	 echo
	 echo
	 echo -n '8005551212
'	# put your own number here
	 sleep 25		# long enough to dial and get through
	 echo -n '
'
	 echo -n '
'		# baud-detect at the other end
	 #
	 # put stuff to do login and password here
	 #
	 sleep 1		)>$CUDEV &
	exec cu -s 1200 -l $CUDEV

Notice that I leave output to the terminal ON ("~>>file", not "~>>:file"),
since that permits monitoring the whole process in case something goes
wrong (as does "cu|tee"). Also, note that everything but the final "cu" is
run in the background, so that "cu" can get started up before the "culog".

Hope this is of use to someone...

Rob Warnock

UUCP:	{ihnp4,ucbvax!amd}!fortune!redwood!rpw3
DDD:	(415)369-7437
Envoy:	rob.warnock/kingfisher
USPS:	Suite 203, 4012 Farm Hill Blvd, Redwood City, CA  94061

------------------Attachment-----------------------------------
/*
 * culog.c - hack to control cu logging when talking to a non-UNIX system
 *
 * usage: culog [ <filename> ]	# usually from within cu with a ~! escape
 *				# If no filename given, logging is turned off.
 *
 * 840904 rpw3	This program uses the Berkeley ioctl TIOCSTI to stuff the
 *		magic characters into the "other" port of a cu connection
 *		to cause the "reverse path cu" to start/stop copying to a
 *		file. Restrictions of first implementation: Only /dev/cul0
 *		is used. Logging ALWAYS appends (never creates). Logging
 *		is always done in non-silent mode (you see what you get).
 *		(Even with that, it's QUITE useful!)
 *
 *		Note: must be installed setuid root, since TIOCSTI is
 *		(for good reason) priviledged.
 */

/* Futures/Bugs:
 *
 * flow control - maybe should use FIONREAD or something to make sure
 *		the entire CULOG_ON string will fit into the tty's input
 * cu device	- should really be an argument; if not, check to see if
 *		stdout is a tty, and if	so, try to use that
 */

#include <sys/ioctl.h>

/* These have "extra" newlines at the beginning, which can sometimes get
 * into the log file, but better that than not being able to close a
 * connection that didn't end in a newline!
 */
#define CULOG_ON	"\n~>>%s\n"	/* Append, leaving tty copy on */
#define CULOG_OFF	"\n~>\n"

#define CUDEV		"/dev/cul0"	/* (future) should be an arg */

main(argc,argv)
int argc;
char **argv;
{
	register char *p;
	register int cul0;
	char buf[1024];

	if((cul0 = open(CUDEV,1)) < 0){
		perror(argv[0]);
		exit(1);
	}
	if(argv[1])
		sprintf(buf, CULOG_ON, argv[1]);
	else
		sprintf(buf, CULOG_OFF);

	for(p = buf; *p != '\0'; ++p){
		if(ioctl(cul0, TIOCSTI, p) != 0){
			perror(argv[0]);
			exit(1);
		}
	}
	close(cul0);
	exit(0);
}
------------------Attachment ends-----------------------------------



More information about the Comp.unix mailing list