Subject: Patches for slattach(???)
To: None <current-users@sun-lamp.cs.berkeley.edu>
From: Dave Burgess <burgess@s069.infonet.net>
List: current-users
Date: 05/06/1994 20:21:00
I have been using this set of patches for slattach for a couple of
months.  They change a couple of things...

1.  They add the functionality of creating a pid file.
2.  They change the default baud rate to 38400 baud (the fastest
interface speed my modem and software will support).

Understanding that the thing with the pid file is for my personal
convenience (for killing the slattach that should be running) the
program should (but does not yet) check to see if there is a copy of it
running.  I usurped the -p option for writing the pid file
(/var/run/slattach.pid) so that the default behavior is the same as it
always was.

TSgt Dave

- - - - - - - - - - Cut Here - - - - - - - - - -
*** slattach.c.orig	Fri Feb 11 04:18:05 1994
--- slattach.c	Thu Mar 31 21:43:18 1994
***************
*** 1,3 ****
--- 1,4 ----
+ 
  /*
   * Copyright (c) 1988 Regents of the University of California.
   * All rights reserved.
***************
*** 59,73 ****
  #include <fcntl.h>
  #include <stdio.h>
  #include <paths.h>
! 
! #define DEFAULT_BAUD	9600
! 
  static char usage_str[] = "\
! usage: %s [-h] [-m] [-s <speed>] <device>\n\
  	-h -- turn on CTS/RTS style flow control\n\
  	-m -- maintain DTR after last close (no HUPCL)\n\
! 	-s -- baud rate (default 9600)\n";
! 
  int main(int argc, char **argv)
  {
  	struct termios tty;
--- 60,75 ----
  #include <fcntl.h>
  #include <stdio.h>
  #include <paths.h>
! #define PIDFILE "/var/run/slattach.pid"
! #define DEFAULT_BAUD	38400
!   
  static char usage_str[] = "\
! usage: %s [-h] [-m] [-p] [-s <speed>] <device>\n\
  	-h -- turn on CTS/RTS style flow control\n\
  	-m -- maintain DTR after last close (no HUPCL)\n\
! 	-p -- write pid number to %s\n\
! 	-s -- baud rate (default 38400)\n";
!   
  int main(int argc, char **argv)
  {
  	struct termios tty;
***************
*** 78,88 ****
  	int slipdisc = SLIPDISC;
  	int speed = DEFAULT_BAUD;
  	int cflags = HUPCL;
  
  	extern char *optarg;
  	extern int optind;
  
! 	while ((option = getopt(argc, argv, "achmns:")) != EOF) {
  		switch (option) {
  		case 'h':
  			cflags |= CRTSCTS;
--- 80,92 ----
  	int slipdisc = SLIPDISC;
  	int speed = DEFAULT_BAUD;
  	int cflags = HUPCL;
+ 	int pidfile = 0;
+ 	FILE *outfile;
  
  	extern char *optarg;
  	extern int optind;
  
! 	while ((option = getopt(argc, argv, "achmnps:")) != EOF) {
  		switch (option) {
  		case 'h':
  			cflags |= CRTSCTS;
***************
*** 90,101 ****
  		case 'm':
  			cflags &= ~HUPCL;
  			break;
  		case 's':
  			speed = atoi(optarg);
  			break;
  		case '?':
  		default:
! 			fprintf(stderr, usage_str, argv[0]);
  			exit(1);
  		}
  	}
--- 94,108 ----
  		case 'm':
  			cflags &= ~HUPCL;
  			break;
+ 		case 'p':
+ 			pidfile = 1;
+ 			break;
  		case 's':
  			speed = atoi(optarg);
  			break;
  		case '?':
  		default:
! 			fprintf(stderr, usage_str, argv[0],PIDFILE);
  			exit(1);
  		}
  	}
***************
*** 104,110 ****
  		dev = argv[optind];
  
  	if (dev == (char *)0) {
! 		fprintf(stderr, usage_str, argv[0]);
  		exit(2);
  	}
  
--- 111,117 ----
  		dev = argv[optind];
  
  	if (dev == (char *)0) {
! 		fprintf(stderr, usage_str, argv[0], PIDFILE);
  		exit(2);
  	}
  
***************
*** 153,158 ****
--- 160,175 ----
  
  	if (fork() > 0)
  		exit(0);
+ 
+ 	if (pidfile) {
+ 		outfile = fopen(PIDFILE,"w");
+ 		if (outfile != NULL) {
+ 			fprintf(outfile,"%d",(int)getpid()); 
+ 			fclose(outfile);
+ 		} else {
+ 			fprintf(stderr,"Invalid pid file name.\n");
+ 		}
+ 	}
  
  	for (;;)
  		sigpause(0L);


------------------------------------------------------------------------------