summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrian <brian@cvs.openbsd.org>2000-04-07 23:46:40 +0000
committerbrian <brian@cvs.openbsd.org>2000-04-07 23:46:40 +0000
commitc9170ac6e779ac87358e5801c9ec6fbb82638d20 (patch)
tree173fecf5262c12439d404437d88f3e633b89afe0
parent9bc53212dcd0b6c2104751f467e6ba0622b29903 (diff)
When running ppp -background, show comfort messages showing
when we're redialing/reconnecting. While we're here, log redial, reconnect and phone number announcements to LogCHAT, and reduce some other logging to LogDEBUG.
-rw-r--r--usr.sbin/ppp/ppp/bundle.c30
-rw-r--r--usr.sbin/ppp/ppp/bundle.h3
-rw-r--r--usr.sbin/ppp/ppp/datalink.c12
-rw-r--r--usr.sbin/ppp/ppp/defs.c18
-rw-r--r--usr.sbin/ppp/ppp/defs.h14
-rw-r--r--usr.sbin/ppp/ppp/main.c49
6 files changed, 80 insertions, 46 deletions
diff --git a/usr.sbin/ppp/ppp/bundle.c b/usr.sbin/ppp/ppp/bundle.c
index 566e5c5cd22..c53c6109fb1 100644
--- a/usr.sbin/ppp/ppp/bundle.c
+++ b/usr.sbin/ppp/ppp/bundle.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: bundle.c,v 1.35 2000/04/06 10:09:57 brian Exp $
+ * $OpenBSD: bundle.c,v 1.36 2000/04/07 23:46:39 brian Exp $
*/
#include <sys/param.h>
@@ -160,17 +160,25 @@ bundle_LayerStart(void *v, struct fsm *fp)
}
-static void
+void
bundle_Notify(struct bundle *bundle, char c)
{
if (bundle->notify.fd != -1) {
- if (write(bundle->notify.fd, &c, 1) == 1)
- log_Printf(LogPHASE, "Parent notified of %s\n",
- c == EX_NORMAL ? "success" : "failure");
+ int ret;
+
+ ret = write(bundle->notify.fd, &c, 1);
+ if (c != EX_REDIAL && c != EX_RECONNECT) {
+ if (ret == 1)
+ log_Printf(LogCHAT, "Parent notified of %s\n",
+ c == EX_NORMAL ? "success" : "failure");
+ else
+ log_Printf(LogERROR, "Failed to notify parent of success\n");
+ close(bundle->notify.fd);
+ bundle->notify.fd = -1;
+ } else if (ret == 1)
+ log_Printf(LogCHAT, "Parent notified of %s\n", ex_desc(c));
else
- log_Printf(LogPHASE, "Failed to notify parent of success.\n");
- close(bundle->notify.fd);
- bundle->notify.fd = -1;
+ log_Printf(LogERROR, "Failed to notify parent of %s\n", ex_desc(c));
}
}
@@ -1220,7 +1228,7 @@ bundle_IdleTimeout(void *v)
{
struct bundle *bundle = (struct bundle *)v;
- log_Printf(LogPHASE, "Idle timer expired.\n");
+ log_Printf(LogPHASE, "Idle timer expired\n");
bundle_StopIdleTimer(bundle);
bundle_Close(bundle, NULL, CLOSE_STAYDOWN);
}
@@ -1643,7 +1651,7 @@ bundle_SendDatalink(struct datalink *dl, int s, struct sockaddr_un *sun)
log_Printf(LogDEBUG, "Received confirmation from pid %d\n",
(int)newpid);
if (lock && (res = ID0uu_lock_txfr(lock, newpid)) != UU_LOCK_OK)
- log_Printf(LogPHASE, "uu_lock_txfr: %s\n", uu_lockerr(res));
+ log_Printf(LogERROR, "uu_lock_txfr: %s\n", uu_lockerr(res));
log_Printf(LogDEBUG, "Transmitting link (%d bytes)\n", expect);
if ((got = writev(reply[0], iov + 1, niov - 1)) != expect) {
@@ -1781,7 +1789,7 @@ bundle_setsid(struct bundle *bundle, int holdsession)
close(fds[0]);
setsid();
bundle_ChangedPID(bundle);
- log_Printf(LogPHASE, "%d -> %d: %s session control\n",
+ log_Printf(LogDEBUG, "%d -> %d: %s session control\n",
(int)orig, (int)getpid(),
holdsession ? "Passed" : "Dropped");
timer_InitService(0); /* Start the Timer Service */
diff --git a/usr.sbin/ppp/ppp/bundle.h b/usr.sbin/ppp/ppp/bundle.h
index c96d2cadb6c..9ce9b311e49 100644
--- a/usr.sbin/ppp/ppp/bundle.h
+++ b/usr.sbin/ppp/ppp/bundle.h
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: bundle.h,v 1.13 2000/03/19 10:33:32 brian Exp $
+ * $OpenBSD: bundle.h,v 1.14 2000/04/07 23:46:39 brian Exp $
*/
#define PHASE_DEAD 0 /* Link is dead */
@@ -190,3 +190,4 @@ extern void bundle_CalculateBandwidth(struct bundle *);
extern void bundle_AutoAdjust(struct bundle *, int, int);
extern int bundle_WantAutoloadTimer(struct bundle *);
extern void bundle_ChangedPID(struct bundle *);
+extern void bundle_Notify(struct bundle *, char);
diff --git a/usr.sbin/ppp/ppp/datalink.c b/usr.sbin/ppp/ppp/datalink.c
index cb99d2b769c..a3c00c41f92 100644
--- a/usr.sbin/ppp/ppp/datalink.c
+++ b/usr.sbin/ppp/ppp/datalink.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: datalink.c,v 1.29 2000/04/02 01:36:22 brian Exp $
+ * $OpenBSD: datalink.c,v 1.30 2000/04/07 23:46:39 brian Exp $
*/
#include <sys/param.h>
@@ -83,7 +83,7 @@ datalink_OpenTimeout(void *v)
timer_Stop(&dl->dial.timer);
if (dl->state == DATALINK_OPENING)
- log_Printf(LogPHASE, "%s: Redial timer expired.\n", dl->name);
+ log_Printf(LogCHAT, "%s: Redial timer expired.\n", dl->name);
}
static int
@@ -170,11 +170,16 @@ datalink_HangupDone(struct datalink *dl)
dl->dial.tries = dl->cfg.dial.max;
dl->dial.incs = 0;
dl->reconnect_tries--;
+ log_Printf(LogCHAT, "%s: Reconnect try %d of %d\n",
+ dl->name, dl->cfg.reconnect.max - dl->reconnect_tries,
+ dl->cfg.reconnect.max);
+ bundle_Notify(dl->bundle, EX_RECONNECT);
} else {
if (dl->phone.next == NULL)
datalink_StartDialTimer(dl, datalink_GetDialTimeout(dl));
else
datalink_StartDialTimer(dl, dl->cfg.dial.next_timeout);
+ bundle_Notify(dl->bundle, EX_REDIAL);
}
}
}
@@ -197,7 +202,7 @@ datalink_ChoosePhoneNumber(struct datalink *dl)
phone = strsep(&dl->phone.alt, "|");
dl->phone.chosen = *phone ? phone : "[NONE]";
if (*phone)
- log_Printf(LogPHASE, "Phone: %s\n", phone);
+ log_Printf(LogCHAT, "Phone: %s\n", phone);
return phone;
}
@@ -309,6 +314,7 @@ datalink_UpdateSet(struct fdescriptor *d, fd_set *r, fd_set *w, fd_set *e,
int timeout;
timeout = datalink_StartDialTimer(dl, datalink_GetDialTimeout(dl));
+ bundle_Notify(dl->bundle, EX_REDIAL);
log_WritePrompts(dl, "Failed to open %s, pause %d seconds\n",
dl->physical->name.full, timeout);
}
diff --git a/usr.sbin/ppp/ppp/defs.c b/usr.sbin/ppp/ppp/defs.c
index c8b438a6f53..369b25dccf1 100644
--- a/usr.sbin/ppp/ppp/defs.c
+++ b/usr.sbin/ppp/ppp/defs.c
@@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: defs.c,v 1.11 2000/03/28 15:14:14 brian Exp $
+ * $OpenBSD: defs.c,v 1.12 2000/04/07 23:46:39 brian Exp $
*/
@@ -342,3 +342,19 @@ HexStr(long val, char *buf, size_t sz)
snprintf(buf, sz, "<0x%lx>", val);
return buf;
}
+
+const char *
+ex_desc(int ex)
+{
+ static char num[12]; /* Used immediately if returned */
+ static const char * const desc[] = {
+ "normal", "start", "sock", "modem", "dial", "dead", "done",
+ "reboot", "errdead", "hangup", "term", "nodial", "nologin",
+ "redial", "reconnect"
+ };
+
+ if (ex >= 0 && ex < sizeof desc / sizeof *desc)
+ return desc[ex];
+ snprintf(num, sizeof num, "%d", ex);
+ return num;
+}
diff --git a/usr.sbin/ppp/ppp/defs.h b/usr.sbin/ppp/ppp/defs.h
index 74fc6d34226..0c1cd70c241 100644
--- a/usr.sbin/ppp/ppp/defs.h
+++ b/usr.sbin/ppp/ppp/defs.h
@@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $OpenBSD: defs.h,v 1.13 2000/02/27 01:38:25 brian Exp $
+ * $OpenBSD: defs.h,v 1.14 2000/04/07 23:46:39 brian Exp $
*
* TODO:
*/
@@ -75,10 +75,13 @@
#define EX_DONE 6
#define EX_REBOOT 7
#define EX_ERRDEAD 8
-#define EX_HANGUP 10
-#define EX_TERM 11
-#define EX_NODIAL 12
-#define EX_NOLOGIN 13
+#define EX_HANGUP 9
+#define EX_TERM 10
+#define EX_NODIAL 11
+#define EX_NOLOGIN 12
+/* return values for -background mode, not really exits */
+#define EX_REDIAL 13
+#define EX_RECONNECT 14
/* physical::type values (OR'd in bundle::phys_type) */
#define PHYS_NONE 0
@@ -109,3 +112,4 @@ extern char *findblank(char *, int);
extern int MakeArgs(char *, char **, int, int);
extern const char *NumStr(long, char *, size_t);
extern const char *HexStr(long, char *, size_t);
+extern const char *ex_desc(int);
diff --git a/usr.sbin/ppp/ppp/main.c b/usr.sbin/ppp/ppp/main.c
index 5b4c19bc411..b990f1d83fb 100644
--- a/usr.sbin/ppp/ppp/main.c
+++ b/usr.sbin/ppp/ppp/main.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $OpenBSD: main.c,v 1.19 2000/04/02 01:36:22 brian Exp $
+ * $OpenBSD: main.c,v 1.20 2000/04/07 23:46:39 brian Exp $
*
* TODO:
*/
@@ -94,7 +94,6 @@
static void DoLoop(struct bundle *);
static void TerminalStop(int);
-static const char *ex_desc(int);
static struct bundle *SignalBundle;
static struct prompt *SignalPrompt;
@@ -166,21 +165,6 @@ BringDownServer(int signo)
server_Close(SignalBundle);
}
-static const char *
-ex_desc(int ex)
-{
- static char num[12]; /* Used immediately if returned */
- static const char * const desc[] = {
- "normal", "start", "sock", "modem", "dial", "dead", "done",
- "reboot", "errdead", "hangup", "term", "nodial", "nologin"
- };
-
- if (ex >= 0 && ex < sizeof desc / sizeof *desc)
- return desc[ex];
- snprintf(num, sizeof num, "%d", ex);
- return num;
-}
-
static void
Usage(void)
{
@@ -436,6 +420,7 @@ main(int argc, char **argv)
if (bgpid) {
char c = EX_NORMAL;
+ int ret;
if (sw.mode == PHYS_BACKGROUND) {
close(bgpipe[1]);
@@ -447,16 +432,30 @@ main(int argc, char **argv)
signal(SIGQUIT, KillChild);
/* Wait for our child to close its pipe before we exit */
- if (read(bgpipe[0], &c, 1) != 1) {
+ while ((ret = read(bgpipe[0], &c, 1)) == 1) {
+ switch (c) {
+ case EX_NORMAL:
+ prompt_Printf(prompt, "PPP enabled\n");
+ log_Printf(LogPHASE, "Parent: PPP enabled\n");
+ case EX_REDIAL:
+ if (!sw.quiet)
+ prompt_Printf(prompt, "Attempting redial\n");
+ continue;
+ case EX_RECONNECT:
+ if (!sw.quiet)
+ prompt_Printf(prompt, "Attempting reconnect\n");
+ continue;
+ default:
+ prompt_Printf(prompt, "Child failed (%s)\n",
+ ex_desc((int)c));
+ log_Printf(LogPHASE, "Parent: Child failed (%s)\n",
+ ex_desc((int) c));
+ }
+ break;
+ }
+ if (ret != 1) {
prompt_Printf(prompt, "Child exit, no status.\n");
log_Printf(LogPHASE, "Parent: Child exit, no status.\n");
- } else if (c == EX_NORMAL) {
- prompt_Printf(prompt, "PPP enabled.\n");
- log_Printf(LogPHASE, "Parent: PPP enabled.\n");
- } else {
- prompt_Printf(prompt, "Child failed (%s).\n", ex_desc((int) c));
- log_Printf(LogPHASE, "Parent: Child failed (%s).\n",
- ex_desc((int) c));
}
close(bgpipe[0]);
}