diff options
author | kris <kris@FreeBSD.org> | 1999-05-29 08:16:34 +0000 |
---|---|---|
committer | kris <kris@FreeBSD.org> | 1999-05-29 08:16:34 +0000 |
commit | 659ebc8fe981009c3b83c02a6d6fcff5451635a6 (patch) | |
tree | 67961c709ee71d872f88d3707b8d7176fcf9b0b6 | |
parent | f05e990fab040bb75d0219645009195e1f72f95a (diff) | |
download | FreeBSD-src-659ebc8fe981009c3b83c02a6d6fcff5451635a6.zip FreeBSD-src-659ebc8fe981009c3b83c02a6d6fcff5451635a6.tar.gz |
$Header$ -> $Id$
Manpage formatting/grammatical fixes.
Check return value of malloc()
Add sccsid[], other minor source code cleanups
Submitted by: Philippe Charnier
-rw-r--r-- | sbin/slattach/Makefile | 2 | ||||
-rw-r--r-- | sbin/slattach/slattach.8 | 86 | ||||
-rw-r--r-- | sbin/slattach/slattach.c | 40 |
3 files changed, 70 insertions, 58 deletions
diff --git a/sbin/slattach/Makefile b/sbin/slattach/Makefile index e0e1a0a..86b3870 100644 --- a/sbin/slattach/Makefile +++ b/sbin/slattach/Makefile @@ -1,6 +1,6 @@ # @(#)Makefile 5.4 (Berkeley) 5/11/90 # -# $Header: /home/ncvs/src/sbin/slattach/Makefile,v 1.6 1995/09/20 12:56:23 ache Exp $ +# $Id$ PROG= slattach SRCS= slattach.c diff --git a/sbin/slattach/slattach.8 b/sbin/slattach/slattach.8 index 9afa051..b0a23c6 100644 --- a/sbin/slattach/slattach.8 +++ b/sbin/slattach/slattach.8 @@ -31,7 +31,7 @@ .\" .\" @(#)slattach.8 6.4 (Berkeley) 3/16/91 .\" -.\" $Header: /home/ncvs/src/sbin/slattach/slattach.8,v 1.12 1997/01/13 00:25:46 wosch Exp $ +.\" $Id$ .\" .Dd April 4, 1993 .Dt SLATTACH 8 @@ -61,35 +61,35 @@ .Nm Slattach is used to assign a tty line to a network interface, and to define the network source and destination addresses. -The following operands are supported by -.Nm slattach : -.Bl -tag -width Ar +.Pp +The following options are available: +.Bl -tag -width indent .It Fl a Autoenable the VJ header compression option, if the other end of the link is capable of VJ header compression then it will be used otherwise normal headers will be used. .It Fl c -Enables the VJ header compression option. Note that both ends of the link +Enable the VJ header compression option. Note that both ends of the link must be able to use VJ header compression for this to work. .It Fl e Ar exit-command -Specifies a command to be invoked within a shell +Specify a command to be invoked within a shell .Ql sh \-c Ar exit-command before -.Nm slattach +.Nm exits. .It Fl f -Disables the invocation of daemon() to run -.Nm slattach +Disable the invocation of daemon() to run +.Nm in the background. .It Fl h Turn on cts/rts style flow control on the slip port, by default no flow control is done. .It Fl l -disable modem control (CLOCAL) and ignore carrier detect on the slip +Disable modem control (CLOCAL) and ignore carrier detect on the slip port. By default the .Ar redial-command is invoked upon carrier drop and -.Nm slattach +.Nm aborts if no .Ar redial-command is specified. @@ -97,49 +97,51 @@ is specified. Throw away ICMP packets. The slip interface will ignore ICMP packets to prevent slow lines being saturated by ICMP responses. .It Fl r Ar redial-command -Specifies a command to be invoked within a shell +Specify a command to be invoked within a shell .Ql sh \-c Ar redial-command whenever carrier is lost on the modem line. Empty .Ar redial-command -i.e. -.Fl r Qq "" +(i.e. +.Fl r Qq "" ) cause connection reestablishing on leased line without any external command invoked. .It Fl s Ar baudrate -Specifies the speed of the connection. If not specified, the +Specify the speed of the connection. If not specified, the default of 9600 is used. .It Fl u Ar unit-command When the line is switched to slip discipline, run -.Ql Nm "sh -c" Ar unit-command <old> <new> +.Ql Nm "sh -c" Ar unit-command old new where -.Ar <old> +.Ar old and -.Ar <new> +.Ar new are the slip unit numbers when the line was last opened and the unit number of the current slip connection respectively. The unit number can change after redialing if you are using more than one slip line. When -.Nm slattach -connected first time, it run -.Ql Nm "sh -c" Ar unit-command Nm \-1 Ar <new> . +.Nm +is connected for the first time, +.Ql Nm "sh -c" Ar unit-command Nm \-1 Ar new +is run. When -.Nm slattach -disconnected, it run -.Ql Nm "sh -c" Ar unit-command <old> Nm \-1 . +.Nm +is disconnected, +.Ql Nm "sh -c" Ar unit-command old Nm \-1 +is run. .Nm Slattach will abort if the unit number changes and .Ql Fl u Ar \%unit-command was not specified. .It Fl z -forces redial +Force redial .Ar redial-command upon startup irrespective of carrier. .It Fl L Use uucp-style device locking. You need it unless you start -.Nm slattach +.Nm from external program which already does uucp locking. Default case is no uucp locking to satisfy such programs. .It Fl K Ar keepalive @@ -156,7 +158,7 @@ Set the SLIP unit number directly. Use with caution, because no check is made for two interfaces with same number. By default sliplogin dynamically assigns the unit number. .It Ar ttyname -Specifies the name of the tty device. +Specify the name of the tty device. .Ar Ttyname should be a string of the form .Ql ttyXX @@ -169,15 +171,15 @@ Only the super-user may attach a network interface. To detach the interface, use .Dq Li ifconfig interface-name down after killing off the -.Nm slattach +.Nm process using .Ql kill -INT . .Ar Interface-name is the name that is shown by -.Xr netstat 1 +.Xr netstat 1 . .Pp To setup -.Nm slattach +.Nm to redial the phone when carrier is lost, use the .Fl r Ar redial-command option to specify a script or executable that will reconnect the @@ -199,7 +201,7 @@ than one line disconnect at the same time. The first to succeed in reconnecting will get the lowest unit number. .Pp To kill -.Nm slattach +.Nm use .Ql kill -INT (SIGINT) which causes it to close the tty and exit. @@ -207,13 +209,13 @@ use To force a redial, use .Ql kill -HUP (SIGHUP) which causes -.Nm slattach +.Nm to think carrier was lost and thus invoke .Ql sh \-c Ar redial-command to reconnect to the server. .Pp If you use a hard-wired connection rather than a modem, invoke -.Nm slattach +.Nm with the .Fl l option in order to ignore carrier on the slip line. @@ -225,8 +227,9 @@ slattach \-c \-s 38400 /dev/cuaa1 slattach \-r 'kermit -y dial.script >kermit.log 2>&1' .Ed .Sh DIAGNOSTICS -Look for error messages in /var/log/messages ( -.Nm slattach +Look for error messages in +.Pa /var/log/messages +.Pf ( Nm slattach is a daemon). Messages indicating the specified interface does not exit, the requested address is unknown, the user is not privileged and tried to @@ -237,16 +240,18 @@ signal handlers. Upon connection and redial the ttyname and baud rate are logged and on shutdown the ttyname is logged. .Pp .Sh FILES -.Pa /var/run/slattach.<tty>.pid , -.Pp +.Bl -tag -width /usr/share/examples/slattach/* -compact +.It Pa /var/run/slattach.<tty>.pid with .Ar tty replaced by the terminal path name component of .Ar ttyname . This file contains the numerical process ID of the -.Nm slattach +.Nm process and can be examined by scripts in order to send a signal to -.Nm slattach . +.Nm +.It Pa /usr/share/examples/slattach/* +.El .Sh SEE ALSO .Xr netstat 1 , .Xr startslip 1 , @@ -254,8 +259,7 @@ process and can be examined by scripts in order to send a signal to .Xr netintro 4 , .Xr ifconfig 8 , .Xr rc 8 , -.Xr sliplogin 8 , -/usr/share/examples/slattach +.Xr sliplogin 8 .Sh HISTORY The .Nm diff --git a/sbin/slattach/slattach.c b/sbin/slattach/slattach.c index 892560c..3e77c12 100644 --- a/sbin/slattach/slattach.c +++ b/sbin/slattach/slattach.c @@ -35,20 +35,22 @@ */ #ifndef lint -static char copyright[] = +static const char copyright[] = "@(#) Copyright (c) 1988 Regents of the University of California.\n\ All rights reserved.\n"; #endif /* not lint */ #ifndef lint -/*static char sccsid[] = "from: @(#)slattach.c 4.6 (Berkeley) 6/1/90";*/ -static char rcsid[] = "$Id: slattach.c,v 1.32 1998/06/28 20:33:36 bde Exp $"; +#if 0 +static char sccsid[] = "from: @(#)slattach.c 4.6 (Berkeley) 6/1/90"; +#endif +static const char rcsid[] = + "$Id$"; #endif /* not lint */ #include <sys/types.h> #include <sys/ioctl.h> #include <sys/socket.h> -#include <sys/time.h> #include <err.h> #include <fcntl.h> @@ -75,7 +77,7 @@ void exit_handler(int ret); /* run exit_cmd iff specified upon exit. */ void setup_line(int cflag); /* configure terminal settings */ void slip_discipline(); /* switch to slip line discipline */ void configure_network(); /* configure slip interface */ -void acquire_line(); /* get tty device as controling terminal */ +void acquire_line(); /* get tty device as controlling terminal */ static void usage __P((void)); int fd = -1; @@ -94,7 +96,7 @@ int keepal = 0; /* keepalive timeout */ int outfill = 0; /* outfill timeout */ int sl_unit = -1; /* unit number */ int uucp_lock = 0; /* do uucp locking */ -int exiting = 0; /* allready running exit_handler */ +int exiting = 0; /* already running exit_handler */ struct termios tty; /* tty configuration/state */ @@ -117,8 +119,6 @@ int main(int argc, char **argv) { int option; - extern char *optarg; - extern int optind; while ((option = getopt(argc, argv, "ace:fhlnr:s:u:zLK:O:S:")) != -1) { switch (option) { @@ -203,7 +203,7 @@ main(int argc, char **argv) /* daemon() closed stderr, so log errors from here on. */ openlog("slattach",LOG_CONS|LOG_PID,LOG_DAEMON); - acquire_line(); /* get tty device as controling terminal */ + acquire_line(); /* get tty device as controlling terminal */ setup_line(0); /* configure for slip line discipline */ slip_discipline(); /* switch to slip line discipline */ @@ -307,7 +307,7 @@ void acquire_line() (void)close (fd); fd = STDIN_FILENO; - /* acquire the serial line as a controling terminal. */ + /* acquire the serial line as a controlling terminal. */ if (ioctl(fd, TIOCSCTTY, 0) < 0) { syslog(LOG_ERR,"ioctl(TIOCSCTTY): %m"); exit_handler(1); @@ -404,7 +404,7 @@ void slip_discipline() close(s); } -/* configure the interface, eg. by passing the unit number to a script. */ +/* configure the interface, e.g. by passing the unit number to a script. */ void configure_network() { int new_unit; @@ -418,8 +418,12 @@ void configure_network() if (config_cmd) { char *s; s = (char*) malloc(strlen(config_cmd) + 32); + if (s == NULL) { + syslog(LOG_ERR, "malloc failed"); + exit(1); + } sprintf (s, "%s %d %d", config_cmd, unit, new_unit); - syslog(LOG_NOTICE, "Configuring %s (sl%d):", dev, unit); + syslog(LOG_NOTICE, "configuring %s (sl%d):", dev, unit); syslog(LOG_NOTICE, " '%s'", s); system(s); free (s); @@ -449,7 +453,7 @@ void sighup_handler() } again: /* invoke a shell for redial_cmd or punt. */ - if (*redial_cmd) { + if (*redial_cmd) { /* Non-empty redial command */ syslog(LOG_NOTICE,"SIGHUP on %s (sl%d); running '%s'", dev, unit, redial_cmd); acquire_line(); /* reopen dead line */ @@ -496,7 +500,7 @@ again: if (!(modem_control & CLOCAL)) { int carrier = 0; - syslog(LOG_NOTICE, "Waiting for carrier on %s (sl%d)", + syslog(LOG_NOTICE, "waiting for carrier on %s (sl%d)", dev, unit); /* Now wait for carrier before attaching line. */ /* We must poll since CLOCAL prevents signal. */ @@ -506,7 +510,7 @@ again: if (comstate & TIOCM_CD) carrier = 1; } - syslog(LOG_NOTICE, "Carrier now present on %s (sl%d)", + syslog(LOG_NOTICE, "carrier now present on %s (sl%d)", dev, unit); } } @@ -569,8 +573,12 @@ void exit_handler(int ret) if (config_cmd) { char *s; s = (char*) malloc(strlen(config_cmd) + 32); + if (s == NULL) { + syslog(LOG_ERR, "malloc failed"); + exit(1); + } sprintf (s, "%s %d -1", config_cmd, unit); - syslog(LOG_NOTICE, "Deconfiguring %s (sl%d):", dev, unit); + syslog(LOG_NOTICE, "deconfiguring %s (sl%d):", dev, unit); syslog(LOG_NOTICE, " '%s'", s); system(s); free (s); |