* (614)451-1883
*/
+static char rcsid[] = "$Id: chat.c,v 1.5 1995/01/11 03:14:45 paulus Exp $";
+
#include <stdio.h>
#include <fcntl.h>
#include <signal.h>
#define TERMIOS
#endif
-#ifdef sun
-# if defined(SUNOS) && SUNOS >= 41
-# ifndef HDB
-# define HDB
-# endif
-# endif
-#endif
-
#ifdef TERMIO
#include <termio.h>
#endif
char *program_name;
-#ifndef LOCK_DIR
-# ifdef __NetBSD__
-# define PIDSTRING
-# define LOCK_DIR "/var/spool/lock"
-# else
-# ifdef HDB
-# define PIDSTRING
-# define LOCK_DIR "/usr/spool/locks"
-# else /* HDB */
-# define LOCK_DIR "/usr/spool/uucp"
-# endif /* HDB */
-# endif
-#endif /* LOCK_DIR */
-
#define MAX_ABORTS 50
#define DEFAULT_CHAT_TIMEOUT 45
void break_sequence __P((void));
void terminate __P((int status));
void do_file __P((char *chat_file));
-void lock __P((void));
void delay __P((void));
int get_string __P((register char *string));
int put_string __P((register char *s));
char *character __P((char c));
void chat_expect __P((register char *s));
char *clean __P((register char *s, int sending));
-void unlock __P((void));
-void lock __P((void));
void break_sequence __P((void));
void terminate __P((int status));
void die __P((void));
}
/*
- * chat [ -v ] [ -t timeout ] [ -l lock-file ] [ -f chat-file ] \
+ * chat [ -v ] [ -t timeout ] [ -f chat-file ] \
* [...[[expect[-say[-expect...]] say expect[-say[-expect]] ...]]]
*
* Perform a UUCP-dialer-like chat script on stdin and stdout.
void usage()
{
fprintf(stderr, "\
-Usage: %s [-v] [-l lock-file] [-t timeout] {-f chat-file || chat-script}\n",
+Usage: %s [-v] [-t timeout] {-f chat-file || chat-script}\n",
program_name);
exit(1);
}
}
/*
- * Unlock and terminate with an error.
+ * Terminate with an error.
*/
void die()
{
- unlock();
terminate(1);
}
const char *msg;
{
syslog(LOG_ERR, "%s", msg);
- unlock();
terminate(1);
}
const char *msg;
{
syslog(LOG_ERR, "%s: %m", msg);
- unlock();
terminate(1);
}
signal(SIGTERM, sigterm);
signal(SIGHUP, sighup);
- if (lock_file)
- lock();
-
set_tty_parameters();
signal(SIGALRM, sigalrm);
alarm(0);
#endif
) {
syslog(LOG_ERR, "Can't restore terminal parameters: %m");
- unlock();
exit(1);
}
exit(status);
}
-/*
- * Create a lock file for the named lock device
- */
-void lock()
- {
- int fd, pid;
-# ifdef PIDSTRING
- char hdb_lock_buffer[12];
-# endif
-
- lock_file = strcat(strcat(strcpy(malloc(strlen(LOCK_DIR)
- + 1 + strlen(lock_file) + 1),
- LOCK_DIR), "/"), lock_file);
-
- if ((fd = open(lock_file, O_EXCL | O_CREAT | O_RDWR, 0644)) < 0)
- {
- char *s = lock_file;
- lock_file = (char *)0; /* Don't remove someone else's lock file! */
- syslog(LOG_ERR, "Can't get lock file '%s': %m", s);
- die();
- }
-
-# ifdef PIDSTRING
- sprintf(hdb_lock_buffer, "%10d\n", getpid());
- write(fd, hdb_lock_buffer, 11);
-# else
- pid = getpid();
- write(fd, &pid, sizeof pid);
-# endif
-
- close(fd);
- }
-
-/*
- * Remove our lockfile
- */
-void unlock()
- {
- if (lock_file)
- {
- unlink(lock_file);
- lock_file = (char *)0;
- }
- }
-
/*
* 'Clean up' this string.
*/
else
syslog(LOG_INFO, "Failed");
- unlock();
terminate(1);
}
}
die();
}
- strcpy(s, s1);
- abort_string[n_aborts++] = s;
+ abort_string[n_aborts++] = s1;
if (verbose)
{
- register char *s1 = s;
-
logf("abort on (");
for (s1 = s; *s1; ++s1)
if ( ! put_string(s))
{
syslog(LOG_INFO, "Failed");
- unlock();
terminate(1);
}
}