From: Paul Mackerras Date: Fri, 13 Aug 1999 01:57:37 +0000 (+0000) Subject: add linkname option X-Git-Tag: ppp-2.4.7~657 X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=commitdiff_plain;h=eec3836d78f32b0ada1a3c04bff77c80abe5ed98 add linkname option --- diff --git a/pppd/main.c b/pppd/main.c index 4acc217..a81e81b 100644 --- a/pppd/main.c +++ b/pppd/main.c @@ -18,7 +18,7 @@ */ #ifndef lint -static const char rcsid[] = "$Id: main.c,v 1.81 1999/08/12 04:17:07 paulus Exp $"; +static const char rcsid[] = "$Id: main.c,v 1.82 1999/08/13 01:57:35 paulus Exp $"; #endif #include @@ -72,6 +72,7 @@ int ifunit; /* Interface unit number */ char *progname; /* Name of this program */ char hostname[MAXNAMELEN]; /* Our hostname */ static char pidfilename[MAXPATHLEN]; /* name of pid file */ +static char linkpidfile[MAXPATHLEN]; /* name of linkname pid file */ static char ppp_devnam[MAXPATHLEN]; /* name of PPP tty (maybe ttypx) */ static uid_t uid; /* Our real user-id */ static int conn_running; /* we have a [dis]connector running */ @@ -144,6 +145,7 @@ static struct subprocess *children; /* Prototypes for procedures local to this file. */ static void create_pidfile __P((void)); +static void create_linkpidfile __P((void)); static void cleanup __P((void)); static void close_tty __P((void)); static void get_input __P((void)); @@ -472,6 +474,8 @@ main(argc, argv) waiting = 0; + create_linkpidfile(); + /* * If we're doing dial-on-demand, set up the interface now. */ @@ -854,7 +858,7 @@ main(argc, argv) if (!demand) { if (pidfilename[0] != 0 && unlink(pidfilename) < 0 && errno != ENOENT) - warn("unable to delete pid file: %m"); + warn("unable to delete pid file %s: %m", pidfilename); pidfilename[0] = 0; } @@ -935,9 +939,11 @@ detach() close(2); detached = 1; log_to_fd = -1; - /* update pid file if it has been written already */ + /* update pid files if they have been written already */ if (pidfilename[0]) create_pidfile(); + if (linkpidfile[0]) + create_linkpidfile(); } /* @@ -974,6 +980,29 @@ create_pidfile() } slprintf(numbuf, sizeof(numbuf), "%d", getpid()); script_setenv("PPPD_PID", numbuf); + if (linkpidfile[0]) + create_linkpidfile(); +} + +static void +create_linkpidfile() +{ + FILE *pidfile; + + if (linkname[0] == 0) + return; + slprintf(linkpidfile, sizeof(linkpidfile), "%sppp-%s.pid", + _PATH_VARRUN, linkname); + if ((pidfile = fopen(linkpidfile, "w")) != NULL) { + fprintf(pidfile, "%d\n", getpid()); + if (pidfilename[0]) + fprintf(pidfile, "%s\n", ifname); + (void) fclose(pidfile); + } else { + error("Failed to create pid file %s: %m", linkpidfile); + linkpidfile[0] = 0; + } + script_setenv("LINKNAME", linkname); } /* @@ -1092,8 +1121,11 @@ cleanup() close_tty(); if (pidfilename[0] != 0 && unlink(pidfilename) < 0 && errno != ENOENT) - warn("unable to delete pid file: %m"); + warn("unable to delete pid file %s: %m", pidfilename); pidfilename[0] = 0; + if (linkpidfile[0] != 0 && unlink(linkpidfile) < 0 && errno != ENOENT) + warn("unable to delete pid file %s: %m", linkpidfile); + linkpidfile[0] = 0; if (locked) unlock(); diff --git a/pppd/options.c b/pppd/options.c index 2571774..fc65d92 100644 --- a/pppd/options.c +++ b/pppd/options.c @@ -18,7 +18,7 @@ */ #ifndef lint -static const char rcsid[] = "$Id: options.c,v 1.62 1999/08/12 04:25:10 paulus Exp $"; +static const char rcsid[] = "$Id: options.c,v 1.63 1999/08/13 01:57:36 paulus Exp $"; #endif #include @@ -94,6 +94,7 @@ int using_pty = 0; bool sync_serial = 0; /* Device is synchronous serial device */ int log_to_fd = 1; /* send log messages to this fd too */ int maxfail = 10; /* max # of unsuccessful connection attempts */ +char linkname[MAXPATHLEN]; /* logical name for link */ extern option_t auth_options[]; extern struct stat devstat; @@ -240,6 +241,9 @@ option_t general_options[] = { { "nologfd", o_int, &log_to_fd, "Don't send log messages to any file descriptor", OPT_NOARG | OPT_VAL(-1) }, + { "linkname", o_string, linkname, + "Set logical name for link", + OPT_PRIV|OPT_STATIC, NULL, MAXPATHLEN }, { "maxfail", o_int, &maxfail, "Maximum number of unsuccessful connection attempts to allow" }, diff --git a/pppd/pppd.8 b/pppd/pppd.8 index a7b4db8..301879c 100644 --- a/pppd/pppd.8 +++ b/pppd/pppd.8 @@ -1,5 +1,5 @@ .\" manual page [] for pppd 2.3 -.\" $Id: pppd.8,v 1.43 1999/08/12 04:22:53 paulus Exp $ +.\" $Id: pppd.8,v 1.44 1999/08/13 01:57:36 paulus Exp $ .\" SH section heading .\" SS subsection heading .\" LP paragraph @@ -426,6 +426,13 @@ Set the maximum number of LCP terminate-request transmissions to Set the LCP restart interval (retransmission timeout) to \fIn\fR seconds (default 3). .TP +.B linkname \fIname\fR +Sets the logical name of the link to \fIname\fR. Pppd will create a +file named \fBppp-\fIname\fB.pid\fR in /var/run (or /etc/ppp on some +systems) containing its process ID. This can be useful in determining +which instance of pppd is responsible for the link to a given peer +system. This is a privileged option. +.TP .B local Don't use the modem control lines. With this option, pppd will ignore the state of the CD (Carrier Detect) signal from the modem and will @@ -1214,6 +1221,9 @@ connection. .B BYTES_RCVD The number of bytes received (at the level of the serial port) during the connection. +.TP +.B LINKNAME +The logical name of the link, set with the \fIlinkname\fR option. .P Pppd invokes the following scripts, if they exist. It is not an error if they don't exist. @@ -1278,6 +1288,10 @@ script. .B /var/run/ppp\fIn\fB.pid \fR(BSD or Linux), \fB/etc/ppp/ppp\fIn\fB.pid \fR(others) Process-ID for pppd process on ppp interface unit \fIn\fR. .TP +.B /var/run/ppp-\fIname\fB.pid \fR(BSD or Linux), \fB/etc/ppp/ppp-\fIname\fB.pid \fR(others) +Process-ID for pppd process for logical link \fIname\fR (see the +\fIlinkname\fR option). +.TP .B /etc/ppp/pap-secrets Usernames, passwords and IP addresses for PAP authentication. This file should be owned by root and not readable or writable by any other diff --git a/pppd/pppd.h b/pppd/pppd.h index 2ce8519..2e7c5ca 100644 --- a/pppd/pppd.h +++ b/pppd/pppd.h @@ -16,7 +16,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: pppd.h,v 1.43 1999/08/12 04:22:53 paulus Exp $ + * $Id: pppd.h,v 1.44 1999/08/13 01:57:37 paulus Exp $ */ /* @@ -200,6 +200,7 @@ extern bool notty; /* Stdin/out is not a tty */ extern char *record_file; /* File to record chars sent/received */ extern bool sync_serial; /* Device is synchronous serial device */ extern int maxfail; /* Max # of unsuccessful connection attempts */ +extern char linkname[MAXPATHLEN]; /* logical name for link */ #ifdef PPP_FILTER extern struct bpf_program pass_filter; /* Filter for pkts to pass */