home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!uwm.edu!rutgers!modus!lpds!wcp
- From: wcp@lpds.sublink.org (Walter C. Pelissero)
- Newsgroups: alt.sources
- Subject: mgetty - A modular getty v1.0, Part02/04
- Message-ID: <1993Jan22.162016.852@lpds.sublink.org>
- Date: 22 Jan 93 16:20:16 GMT
- Organization: Sweet home under white clouds
- Lines: 1867
- Phone: + 39 2 8464117 - 8435411 (work) 8267089 (home)
- Postal-Address: Via G. de Ruggiero 87, 20142 Milano - Italia
-
- Submitted-by: wcp@lpds
- Archive-name: mgetty-1.0/part02
-
- ---- Cut Here and feed the following to sh ----
- #!/bin/sh
- # this is mgetty10.02 (part 2 of mgetty-1.0)
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file doc/mgetty.8 continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 2; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping doc/mgetty.8'
- else
- echo 'x - continuing file doc/mgetty.8'
- sed 's/^X//' << 'SHAR_EOF' >> 'doc/mgetty.8' &&
- Xto DCE.
- X.TP
- Xrecord
- XThis is the \fIplay\fP counterpart. It is able to receive (and record
- Xto a file) voice from DCE.
- X.TP
- Xc2rec
- XThis is the Class 2 receiver, currently designed around ZyXEL U-1496.
- X.PP
- XAdd of new programs to this list is very simple; invoked programs will
- Xhave their stdin, stdout, and stderr properly redirected.
- X.SH FILES
- X.TP 2.3i
- X/usr/local/lib/mgetty
- XMgetty library area
- X.TP
- XLIBDIR/sound
- XDirectory of vocal messages to be used in TCL scripts.
- X.TP
- XLIBDIR/ttys
- XDirectory of tty interface scripts.
- X.SH BUGS
- XThe \fIstty\fP command is not yet implemented.
- X.PP
- X/usr/lib/uucp/* files are never used so some difference may be
- Xnoticed. Examples: lock files are always created also if tty is not a
- Xdialout line; uucp dialers are never used to reset modem, all the
- Xnecessary steps should be done inside mgetty script.
- X.PP
- XHDB cu and uucico don't like mgetty; an ungetty (a true ungetty) call
- Xis needed before and after dialout on lines monitored by mgetty.
- X.SH AUTHOR
- XWalter Pelissero <wally@lpds.sublink.org>
- X.SH "SEE ALSO"
- Xc2rec(8), play(8), record(8)
- SHAR_EOF
- echo 'File doc/mgetty.8 is complete' &&
- true || echo 'restore of doc/mgetty.8 failed'
- rm -f _shar_wnt_.tmp
- fi
- # ============= doc/play.8 ==============
- if test -f 'doc/play.8' -a X"$1" != X"-c"; then
- echo 'x - skipping doc/play.8 (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting doc/play.8 (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'doc/play.8' &&
- X.\" -*- Nroff -*-
- X.\"
- X.\" $Id: play.8,v 1.2 1993/01/21 19:45:21 wcp Exp $
- X.\"
- X.\" Copyright (C) 1992 Walter Pelissero
- X.\"
- X.\" This program is free software; you can redistribute it and/or modify
- X.\" it under the terms of the GNU General Public License as published by
- X.\" the Free Software Foundation; either version 2 of the License, or
- X.\" (at your option) any later version.
- X.\"
- X.\" This program is distributed in the hope that it will be useful,
- X.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
- X.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X.\" GNU General Public License for more details.
- X.\"
- X.\" You should have received a copy of the GNU General Public License
- X.\" along with this program; if not, write to the Free Software
- X.\" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X.\"
- X.\"
- X.\" $Log: play.8,v $
- X.\" Revision 1.2 1993/01/21 19:45:21 wcp
- X.\" Changed .I in \fI/\fP.
- X.\"
- X.\" Revision 1.1 1993/01/13 21:40:54 wcp
- X.\" Initial revision
- X.\"
- X.\"
- X.de XX
- X.ds XX \\$4\ (v\\$3)
- X..
- X.XX $Id: play.8,v 1.2 1993/01/21 19:45:21 wcp Exp $
- X.TH PLAY 8 \*(XX
- X.AT 3
- X.SH NAME
- Xplay \- voice player for ZyXEL U-1496
- X.SH SYNOPSIS
- X.B play
- X.RI [ -x\ debug_level ]
- X.RI [ -s\ speaker ]
- X.RI [ -c\ device ]
- X.RI [ -v\ volume ]
- X.RI [ -e\ encoding ]
- X.RI [ voice_file ]
- X.SH DESCRIPTION
- X\fIPlay\fP is a sound player front end for \fImgetty\fP. \fIRecord\fP
- Xcan work in two ways, on a successfully established connection, or in
- Xa batched way, to listen to already saved messages. If no file name is
- Xspecified on command line, \fIplay\fP take sound data from stdin.
- X.SH OPTIONS
- X.IP "-x \fIlevel\fP"
- XTell the verbosity of debug informations displayed during processing.
- X.IP "-s \fIspeaker\fP"
- XSpecify which speaker to play with: 0 = telco line, 1 = microphone, 2
- X= internal speaker. Default is internal speaker if \fI-c\fP is
- Xspecified, telco line instead. This option must be specified after the
- X\fI-c\fP option, if present.
- X.IP "-c \fIdevice\fP"
- XWhich device to connect to. If this option is not specified \fIplay\fP
- Xexpects to be already connected to a device and to have stdin/stdout
- Xalready redirected.
- X.IP "-v \fIvolume\fP"
- XPlayback volume in range from 0 to 7.
- X.IP "-e \fIencoding\fP"
- XSpecify encoding algorithm for data to be played: 1 = CELP, 2 = ADPCM
- Xwith two bits, 3 = ADPCM with three bits.
- X.SH BUGS
- XThe volume option is useless.
- X.PP
- XCurrently supported modems are ZyXEL U-1496 only.
- X.SH AUTHOR
- XWalter Pelissero <wally@lpds.sublink.org>
- X.SH "SEE ALSO"
- Xmgetty(8), record(8)
- SHAR_EOF
- true || echo 'restore of doc/play.8 failed'
- rm -f _shar_wnt_.tmp
- fi
- # ============= doc/record.8 ==============
- if test -f 'doc/record.8' -a X"$1" != X"-c"; then
- echo 'x - skipping doc/record.8 (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting doc/record.8 (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'doc/record.8' &&
- X.\" -*- Nroff -*-
- X.\"
- X.\" $Id: record.8,v 1.2 1993/01/21 19:45:21 wcp Exp $
- X.\"
- X.\" Copyright (C) 1992 Walter Pelissero
- X.\"
- X.\" This program is free software; you can redistribute it and/or modify
- X.\" it under the terms of the GNU General Public License as published by
- X.\" the Free Software Foundation; either version 2 of the License, or
- X.\" (at your option) any later version.
- X.\"
- X.\" This program is distributed in the hope that it will be useful,
- X.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
- X.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X.\" GNU General Public License for more details.
- X.\"
- X.\" You should have received a copy of the GNU General Public License
- X.\" along with this program; if not, write to the Free Software
- X.\" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X.\"
- X.\"
- X.\" $Log: record.8,v $
- X.\" Revision 1.2 1993/01/21 19:45:21 wcp
- X.\" Changed .I in \fI/\fP.
- X.\"
- X.\" Revision 1.1 1993/01/13 21:40:54 wcp
- X.\" Initial revision
- X.\"
- X.\"
- X.de XX
- X.ds XX \\$4\ (v\\$3)
- X..
- X.XX $Id: record.8,v 1.2 1993/01/21 19:45:21 wcp Exp $
- X.TH RECORD 8 \*(XX
- X.AT 3
- X.SH NAME
- Xrecord \- voice recorder for ZyXEL U-1496
- X.SH SYNOPSIS
- X.B record
- X.RI [ -x\ debug_level ]
- X.RI [ -f ]
- X.RI [ -d ]
- X.RI [ -m\ microphone ]
- X.RI [ -c\ device ]
- X.RI [ -t\ min_time [ :max_time ]]
- X.RI [ -e\ encoding ]
- X.RI [ file_or_directory ]
- X.SH DESCRIPTION
- X\fIRecord\fP is a sound recorder front end for \fImgetty\fP.
- X\fIRecord\fP can work in two ways, on a successfully established
- Xconnection, or in a batched way, to record greeting messages, etc. If
- Xno file name is specified on command line, \fIrecord\fP write sound
- Xdata to stdout. If a directory is specified instead of a file,
- X\fIrecord\fP creates a file in it with this name template: inXXXXXXXX.
- XWhere XXXXXXXXX stands for a message sequence number. The program
- Xadjust message sequence number to avoid overwriting of existing
- Xmessages.
- X.SH OPTIONS
- X.IP "-x \fIlevel\fP"
- XTell the verbosity of debug informations displayed during processing.
- X.IP "-m \fImicrophone\fP"
- XSpecify which microphone to record from: 0 = telco line, 1 =
- Xmicrophone, 2 = internal speaker. Default is microphone if \fI-c\fP is
- Xspecified, telco line instead. This option must be specified after the
- X\fI-c\fP option, if present.
- X.IP -f
- XDisable T.30 fax tone detection.
- X.IP -d
- XEnable DTMF digits detection.
- X.IP "-c \fIdevice\fP"
- XWhich device to connect to. If this option is not specified \fIplay\fP
- Xexpect to already connected and to have stdin/stdout already properly
- Xredirected.
- X.IP "-t \fImin_time\fP[\fI:max_time\fP]"
- XMinimum and (optionally) maximum recording time. If a message is
- Xrecorded with a length less than minimum, line garbage is assumed and
- Xno message is saved (output file, if any, is discarded). If message
- Xexceeds the maximum, it is truncated. Default values are respectively
- X10 senconds and 5 minutes.
- X.IP "-e \fIencoding\fP"
- XSpecify encoding algorithm for data to be recorded: 1 = CELP, 2 = ADPCM
- Xwith two bits, 3 = ADPCM with three bits.
- X.SH DIAGNOSTICS
- XOn exit it returns a code specifing the reason of exiting:
- X.IP 0
- XMessage recorded succesfully.
- X.IP 1
- XGot silence or message too short. No message is recorded. This may
- Xmean that a DCE is waiting on the other end of line.
- X.IP 2
- XHeard a T.30 fax tone. No message is recorded. A fax machine is
- Xwaiting to send.
- X.IP "10 through 19"
- XReceived DTMF digit. Real value is incremented by 10.
- X.SH BUGS
- XDTMF support is still untested.
- X.PP
- XCurrently supported modems are ZyXEL U-1496 only.
- X.SH AUTHOR
- XWalter Pelissero <wally@lpds.sublink.org>
- X.SH "SEE ALSO"
- Xmgetty(8), play(8)
- SHAR_EOF
- true || echo 'restore of doc/record.8 failed'
- rm -f _shar_wnt_.tmp
- fi
- # ============= listen.sh ==============
- if test -f 'listen.sh' -a X"$1" != X"-c"; then
- echo 'x - skipping listen.sh (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting listen.sh (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'listen.sh' &&
- X: use /bin/sh
- X#
- X# @(#)$Id: listen.sh,v 1.2 1993/01/22 15:14:24 wcp Exp $
- X#
- X# Copyright (C) 1993 Walter Pelissero
- X#
- X# This program is free software; you can redistribute it and/or modify
- X# it under the terms of the GNU General Public License as published by
- X# the Free Software Foundation; either version 2 of the License, or
- X# (at your option) any later version.
- X#
- X# This program is distributed in the hope that it will be useful,
- X# but WITHOUT ANY WARRANTY; without even the implied warranty of
- X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X# GNU General Public License for more details.
- X#
- X# You should have received a copy of the GNU General Public License
- X# along with this program; if not, write to the Free Software
- X# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X#
- X
- X#
- X# $Log: listen.sh,v $
- X# Revision 1.2 1993/01/22 15:14:24 wcp
- X# Removed magic string.
- X#
- X# Revision 1.1 1993/01/07 23:16:09 wcp
- X# Initial revision
- X#
- X#
- X
- XLIBDIR=%LIB_DIR%
- XPLAY="$LIBDIR/play"
- X
- Xflags=
- Xfor a in $*
- Xdo
- X case $a in
- X -*) flags="$flags $a"
- X shift; #=`eval $# - 1`
- X ;;
- X *) break
- X ;;
- X esac
- Xdone
- X
- Xplay () {
- X encoding=`sed -n '1,/^DATA:/s/^ENCODING:[ \t]*\(.*\)/\1/p' $1`
- X [ "$encoding" ] || encoding=2
- X tail +`awk '/^DATA:$/ { print NR + 1; exit }' $1` $1 | $PLAY $flags -s $encoding
- X}
- X
- X[ $# -lt 1 ] && set -- /usr/spool/voice/*
- X
- Xfor f in $*
- Xdo
- X if [ -d $f ]
- X then
- X for ff in $f/*
- X do
- X play $ff
- X done
- X else
- X play $f
- X fi
- Xdone
- SHAR_EOF
- true || echo 'restore of listen.sh failed'
- rm -f _shar_wnt_.tmp
- fi
- # ============= localize.c ==============
- if test -f 'localize.c' -a X"$1" != X"-c"; then
- echo 'x - skipping localize.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting localize.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'localize.c' &&
- X/*
- X * $Id: localize.c,v 1.1 1993/01/06 18:02:00 wcp Exp $
- X *
- X * Copyright (C) 1992 Walter Pelissero
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of the GNU General Public License as published by
- X * the Free Software Foundation; either version 1, or (at your option)
- X * any later version.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X */
- X
- X/*
- X * $Log: localize.c,v $
- X * Revision 1.1 1993/01/06 18:02:00 wcp
- X * Initial revision
- X *
- X */
- X
- Xextern int printf(const char *, ...);
- Xextern volatile void exit(int);
- X
- Xint main()
- X{
- X printf("s#%%LIB_DIR%%#%s#\n", LIB_DIR);
- X printf("s#%%BIN_DIR%%#%s#\n", BIN_DIR);
- X printf("s#%%PBMPLUS%%#%s#\n", PBMPLUS);
- X return exit(0), 0;
- X}
- SHAR_EOF
- true || echo 'restore of localize.c failed'
- rm -f _shar_wnt_.tmp
- fi
- # ============= locks.c ==============
- if test -f 'locks.c' -a X"$1" != X"-c"; then
- echo 'x - skipping locks.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting locks.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'locks.c' &&
- X/*
- X * $Id: locks.c,v 1.2 1993/01/06 18:06:04 wcp Exp $
- X *
- X * Copyright (C) 1992 Walter Pelissero
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of the GNU General Public License as published by
- X * the Free Software Foundation; either version 1, or (at your option)
- X * any later version.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X */
- X
- X/*
- X * $Log: locks.c,v $
- X * Revision 1.2 1993/01/06 18:06:04 wcp
- X * Modified unlockLine() to be able to remove someone else locks.
- X * Added ilLocked().
- X *
- X * Revision 1.1 1992/08/28 22:44:05 wally
- X * Initial revision
- X *
- X */
- X
- X#include <sys/types.h>
- X#ifdef DEBUG
- X#include <dbmalloc.h>
- X#endif
- X#include <stdio.h>
- X#include <string.h>
- X#include <fcntl.h>
- X#include <stdlib.h>
- X#include <errno.h>
- X#include "common.h"
- X
- Xstatic char RcsId[] = "$Id: locks.c,v 1.2 1993/01/06 18:06:04 wcp Exp $";
- X
- Xbool unlockLine(const char *line)
- X{
- X char *tty;
- X char *pathname = malloc(strlen(LOCK_DIR) + strlen(line) + 7);
- X int fd;
- X bool ret = FAILED;
- X
- X tty = strdup(basename(line));
- X strlower(tty);
- X sprintf(pathname, "%s/LCK..%s", LOCK_DIR, tty);
- X free(tty);
- X fd = open(pathname, O_RDONLY);
- X if (fd >= 0)
- X {
- X char buf[32];
- X int nread;
- X int pid;
- X
- X if ((nread = read(fd, buf, sizeof(buf))) > 0)
- X {
- X#if defined(M_XENIX)
- X buf[nread - 1] = '\0';
- X pid = atoi(buf);
- X#else
- X#endif
- X }
- X else
- X pid = getpid();
- X close(fd);
- X if (pid == getpid() || kill(pid, 0) < 0)
- X {
- X unlink(pathname);
- X ret = SUCCEEDED;
- X }
- X else
- X ret = FAILED;
- X }
- X else
- X ret = (errno == ENOENT);
- X free(pathname);
- X return ret;
- X}
- X
- Xbool lockLine(const char *line, int time)
- X{
- X char *pathname1 = makeTemp(LOCK_DIR), *pathname2, *tty;
- X int fd = open(pathname1, O_WRONLY | O_CREAT, 0644), ret = TRUE;
- X
- X if (fd < 0)
- X return FALSE;
- X else
- X {
- X char buf[32];
- X
- X#if defined(M_XENIX)
- X sprintf(buf, "%10u\n", getpid());
- X write(fd, buf, strlen(buf));
- X#else
- X# error unsupported UUCP locking system
- X#endif
- X close(fd);
- X }
- X tty = strdup(basename(line));
- X strlower(tty);
- X pathname2 = malloc(strlen(LOCK_DIR) + strlen(tty) + 7);
- X sprintf(pathname2, "%s/LCK..%s", LOCK_DIR, tty);
- X free(tty);
- X while (link(pathname1, pathname2) < 0)
- X {
- X if (!unlockLine(line))
- X {
- X sleep(10);
- X if ((time -= 10) <= 0)
- X {
- X ret = FALSE;
- X break;
- X }
- X }
- X }
- X unlink(pathname1);
- X free(pathname1);
- X free(pathname2);
- X return ret;
- X}
- X
- Xbool isLocked(const char *line)
- X{
- X char pathname[strlen(LOCK_DIR) + strlen(line) + 7];
- X int fd;
- X bool ret = FALSE;
- X
- X sprintf(pathname, "%s/LCK..%s", LOCK_DIR, line);
- X if ((fd = open(pathname, O_RDONLY)) >= 0)
- X {
- X int nread;
- X char buf[30];
- X
- X if ((nread = read(fd, buf, sizeof(buf))) > 0)
- X {
- X int pid;
- X
- X#if defined(M_XENIX)
- X buf[nread - 1] = '\0';
- X pid = atoi(buf);
- X#else
- X#endif
- X if (kill(pid, 0) == 0)
- X ret = TRUE;
- X }
- X }
- X return ret;
- X}
- SHAR_EOF
- true || echo 'restore of locks.c failed'
- rm -f _shar_wnt_.tmp
- fi
- # ============= mgetty.c ==============
- if test -f 'mgetty.c' -a X"$1" != X"-c"; then
- echo 'x - skipping mgetty.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting mgetty.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'mgetty.c' &&
- X/*
- X * $Id: mgetty.c,v 1.4 1993/01/15 23:06:14 wcp Exp $
- X *
- X * Copyright (C) 1992 Walter Pelissero
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of the GNU General Public License as published by
- X * the Free Software Foundation; either version 1, or (at your option)
- X * any later version.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X */
- X
- X/*
- X * $Log: mgetty.c,v $
- X * Revision 1.4 1993/01/15 23:06:14 wcp
- X * Modified CMD_receive to accept multiple tokens instead of a list.
- X *
- X * Revision 1.3 1993/01/13 21:28:37 wcp
- X * spawn() is substituted by invoke().
- X * Added CMD_slow_write(), to leave this choice at run time.
- X * Reenabled the old exec.
- X *
- X * Revision 1.2 1993/01/07 23:17:13 wcp
- X * Modified open() flags to tty for compatibility with tset.
- X *
- X * Revision 1.1 1993/01/06 18:07:40 wcp
- X * Initial revision
- X *
- X */
- X
- X#include <sys/types.h>
- X#ifdef DEBUG
- X#include <dbmalloc.h>
- X#endif
- X#include <stdio.h>
- X#include <fcntl.h>
- X#include <termio.h>
- X#include <getopt.h>
- X#include <string.h>
- X#include <ctype.h>
- X#include <errno.h>
- X#include <signal.h>
- X#include <utmp.h>
- X#include <stdlib.h>
- X#include <tcl.h>
- X#include <sys/wait.h>
- X#include "common.h"
- X#include "modemio.h"
- X
- Xconst unsigned long DEFAULT_BAUDRATE = 9600;
- X
- Xtypedef enum {
- X MD_RAW = 1,
- X MD_COOKED = 2,
- X MD_XONXOFF = 4,
- X MD_CTSRTS = 8,
- X MD_NOFLOW = 16,
- X MD_LOCAL = 32,
- X MD_REMOTE = 64
- X } TtyMode;
- X
- Xtypedef enum { UTMP_GETTY, UTMP_LOGIN, UTMP_EXIT, UTMP_PROCESS } UtmpStatus;
- X
- X#ifdef DEBUG
- Xstatic int verbosity = 9;
- X#else
- Xstatic int verbosity = 0;
- X#endif
- X
- Xconst char *myname;
- X
- Xstatic char RcsId[] = "$Id: mgetty.c,v 1.4 1993/01/15 23:06:14 wcp Exp $";
- Xstatic bool suspended = FALSE;
- Xstatic unsigned long baudrate;
- Xstatic const char *line, *site;
- Xstatic bool timedout;
- Xstatic Tcl_Interp *interp;
- Xstatic bool set_utmp(UtmpStatus, const char *, int);
- X
- X
- Xinline bool setUtmp(UtmpStatus status, const char *line)
- X{
- X return set_utmp(status, line, getpid());
- X}
- X
- Xstatic bool closeLine()
- X{
- X close(0);
- X close(1);
- X close(2);
- X return TRUE;
- X}
- X
- Xstatic SIGTYPE suspend(int sig)
- X{
- X if (!suspended)
- X {
- X suspended = TRUE;
- X signal(sig, suspend);
- X setUtmp(UTMP_PROCESS, line);
- X closeLine();
- X while(suspended)
- X sleep(1024);
- X }
- X#if SIGTYPE == int
- X return 0;
- X#endif
- X}
- X
- Xstatic SIGTYPE restart(int sig)
- X{
- X suspended = FALSE;
- X signal(sig, restart);
- X setUtmp(UTMP_LOGIN, line);
- X#if SIGTYPE == int
- X return 0;
- X#endif
- X}
- X
- Xstatic bool setMode(int mode)
- X{
- X struct termio tty_settings;
- X
- X if (ioctl(1, TCGETA, &tty_settings) < 0)
- X {
- X fprintf(stderr, "%s: can't ioctl\n", myname);
- X return FAILED;
- X }
- X if (mode & MD_RAW)
- X {
- X if (verbosity > 8)
- X fprintf(stderr, "%s: setting MD_RAW\n", myname);
- X tty_settings.c_iflag &= ~(BRKINT | ICRNL | ISTRIP);
- X tty_settings.c_cflag &= ~PARENB;
- X tty_settings.c_cflag |= (HUPCL | CSIZE | CS8 | CREAD);
- X tty_settings.c_lflag &= ~(ISIG | ECHO | ICANON);
- X tty_settings.c_cc[VMIN] = 1;
- X tty_settings.c_cc[VTIME] = 0;
- X tty_settings.c_oflag &= ~OPOST;
- X }
- X if (mode & MD_COOKED)
- X {
- X if (verbosity > 8)
- X fprintf(stderr, "%s: setting MD_COOKED\n", myname);
- X tty_settings.c_lflag |= ICANON | ECHO | ISIG | ECHOE | ECHOK;
- X tty_settings.c_iflag |= ICRNL | BRKINT | IGNPAR;
- X tty_settings.c_oflag |= ONLCR | OPOST | TAB3;
- X tty_settings.c_cc[VMIN] = 4;
- X tty_settings.c_cc[VTIME] = 0;
- X }
- X if (mode & MD_XONXOFF)
- X {
- X if (verbosity > 8)
- X fprintf(stderr, "%s: setting MD_XONXOFF\n", myname);
- X tty_settings.c_iflag |= IXON | IXANY;
- X }
- X if (mode & MD_CTSRTS)
- X {
- X if (verbosity > 8)
- X fprintf(stderr, "%s: setting MD_CTSRTS\n", myname);
- X tty_settings.c_cflag |= CTSFLOW | RTSFLOW;
- X }
- X if (mode & MD_NOFLOW)
- X {
- X if (verbosity > 8)
- X fprintf(stderr, "%s: setting MD_NOFLOW\n", myname);
- X tty_settings.c_cflag &= ~(CTSFLOW | RTSFLOW);
- X tty_settings.c_iflag &= ~(IXON | IXANY);
- X }
- X if (mode & MD_LOCAL)
- X {
- X if (verbosity > 8)
- X fprintf(stderr, "%s: setting MD_LOCAL\n", myname);
- X tty_settings.c_cflag |= CLOCAL;
- X }
- X if (mode & MD_REMOTE)
- X {
- X if (verbosity > 8)
- X fprintf(stderr, "%s: setting MD_REMOTE\n", myname);
- X tty_settings.c_cflag &= ~CLOCAL;
- X }
- X if (ioctl(1, TCSETAF, &tty_settings) < 0)
- X {
- X fprintf(stderr, "%s: can't set baud\n", myname);
- X return FAILED;
- X }
- X return SUCCEEDED;
- X}
- X
- Xstatic bool setBaudRate(unsigned speed)
- X{
- X struct termio tty_settings;
- X int baud = B38400;
- X
- X baudrate = speed;
- X if (verbosity > 5)
- X fprintf(stderr, "%s: setting baud rate to about %u\n", myname, speed);
- X if (ioctl(1, TCGETA, &tty_settings) < 0)
- X return FAILED;
- X if (speed <= 19200) baud = B19200;
- X if (speed <= 9600) baud = B9600;
- X if (speed <= 4800) baud = B4800;
- X if (speed <= 2400) baud = B2400;
- X if (speed <= 1800) baud = B1800;
- X if (speed <= 1200) baud = B1200;
- X if (speed <= 600) baud = B600;
- X if (speed <= 300) baud = B300;
- X if (speed <= 200) baud = B200;
- X if (speed <= 150) baud = B150;
- X if (speed <= 134) baud = B134;
- X if (speed <= 110) baud = B110;
- X if (speed <= 75) baud = B75;
- X if (speed <= 50) baud = B50;
- X tty_settings.c_cflag &= ~CBAUD;
- X tty_settings.c_cflag |= baud;
- X if (ioctl(1, TCSETA, &tty_settings) < 0)
- X return FAILED;
- X return SUCCEEDED;
- X}
- X
- Xstatic bool openLine(const char *portname)
- X{
- X /* If spawned from init stdin/stdout/stderr may (should?) point
- X to unopened file descriptors. */
- X close(0); close(1);
- X#ifndef DEBUG
- X close(2);
- X#endif
- X setpgrp();
- X errno = 0;
- X chdir("/dev");
- X /* The following two open()s should have O_RDONLY and O_WRONLY
- X respectively but tset (and other programs?) cannot work properly
- X if we do so. */
- X if (open(portname, (O_RDWR | O_NDELAY)) < 0 ||
- X open(portname, (O_RDWR | O_NDELAY)) < 0)
- X {
- X if (errno == EBUSY)
- X fprintf(stderr, "%s: port %s BUSY\n", myname, portname);
- X else
- X fprintf(stderr, "%s: can't connect into %s (%s)\n", myname,
- X portname, sys_errlist[errno]);
- X return FAILED;
- X }
- X setMode(MD_RAW | MD_NOFLOW | MD_LOCAL);
- X setBaudRate(DEFAULT_BAUDRATE);
- X if (fcntl(0, F_SETFL, O_RDONLY) == ERROR ||
- X fcntl(1, F_SETFL, O_WRONLY) == ERROR)
- X {
- X fprintf(stderr, "%s: can't unset O_NDELAY for %s\n", myname, portname);
- X return FAILED;
- X }
- X#ifndef DEBUG
- X dup(1);
- X#endif
- X if (verbosity > 5)
- X fprintf(stderr, "%s: line parameters set for %s\n", myname, portname);
- X return SUCCEEDED;
- X}
- X
- Xstatic bool set_utmp(UtmpStatus status, const char *line, int pid)
- X{
- X int ufd;
- X bool ret = FAILED;
- X const char *id;
- X struct utmp ut;
- X
- X id = line + strlen(line) - 2;
- X if((ufd = open(UTMP_FILE, O_RDWR | O_CREAT, 0644)) < 0)
- X return FAILED;
- X while(read(ufd, (char *)&ut, sizeof(ut)) == sizeof(ut))
- X {
- X char buf[sizeof(ut.ut_line) + 1];
- X
- X strncpy(buf, ut.ut_line, sizeof(ut.ut_line));
- X buf[sizeof(buf) - 1] = 0;
- X if((!strcmp(buf, line) || ut.ut_type == INIT_PROCESS)
- X && pid == ut.ut_pid)
- X {
- X strncpy(ut.ut_line, line, sizeof(ut.ut_line));
- X strncpy(ut.ut_id, id, sizeof(ut.ut_id));
- X ut.ut_time = time(0);
- X switch (status)
- X {
- X case UTMP_GETTY:
- X strcpy(ut.ut_name, "LOGIN");
- X ut.ut_type = LOGIN_PROCESS;
- X break;
- X case UTMP_LOGIN:
- X strcpy(ut.ut_name, "LOGIN2");
- X ut.ut_type = LOGIN_PROCESS;
- X break;
- X case UTMP_PROCESS:
- X strncpy(ut.ut_name, "DIALOUT", sizeof(ut.ut_name));
- X ut.ut_type = USER_PROCESS;
- X break;
- X case UTMP_EXIT:
- X strncpy(ut.ut_name, "LOGIN", sizeof(ut.ut_name));
- X ut.ut_type = DEAD_PROCESS;
- X break;
- X }
- X lseek(ufd, -sizeof(ut), 1);
- X write(ufd, (char *)&ut, sizeof(ut));
- X ret = SUCCEEDED;
- X if (verbosity > 8)
- X fprintf(stderr, "%s: utmp file set\n", myname);
- X break;
- X }
- X }
- X close(ufd);
- X return ret;
- X}
- X
- Xstatic SIGTYPE terminate(int sig)
- X{
- X mdhangup(1);
- X closeLine();
- X setUtmp(UTMP_EXIT, line);
- X exit(0);
- X#if SIGTYPE == int
- X return 0;
- X#endif
- X}
- X
- Xstatic char *getLoginName()
- X{
- X static char buf[80];
- X int len;
- X
- X timedout = FALSE;
- X alarm(180);
- X if ((len = read(0, buf, sizeof(buf))) > 0)
- X {
- X buf[len - 1] = 0;
- X mdwrite("\r", 1);
- X }
- X alarm(0);
- X if (timedout || len < 1)
- X {
- X mdhangup(1);
- X return 0;
- X }
- X return buf;
- X}
- X
- Xstatic void spawnGetty(char **getty_args)
- X{
- X struct termio tty_settings;
- X char getty[strlen(getty_args[0] + 1)];
- X
- X if (ioctl(1, TCGETA, &tty_settings) < 0)
- X return;
- X /* Here we have to reset HUPCL because getty tries to hang up
- X before continuing on its job.
- X Resetting CLOCAL is necessary because we want getty to be
- X aware of line losing. */
- X tty_settings.c_cflag &= ~(HUPCL | CLOCAL);
- X if (ioctl(1, TCSETAF, &tty_settings) < 0)
- X return;
- X strcpy(getty, getty_args[0]);
- X getty_args[0] = "-";
- X execv(getty, getty_args);
- X return;
- X}
- X
- Xstatic void resetSignals()
- X{
- X alarm(0);
- X signal(SIGALRM, SIG_DFL);
- X signal(SIGUSR1, SIG_DFL);
- X signal(SIGUSR2, SIG_DFL);
- X signal(SIGQUIT, SIG_DFL);
- X signal(SIGTERM, SIG_DFL);
- X signal(SIGHUP, SIG_DFL);
- X signal(SIGINT, SIG_DFL);
- X}
- X
- Xstatic void doLogin()
- X{
- X char *name;
- X
- X mdread(2, 0, 0, 0);
- X setMode(MD_REMOTE | MD_NOFLOW | MD_COOKED);
- X do
- X {
- X char buf[256];
- X
- X sprintf(buf, "\r\n\n[%u on %s]\r\n%s!login: ", baudrate, line, site);
- X if (write(1, buf, strlen(buf)) < 0)
- X {
- X name = 0;
- X break;
- X }
- X }
- X while (!(name = getLoginName()) || !strlen(name));
- X if (name)
- X {
- X if (verbosity > 4)
- X fprintf(stderr, "%s: executing login\n", myname);
- X setUtmp(UTMP_LOGIN, line);
- X if (!lockLine(line, 30))
- X return;
- X#ifdef DEBUG
- X close(2);
- X dup(1);
- X#endif
- X setMode(MD_XONXOFF);
- X resetSignals();
- X execlp("/etc/login", "login", name, (char *)0);
- X execlp("/bin/login", "login", name, (char *)0);
- X {
- X char buf[128];
- X
- X sprintf(buf, "\r\n%s: login not executable.\r\n", myname);
- X mdwrite(buf, 1);
- X }
- X }
- X sleep(1);
- X}
- X
- Xstatic SIGTYPE timeout(int sig)
- X{
- X timedout = TRUE;
- X signal(sig, timeout);
- X#if SIGTYPE == int
- X return 0;
- X#endif
- X}
- X
- X
- Xstatic int catcher(int sig)
- X{
- X fprintf(stderr, "GOT SIGNAL %u\n", sig);
- X signal(sig, catcher);
- X return 0;
- X}
- X
- Xstatic void catchSignals()
- X{
- X unsigned i;
- X
- X for (i = 0; i < NSIG; ++i) /* -wp9/20/92. */
- X if (i != SIGCLD)
- X signal(i, catcher);
- X signal(SIGALRM, timeout);
- X signal(SIGUSR1, suspend);
- X signal(SIGUSR2, terminate); /* when restarted we exit to redo all the
- X settings we may have already done. */
- X signal(SIGQUIT, terminate);
- X signal(SIGTERM, terminate);
- X signal(SIGHUP, terminate);
- X signal(SIGINT, terminate);
- X}
- X
- Xstatic int CMD_send(ClientData clientData, Tcl_Interp *interp, int argc,
- X char *argv[])
- X{
- X int i;
- X
- X if (argc < 2)
- X {
- X Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
- X " string ?string ...?\"", 0);
- X return TCL_ERROR;
- X }
- X for (i = 1; i < argc; ++i)
- X {
- X if (mdwrite(argv[i], 1) < 0)
- X {
- X Tcl_AppendResult(interp, "cannot send \"", argv[i], "\" (",
- X sys_errlist[errno], ")", 0);
- X return TCL_ERROR;
- X }
- X }
- X return TCL_OK;
- X}
- X
- Xstatic int CMD_listen(ClientData clientData, Tcl_Interp *interp, int argc,
- X char *argv[])
- X{
- X char *response;
- X
- X if (argc > 1)
- X {
- X Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], "\"", 0);
- X return TCL_ERROR;
- X }
- X while (!(response = mdread(1000, 0, 0, 0)) || strlen(response) == 0);
- X Tcl_SetResult(interp, response, TCL_STATIC);
- X return TCL_OK;
- X}
- X
- Xstatic int CMD_receive(ClientData clientData, Tcl_Interp *interp, int argc,
- X char *argv[])
- X{
- X unsigned t = 30;
- X
- X if (argc > 1)
- X t = atoi(argv[1]);
- X if (argc > 2)
- X {
- X const char *p;
- X
- X if (p = mdread(t, 0, (const char **)argv + 2, 0))
- X Tcl_SetResult(interp, (char *)p, TCL_VOLATILE);
- X else
- X Tcl_SetResult(interp, "", TCL_STATIC);
- X }
- X else
- X {
- X char *p = mdread(t, 0, 0, 0);
- X
- X if (p)
- X Tcl_SetResult(interp, p, TCL_STATIC);
- X else
- X Tcl_SetResult(interp, "", TCL_STATIC);
- X }
- Xreturn TCL_OK;
- X}
- X
- Xstatic int CMD_flush_input(ClientData clientData, Tcl_Interp *interp,
- X int argc, char *argv[])
- X{
- X if (argc > 1)
- X {
- X Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
- X "\"", 0);
- X return TCL_ERROR;
- X }
- X mdflushin(0);
- X return TCL_OK;
- X}
- X
- Xstatic int CMD_hangup(ClientData clientData, Tcl_Interp *interp, int argc,
- X char *argv[])
- X{
- X if (argc > 1)
- X {
- X Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
- X "\"", 0);
- X return TCL_ERROR;
- X }
- X mdhangup(1);
- X return TCL_OK;
- X}
- X
- X/* This is mainly an exec (Tcl command) reedition to better follow
- X some need related to DCE handling. Input, output streams are
- X redirected to tty so invoked programs can deal with it. Output
- X is not collected in any way. */
- Xstatic int CMD_invoke(ClientData clientData, Tcl_Interp *interp, int argc,
- X char *argv[])
- X{
- X int *pidPtr;
- X
- X /* See if the command is to be run in background; if so, create
- X the command, detach it, and return. */
- X if ((argv[argc-1][0] == '&') && (argv[argc-1][1] == 0))
- X {
- X int numPids;
- X
- X argc--;
- X argv[argc] = NULL;
- X numPids = Tcl_CreatePipeline(interp, argc-1, argv+1, &pidPtr,
- X (int *) NULL, (int *) NULL, (int *) NULL);
- X if (numPids < 0)
- X return TCL_ERROR;
- X Tcl_DetachPids(numPids, pidPtr);
- X }
- X else
- X {
- X int numPids, i, rvalue;
- X char buf[32];
- X
- X lockLine(line, 30);
- X setUtmp(UTMP_PROCESS, line);
- X numPids = Tcl_CreatePipeline(interp, argc-1, argv+1, &pidPtr,
- X (int *) NULL, (int *) NULL, (int *) NULL);
- X if (numPids < 0)
- X return TCL_ERROR;
- X /* This ensure last process on pipe has value saved
- X in rvalue, bacuse we must return it. */
- X for (i = 0; i < numPids; i++)
- X {
- X int pid;
- X
- X pid = Tcl_WaitPids(1, &pidPtr[i], (int *) &rvalue);
- X if (pid == -1)
- X {
- X Tcl_AppendResult(interp, "error waiting for process to exit: ",
- X Tcl_UnixError(interp), (char *) NULL);
- X continue;
- X }
- X }
- X rvalue = (WIFEXITED(rvalue)) ? WEXITSTATUS(rvalue) : -1;
- X if (verbosity > 6)
- X fprintf(stderr, "%s: invoked program returned %d\n", myname, rvalue);
- X sprintf(buf, "%d", rvalue);
- X Tcl_SetResult(interp, buf, TCL_VOLATILE);
- X unlockLine(line);
- X setUtmp(UTMP_GETTY, line);
- X }
- X ckfree((char *) pidPtr);
- X return TCL_OK;
- X}
- X
- Xstatic int CMD_mode(ClientData clientData, Tcl_Interp *interp, int argc,
- X char *argv[])
- X{
- X int i;
- X
- X if (argc < 2)
- X {
- X Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
- X " mode ?mode ...?\"", 0);
- X return TCL_ERROR;
- X }
- X for (i = 1; i < argc; ++i)
- X {
- X if (!strcomp(argv[i], "raw"))
- X setMode(MD_RAW);
- X else if (!strcomp(argv[i], "cooked"))
- X setMode(MD_COOKED);
- X else if (!strcomp(argv[i], "xon_xoff"))
- X setMode(MD_XONXOFF);
- X else if (!strcomp(argv[i], "cts_rts"))
- X setMode(MD_CTSRTS);
- X else if (!strcomp(argv[i], "no_flow"))
- X setMode(MD_NOFLOW);
- X else if (!strcomp(argv[i], "local"))
- X setMode(MD_LOCAL);
- X else if (!strcomp(argv[i], "remote"))
- X setMode(MD_REMOTE);
- X else
- X {
- X Tcl_AppendResult(interp, "unrecognized flag \"", argv[i], "\"", 0);
- X return TCL_ERROR;
- X }
- X }
- X return TCL_OK;
- X}
- X
- Xstatic int CMD_baudrate(ClientData clientData, Tcl_Interp *interp, int argc,
- X char *argv[])
- X{
- X char buf[16];
- X
- X if (argc > 2)
- X {
- X Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
- X " baud_rate\"", 0);
- X return TCL_ERROR;
- X }
- X if (argc > 1)
- X setBaudRate(atoi(argv[1]));
- X sprintf(buf, "%u", baudrate);
- X Tcl_SetResult(interp, buf, TCL_VOLATILE);
- X return TCL_OK;
- X}
- X
- Xstatic int CMD_login(ClientData clientData, Tcl_Interp *interp, int argc,
- X char *argv[])
- X{
- X if (argc > 1)
- X {
- X Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
- X "\"", 0);
- X return TCL_ERROR;
- X }
- X doLogin();
- X /* Should not return. */
- X Tcl_SetResult(interp, "error in login process", TCL_STATIC);
- X return TCL_ERROR;
- X}
- X
- Xstatic int CMD_sleep(ClientData clientData, Tcl_Interp *interp, int argc,
- X char *argv[])
- X{
- X if (argc != 2)
- X {
- X Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
- X " seconds\"", 0);
- X return TCL_ERROR;
- X }
- X sleep(atoi(argv[1]));
- X return TCL_OK;
- X}
- X
- X#if DEBUG > 7
- Xvoid Tcl_DEBUG(ClientData clientData, Tcl_Interp *interp, int level,
- X char *command, Tcl_CmdProc *cmdProc, ClientData cmdClientData,
- X int argc, char *argv[])
- X{
- X int i;
- X
- X fprintf(stderr, "%s: TRACE: [%u] %s --", myname, level, command);
- X for (i = 0; i < argc; ++i)
- X fprintf(stderr, " [%s]", argv[i]);
- X putc('\n', stderr);
- X}
- X#endif /* DEBUG */
- X
- Xint CMD_exit(ClientData dummy, Tcl_Interp *interp, int argc, char *argv[])
- X{
- X if ((argc != 1) && (argc != 2))
- X {
- X Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
- X " ?returnCode?\"", (char *) NULL);
- X return TCL_ERROR;
- X }
- X mdhangup(1);
- X closeLine();
- X setUtmp(UTMP_EXIT, line);
- X if (argc == 1)
- X exit(0);
- X exit(atoi(argv[1]));
- X return TCL_ERROR;
- X}
- X
- X
- Xstatic void setBits(int flag, bool on, unsigned short *field)
- X{
- X if (on)
- X *field |= flag;
- X else
- X *field &= ~flag;
- X}
- X
- Xstatic int CMD_slow_write(ClientData clientData, Tcl_Interp *interp, int argc,
- X char *argv[])
- X{
- X if (argc > 2)
- X {
- X Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
- X " ?ON|OFF|1|0|TRUE|FALSE|TOGGLE?\"", 0);
- X return TCL_ERROR;
- X }
- X if (argc > 1)
- X {
- X char *p = argv[1];
- X
- X if (!strcomp(p, "ON") || !strcomp(p, "1") || !strcomp(p, "TRUE"))
- X mdslowrite = TRUE;
- X else if (!strcomp(p, "OFF") || !strcomp(p, "0") || !strcomp(p, "FALSE"))
- X mdslowrite = FALSE;
- X else if (!strcomp(p, "TOGGLE"))
- X mdslowrite = !mdslowrite;
- X else
- X {
- X Tcl_AppendResult(interp, "unrecognized flag \"", p, "\"", 0);
- X return TCL_ERROR;
- X }
- X }
- X Tcl_SetResult(interp, mdslowrite ? "ON" : "OFF", TCL_STATIC);
- X return TCL_OK;
- X}
- X
- X/* THIS FUNCTION IS NOT COMPLETE AT ALL!! -wp9/20/92. */
- X
- Xstatic int CMD_stty(ClientData clientData, Tcl_Interp *interp, int argc,
- X char *argv[])
- X{
- X int i;
- X struct termio tty;
- X
- X if (argc < 2)
- X {
- X Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
- X " mode ?mode ...?\"", 0);
- X return TCL_ERROR;
- X }
- X if (ioctl(1, TCGETA, &tty) < 0)
- X {
- X Tcl_SetResult(interp, "cannot get current line setting", TCL_STATIC);
- X return TCL_ERROR;
- X }
- X for (i = 1; i < argc; ++i)
- X {
- X char *p = argv[i];
- X
- X if (*p == '-')
- X ++p;
- X /* Input flags */
- X if (!strcomp(p, "IGNBRK"))
- X setBits(IGNBRK, p == argv[i], &tty.c_iflag);
- X else if (!strcomp(p, "BRKINT"))
- X setBits(BRKINT, p == argv[i], &tty.c_iflag);
- X else if (!strcomp(p, "IGNPAR"))
- X setBits(IGNPAR, p == argv[i], &tty.c_iflag);
- X else if (!strcomp(p, "PARMRK"))
- X setBits(PARMRK, p == argv[i], &tty.c_iflag);
- X else if (!strcomp(p, "INPCK"))
- X setBits(INPCK, p == argv[i], &tty.c_iflag);
- X else if (!strcomp(p, "ISTRIP"))
- X setBits(ISTRIP, p == argv[i], &tty.c_iflag);
- X else if (!strcomp(p, "INLCR"))
- X setBits(INLCR, p == argv[i], &tty.c_iflag);
- X else if (!strcomp(p, "IGNCR"))
- X setBits(IGNCR, p == argv[i], &tty.c_iflag);
- X else if (!strcomp(p, "ICRNL"))
- X setBits(ICRNL, p == argv[i], &tty.c_iflag);
- X else if (!strcomp(p, "IUCLC"))
- X setBits(IUCLC, p == argv[i], &tty.c_iflag);
- X else if (!strcomp(p, "IXON"))
- X setBits(IXON, p == argv[i], &tty.c_iflag);
- X else if (!strcomp(p, "IXANY"))
- X setBits(IXANY, p == argv[i], &tty.c_iflag);
- X else if (!strcomp(p, "IXOFF"))
- X setBits(IXOFF, p == argv[i], &tty.c_iflag);
- X#ifdef DOSMODE
- X else if (!strcomp(p, "DOSMODE"))
- X setBits(DOSMODE, p == argv[i], &tty.c_iflag);
- X#endif
- X /* Output flags */
- X else if (!strcomp(p, "OPOST"))
- X setBits(OPOST, p == argv[i], &tty.c_oflag);
- X else if (!strcomp(p, "OLCUC"))
- X setBits(OLCUC, p == argv[i], &tty.c_oflag);
- X else if (!strcomp(p, "ONLCR"))
- X setBits(ONLCR, p == argv[i], &tty.c_oflag);
- X else if (!strcomp(p, "OCRNL"))
- X setBits(OCRNL, p == argv[i], &tty.c_oflag);
- X else if (!strcomp(p, "ONOCR"))
- X setBits(ONOCR, p == argv[i], &tty.c_oflag);
- X else if (!strcomp(p, "ONLRET"))
- X setBits(ONLRET, p == argv[i], &tty.c_oflag);
- X else if (!strcomp(p, "OFILL"))
- X setBits(OFILL, p == argv[i], &tty.c_oflag);
- X else if (!strcomp(p, "OFDEL"))
- X setBits(OFDEL, p == argv[i], &tty.c_oflag);
- X else if (!strcomp(p, "NL0"))
- X if (p != argv[i])
- X break;
- X else
- X setBits(NL1, FALSE, &tty.c_oflag);
- X else if (!strcomp(p, "NL1"))
- X if (p != argv[i])
- X break;
- X else
- X setBits(NL1, TRUE, &tty.c_oflag);
- X else if (!strcomp(p, "CR0"))
- X if (p != argv[i])
- X break;
- X else
- X setBits(CRDLY, FALSE, &tty.c_oflag);
- X else if (!strcomp(p, "CR1"))
- X if (p != argv[i])
- X break;
- X else setBits(CR1, TRUE, &tty.c_oflag);
- X else if (!strcomp(p, "CR2"))
- X if (p != argv[i])
- X break;
- X else setBits(CR2, TRUE, &tty.c_oflag);
- X else if (!strcomp(p, "CR3"))
- X if (p != argv[i])
- X break;
- X else setBits(CR3, TRUE, &tty.c_oflag);
- X else if (!strcomp(p, "TAB0"))
- X if (p != argv[i])
- X break;
- X else setBits(TAB0, p == argv[i], &tty.c_oflag);
- X else if (!strcomp(p, "TAB1"))
- X if (p != argv[i])
- X break;
- X else setBits(TAB1, p == argv[i], &tty.c_oflag);
- X else if (!strcomp(p, "TAB2"))
- X if (p != argv[i])
- X break;
- X else setBits(TAB2, p == argv[i], &tty.c_oflag);
- X else if (!strcomp(p, "TAB3"))
- X if (p != argv[i])
- X break;
- X else setBits(TAB3, p == argv[i], &tty.c_oflag);
- X else if (!strcomp(p, "BS0"))
- X if (p != argv[i])
- X break;
- X else setBits(BS0, p == argv[i], &tty.c_oflag);
- X else if (!strcomp(p, "BS1"))
- X if (p != argv[i])
- X break;
- X else setBits(BS1, p == argv[i], &tty.c_oflag);
- X else if (!strcomp(p, "VT0"))
- X if (p != argv[i])
- X break;
- X else setBits(VT0, p == argv[i], &tty.c_oflag);
- X else if (!strcomp(p, "VT1"))
- X if (p != argv[i])
- X break;
- X else setBits(VT1, p == argv[i], &tty.c_oflag);
- X else if (!strcomp(p, "FF0"))
- X if (p != argv[i])
- X break;
- X else setBits(FF0, p == argv[i], &tty.c_oflag);
- X else if (!strcomp(p, "FF1"))
- X if (p != argv[i])
- X break;
- X else setBits(FF1, p == argv[i], &tty.c_oflag);
- X /* Control flags */
- X else if (!strcomp(p, "B0"))
- X if (p != argv[i])
- X break;
- X else setBits(B0, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "B50"))
- X if (p != argv[i])
- X break;
- X else setBits(B50, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "B75"))
- X if (p != argv[i])
- X break;
- X else setBits(B75, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "B110"))
- X if (p != argv[i])
- X break;
- X else setBits(B110, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "B134"))
- X if (p != argv[i])
- X break;
- X else setBits(B134, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "B150"))
- X if (p != argv[i])
- X break;
- X else setBits(B150, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "B200"))
- X if (p != argv[i])
- X break;
- X else setBits(B200, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "B300"))
- X if (p != argv[i])
- X break;
- X else setBits(B300, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "B600"))
- X if (p != argv[i])
- X break;
- X else setBits(B600, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "B1200"))
- X if (p != argv[i])
- X break;
- X else setBits(B1200, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "B1800"))
- X if (p != argv[i])
- X break;
- X else setBits(B1800, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "B2400"))
- X if (p != argv[i])
- X break;
- X else setBits(B2400, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "B4800"))
- X if (p != argv[i])
- X break;
- X else setBits(B4800, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "B9600"))
- X if (p != argv[i])
- X break;
- X else setBits(B9600, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "B19200") || !strcomp(p, "EXTA"))
- X if (p != argv[i])
- X break;
- X else setBits(B19200, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "B38400") || !strcomp(p, "EXTB"))
- X if (p != argv[i])
- X break;
- X else setBits(B38400, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "CS5"))
- X if (p != argv[i])
- X break;
- X else setBits(CS5, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "CS6"))
- X if (p != argv[i])
- X break;
- X else setBits(CS6, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "CS7"))
- X if (p != argv[i])
- X break;
- X else setBits(CS7, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "CS8"))
- X if (p != argv[i])
- X break;
- X else setBits(CS8, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "CSTOPB"))
- X setBits(CSTOPB, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "CREAD"))
- X setBits(CREAD, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "PARENB"))
- X setBits(PARENB, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "PARODD"))
- X setBits(PARODD, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "HUPCL"))
- X setBits(HUPCL, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "CLOCAL"))
- X setBits(CLOCAL, p == argv[i], &tty.c_cflag);
- X else if (!strcomp(p, "LOBLK"))
- X setBits(LOBLK, p == argv[i], &tty.c_cflag);
- X#ifdef CTSFLOW
- X else if (!strcomp(p, "CTSFLOW"))
- X setBits(CTSFLOW, p == argv[i], &tty.c_cflag);
- X#endif
- X#ifdef RTSFLOW
- X else if (!strcomp(p, "RTSFLOW"))
- X setBits(RTSFLOW, p == argv[i], &tty.c_cflag);
- X#endif
- X /* Line discipline flags */
- X else if (!strcomp(p, "ISIG"))
- X setBits(ISIG, p == argv[i], &tty.c_lflag);
- X else if (!strcomp(p, "ICANON"))
- X setBits(ICANON, p == argv[i], &tty.c_lflag);
- X else if (!strcomp(p, "XCASE"))
- X setBits(XCASE, p == argv[i], &tty.c_lflag);
- X else if (!strcomp(p, "ECHO"))
- X setBits(ECHO, p == argv[i], &tty.c_lflag);
- X else if (!strcomp(p, "ECHOE"))
- X setBits(ECHOE, p == argv[i], &tty.c_lflag);
- X else if (!strcomp(p, "ECHOK"))
- X setBits(ECHOK, p == argv[i], &tty.c_lflag);
- X else if (!strcomp(p, "ECHONL"))
- X setBits(ECHONL, p == argv[i], &tty.c_lflag);
- X else if (!strcomp(p, "NOFLSH"))
- X setBits(NOFLSH, p == argv[i], &tty.c_lflag);
- X else if (!strcomp(p, "XCLUDE"))
- X setBits(XCLUDE, p == argv[i], &tty.c_lflag);
- X else
- X break;
- X }
- X if (i < argc)
- X {
- X Tcl_AppendResult(interp, "unrecognized flag \"", argv[i], "\"", 0);
- X return TCL_ERROR;
- X }
- X if (ioctl(1, TCSETAF, &tty) < 0)
- X {
- X Tcl_SetResult(interp, "cannot set line parameters", TCL_STATIC);
- X return TCL_ERROR;
- X }
- X return TCL_OK;
- X}
- X
- Xstatic void createTclEnvironment()
- X{
- X interp = Tcl_CreateInterp ();
- X Tcl_CreateCommand(interp, "listen", CMD_listen, 0, 0);
- X Tcl_CreateCommand(interp, "send", CMD_send, 0, 0);
- X Tcl_CreateCommand(interp, "receive", CMD_receive, 0, 0);
- X Tcl_CreateCommand(interp, "flush_input", CMD_flush_input, 0, 0);
- X Tcl_CreateCommand(interp, "hangup", CMD_hangup, 0, 0);
- X Tcl_CreateCommand(interp, "login", CMD_login, 0, 0);
- X Tcl_CreateCommand(interp, "invoke", CMD_invoke, 0, 0);
- X Tcl_CreateCommand(interp, "mode", CMD_mode, 0, 0);
- X Tcl_CreateCommand(interp, "baudrate", CMD_baudrate, 0, 0);
- X Tcl_CreateCommand(interp, "stty", CMD_stty, 0, 0);
- X Tcl_CreateCommand(interp, "sleep", CMD_sleep, 0, 0);
- X Tcl_CreateCommand(interp, "slow_write", CMD_slow_write, 0, 0);
- X Tcl_DeleteCommand(interp, "exit");
- X Tcl_CreateCommand(interp, "exit", CMD_exit, 0, 0);
- X#if DEBUG > 7
- X Tcl_CreateTrace(interp, 5, Tcl_DEBUG, 0);
- X#endif
- X}
- X
- Xstatic bool processInitFile()
- X{
- X char pathname[256];
- X
- X sprintf(pathname, "%s/ttys/%s", LIB_DIR, line);
- X if (access(pathname, R_OK) == 0)
- X {
- X if (Tcl_EvalFile(interp, pathname) == TCL_OK)
- X return SUCCEEDED;
- X else
- X fprintf(stderr, "%s: error in tcl script (\"%s\" at line %u)\n",
- X myname, interp->result, interp->errorLine);
- X }
- X return FALSE;
- X}
- X
- Xint main(unsigned argc, char *argv[])
- X{
- X#ifdef notdef
- X mdslowrite = TRUE;
- X#endif
- X myname = basename(argv[0]);
- X site = siteName();
- X#ifdef DEBUG
- X if (!isatty(fileno(stderr)))
- X {
- X /* If spawned from init stdin/stdout/stderr may (should?) point
- X to unopened file descriptors. */
- X close(0); close(1); close(2);
- X open("/dev/null", O_RDONLY);
- X dup(open("/tmp/getty-stderr", O_WRONLY | O_CREAT | O_APPEND, 0644));
- X }
- X#endif
- X optind = 1; /* the first argument is the real getty -wp9/20/92. */
- X mdverbosity = verbosity;
- X#if defined(M_XENIX) || defined(BSD)
- X line = argv[optind + 1];
- X#else
- X line = argv[argc - 1];
- X#endif
- X if (isLocked(line))
- X exit(1);
- X createTclEnvironment();
- X if (!openLine(line))
- X {
- X fprintf(stderr, "%s: cannot open assigned tty\n", myname);
- X exit(6);
- X }
- X catchSignals();
- X if (!setUtmp(UTMP_GETTY, line))
- X {
- X fprintf(stderr, "%s: no slot in utmp\n", myname);
- X exit(5);
- X }
- X if (!processInitFile())
- X spawnGetty(argv + optind);
- X mdhangup(1);
- X closeLine();
- X setUtmp(UTMP_EXIT, line);
- X return exit(0), 0;
- X}
- SHAR_EOF
- true || echo 'restore of mgetty.c failed'
- rm -f _shar_wnt_.tmp
- fi
- # ============= modemio.c ==============
- if test -f 'modemio.c' -a X"$1" != X"-c"; then
- echo 'x - skipping modemio.c (File already exists)'
- rm -f _shar_wnt_.tmp
- else
- > _shar_wnt_.tmp
- echo 'x - extracting modemio.c (Text)'
- sed 's/^X//' << 'SHAR_EOF' > 'modemio.c' &&
- X/*
- X * $Id: modemio.c,v 1.1 1993/01/06 18:09:44 wcp Exp $
- X *
- X * Copyright (C) 1992 Walter Pelissero
- X *
- X * This program is free software; you can redistribute it and/or modify
- X * it under the terms of the GNU General Public License as published by
- X * the Free Software Foundation; either version 1, or (at your option)
- X * any later version.
- X *
- X * This program is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- X * GNU General Public License for more details.
- X *
- X * You should have received a copy of the GNU General Public License
- X * along with this program; if not, write to the Free Software
- X * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X */
- X
- X/*
- X * $Log: modemio.c,v $
- X * Revision 1.1 1993/01/06 18:09:44 wcp
- X * Initial revision
- X *
- X */
- X
- X#include <sys/types.h>
- X#ifdef DEBUG
- X#include <dbmalloc.h>
- X#endif
- X#include <string.h>
- X#include <signal.h>
- X#include <stdio.h>
- X#include <stdlib.h>
- X#include <termio.h>
- X#include "common.h"
- X
- Xstatic char RcsId[] = "$Id: modemio.c,v 1.1 1993/01/06 18:09:44 wcp Exp $";
- Xbool mdtimedout;
- Xunsigned mdverbosity = 0;
- Xbool mdslowrite = FALSE;
- Xextern const char *myname;
- Xchar mdread_buffer[1024];
- Xstatic SIGTYPE (*exsa)(int), (*exsh)(int);
- X
- Xstatic SIGTYPE timeout(int sig)
- X{
- X mdtimedout = TRUE;
- X#if SIGTYPE == int
- X return 0;
- X#endif
- X}
- X
- Xstatic void getSignals()
- X{
- X exsa = signal(SIGALRM, timeout);
- X exsh = signal(SIGHUP, timeout);
- X mdtimedout = FALSE;
- X}
- X
- Xstatic void relSignals()
- X{
- X alarm(0);
- X signal(SIGALRM, exsa);
- X signal(SIGHUP, exsh);
- X}
- X
- X/*
- X * substr(s, l)
- X *
- X * Function: Checks for the presence of the string pointed to by s
- X * somewhere within the string pointed to by l.
- X *
- X * Returns: 0 if found.
- X * -1 if not found.
- X */
- Xstatic int substr(const char *s, const char *l)
- X{
- X int len;
- X
- X len = strlen(s);
- X while ((l = strchr(l, *s)) != NULL)
- X {
- X if (!strncmp(s, l, len))
- X return(0);
- X l++;
- X }
- X return(-1);
- X}
- X
- X/*
- X * mdwrite(c)
- X *
- X * Function: Outputs the string pointed to by c to the ACU device.
- X *
- X * Returns: 0 on completion.
- X * -1 on write errors.
- X *
- X */
- Xint mdwrite(const char *c, int fd)
- X{
- X getSignals();
- X if (mdverbosity > 6)
- X fprintf(stderr, "%s: sent modem <<", myname);
- X while (*c)
- X {
- X alarm(1);
- X if (mdtimedout || write(fd, c, 1) != 1)
- X {
- X relSignals();
- X if (mdverbosity > 6)
- X fprintf(stderr, ">>-FAIL\n");
- X fprintf(stderr, "%s: acu write error (%s)\n", myname,
- X sys_errlist[errno]);
- X return(-1);
- X }
- X if (mdverbosity > 6)
- X fprintf(stderr, "%s", vgets(*c));
- X if (mdslowrite)
- X nap(100);
- X c++;
- X }
- X relSignals();
- X if (mdverbosity > 6)
- X fprintf(stderr, ">>-OK\n");
- X return(0);
- X}
- X
- X/*
- X *
- X * Function: Reads from the ACU until it finds a valid response (found
- X * in ModemAnswers) or times out after rtime seconds.
- X *
- X * Returns: The index in ModemAnswers of the modem response found.
- X * -1 on timeout.
- X *
- X */
- Xchar *mdread(unsigned rtime, int fd, const char **tokens, unsigned *ret)
- X{
- X char *bp = mdread_buffer, *rp = bp;
- X unsigned char c;
- X
- X getSignals();
- X if (mdverbosity > 6)
- X fprintf(stderr, "%s: modem returned <<", myname);
- X errno = 0;
- X alarm(rtime);
- X while (!mdtimedout && read(fd, &c, 1) == 1)
- SHAR_EOF
- true || echo 'restore of modemio.c failed'
- fi
- echo 'End of mgetty-1.0 part 2'
- echo 'File modemio.c is continued in part 3'
- echo 3 > _shar_seq_.tmp
- exit 0
-
- --
- P4 32 8 @A ^@@A ^@@Ax^@@A ^@DA"^@D]%xJe&H1\236\331\306
-