summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sbin/slattach/slattach.813
-rw-r--r--sbin/slattach/slattach.c24
2 files changed, 33 insertions, 4 deletions
diff --git a/sbin/slattach/slattach.8 b/sbin/slattach/slattach.8
index f346824..f3b8182 100644
--- a/sbin/slattach/slattach.8
+++ b/sbin/slattach/slattach.8
@@ -31,7 +31,7 @@
.\"
.\" @(#)slattach.8 6.4 (Berkeley) 3/16/91
.\"
-.\" $Header: /a/cvs/386BSD/src/sbin/slattach/slattach.8,v 1.6 1993/09/15 21:18:07 jkh Exp $
+.\" $Header: /home/ncvs/src/sbin/slattach/slattach.8,v 1.3 1994/08/23 08:28:31 rich Exp $
.\"
.Dd April 4, 1993
.Dt SLATTACH 8
@@ -167,6 +167,17 @@ logs failure to set the controlling terminal or failure to install
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
+with
+.Aq tty
+replaced by the terminal path name component of
+.Ar ttyname .
+This file contains the numerical process ID of the
+.Nm slattach
+process and can be examined by scripts in oder to send a signal to
+.Nm slattch .
.Sh SEE ALSO
.Xr netstat 1 ,
.Xr netintro 4 ,
diff --git a/sbin/slattach/slattach.c b/sbin/slattach/slattach.c
index a773493..f89bc7d 100644
--- a/sbin/slattach/slattach.c
+++ b/sbin/slattach/slattach.c
@@ -89,6 +89,7 @@ int exiting = 0; /* allready running exit_handler */
struct termios tty; /* tty configuration/state */
char tty_path[32]; /* path name of the tty (e.g. /dev/tty01) */
+char pidfilename[40]; /* e.g. /var/run/slattach.tty01.pid */
char *redial_cmd = 0; /* command to exec upon shutdown. */
char *config_cmd = 0; /* command to exec if slip unit changes. */
char *exit_cmd = 0; /* command to exec before exiting. */
@@ -112,6 +113,7 @@ int main(int argc, char **argv)
int option;
extern char *optarg;
extern int optind;
+ char *cp;
while ((option = getopt(argc, argv, "ace:fhlnr:s:u:z")) != EOF) {
switch (option) {
@@ -152,7 +154,7 @@ int main(int argc, char **argv)
break;
default:
fprintf(stderr, "%s: Invalid option -- '%c'\n",
- option);
+ argv[0], option);
case '?':
fprintf(stderr, usage_str, argv[0]);
exit_handler(1);
@@ -179,7 +181,11 @@ int main(int argc, char **argv)
strncat(tty_path, dev, 10);
dev = tty_path;
}
-
+ cp = strrchr(dev, '/'); /* always succeeds */
+ cp++; /* trailing tty pathname component */
+ sprintf(pidfilename, "%sslattach.%s.pid", _PATH_VARRUN, cp);
+ printf("%s\n",pidfilename);
+
if (!foreground)
daemon(0,0); /* fork, setsid, chdir /, and close std*. */
/* daemon() closed stderr, so log errors from here on. */
@@ -225,7 +231,7 @@ int main(int argc, char **argv)
void acquire_line()
{
int ttydisc = TTYDISC;
- int pgrp;
+ FILE *pidfile;
ioctl(fd, TIOCSETD, &ttydisc); /* reset to tty discipline */
@@ -241,6 +247,14 @@ void acquire_line()
while (getppid () != 1)
sleep (1); /* Wait for parent to die. */
+ /* create PID file */
+ if((pidfile = fopen(pidfilename, "w")) == NULL) {
+ syslog(LOG_NOTICE,"cannot create PID file: %m");
+ } else {
+ fprintf(pidfile, "%ld\n", getpid());
+ fclose(pidfile);
+ }
+
if ((int)signal(SIGHUP,sighup_handler) < 0) /* Re-enable HUP signal */
syslog(LOG_NOTICE,"cannot install SIGHUP handler: %m");
@@ -438,6 +452,10 @@ void exit_handler(int ret)
*/
if (fd != -1)
close(fd);
+
+ /* Remove the PID file */
+ (void)unlink(pidfilename);
+
/* invoke a shell for exit_cmd. */
if (exit_cmd) {
syslog(LOG_NOTICE,"exiting after running %s", exit_cmd);
OpenPOWER on IntegriCloud