diff options
author | brian <brian@FreeBSD.org> | 1997-11-04 01:17:05 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1997-11-04 01:17:05 +0000 |
commit | bd52968d26311964fedc5301c206df302f372273 (patch) | |
tree | f001d2d5c1ea74b74efa5b0b9686fae06243301a /usr.sbin/ppp | |
parent | 9e1a11429b69867cc575ecf805ef1c0c4ae8ba42 (diff) | |
download | FreeBSD-src-bd52968d26311964fedc5301c206df302f372273.zip FreeBSD-src-bd52968d26311964fedc5301c206df302f372273.tar.gz |
Introduce [local] to "set log [local] ...". This spits
logging out to the screen in terminal mode - should be
good for installation problem diagnosis.
Diffstat (limited to 'usr.sbin/ppp')
-rw-r--r-- | usr.sbin/ppp/command.c | 44 | ||||
-rw-r--r-- | usr.sbin/ppp/command.h | 4 | ||||
-rw-r--r-- | usr.sbin/ppp/log.c | 72 | ||||
-rw-r--r-- | usr.sbin/ppp/log.h | 7 | ||||
-rw-r--r-- | usr.sbin/ppp/main.c | 17 | ||||
-rw-r--r-- | usr.sbin/ppp/ppp.8 | 52 | ||||
-rw-r--r-- | usr.sbin/ppp/ppp.8.m4 | 52 | ||||
-rw-r--r-- | usr.sbin/ppp/systems.c | 13 |
8 files changed, 191 insertions, 70 deletions
diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c index b84d094..c6bdc6b 100644 --- a/usr.sbin/ppp/command.c +++ b/usr.sbin/ppp/command.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: command.c,v 1.88 1997/10/26 01:02:26 brian Exp $ + * $Id: command.c,v 1.89 1997/10/26 12:42:09 brian Exp $ * */ #include <sys/param.h> @@ -119,7 +119,7 @@ HelpCommand(struct cmdtab const * list, } int -IsInteractive() +IsInteractive(int Display) { char *mes = NULL; @@ -134,7 +134,7 @@ IsInteractive() else if (mode & MODE_DEDICATED) mes = "Working in dedicated mode."; if (mes) { - if (VarTerm) + if (Display && VarTerm) fprintf(VarTerm, "%s\n", mes); return 0; } @@ -391,11 +391,17 @@ ShowLogLevel() if (!VarTerm) return 0; - fprintf(VarTerm, "Log:"); - for (i = LogMIN; i < LogMAXCONF; i++) { - if (LogIsKept(i)) + + fprintf(VarTerm, "Log: "); + for (i = LogMIN; i <= LogMAX; i++) + if (LogIsKept(i) & LOG_KEPT_SYSLOG) fprintf(VarTerm, " %s", LogName(i)); - } + + fprintf(VarTerm, "\nLocal:"); + for (i = LogMIN; i <= LogMAX; i++) + if (LogIsKept(i) & LOG_KEPT_LOCAL) + fprintf(VarTerm, " %s", LogName(i)); + fprintf(VarTerm, "\n"); return 0; @@ -740,7 +746,7 @@ TerminalCommand(struct cmdtab const * list, int argc, char **argv) fprintf(VarTerm, "LCP state is [%s]\n", StateNames[LcpFsm.state]); return 1; } - if (!IsInteractive()) + if (!IsInteractive(1)) return (1); if (OpenModem(mode) < 0) { if (VarTerm) @@ -961,18 +967,32 @@ SetLogLevel(struct cmdtab const * list, int argc, char **argv) int i; int res; char *arg; + void (*Discard)(int), (*Keep)(int); + void (*DiscardAll)(void); res = 0; + if (strcasecmp(argv[0], "local")) { + Discard = LogDiscard; + Keep = LogKeep; + DiscardAll = LogDiscardAll; + } else { + argc--; + argv++; + Discard = LogDiscardLocal; + Keep = LogKeepLocal; + DiscardAll = LogDiscardAllLocal; + } + if (argc == 0 || (argv[0][0] != '+' && argv[0][0] != '-')) - LogDiscardAll(); + (*DiscardAll)(); while (argc--) { arg = **argv == '+' || **argv == '-' ? *argv + 1 : *argv; for (i = LogMIN; i <= LogMAX; i++) if (strcasecmp(arg, LogName(i)) == 0) { if (**argv == '-') - LogDiscard(i); + (*Discard)(i); else - LogKeep(i); + (*Keep)(i); break; } if (i > LogMAX) { @@ -1306,7 +1326,7 @@ static struct cmdtab const SetCommands[] = { {"loopback", NULL, SetLoopback, LOCAL_AUTH, "Set loopback facility", "set loopback on|off"}, {"log", NULL, SetLogLevel, LOCAL_AUTH, - "Set log level", "set log [+|-]value..."}, + "Set log level", "set log [local] [+|-]value..."}, {"login", NULL, SetVariable, LOCAL_AUTH, "Set login script", "set login chat-script", (void *) VAR_LOGIN}, {"mru", NULL, SetInitialMRU, LOCAL_AUTH, diff --git a/usr.sbin/ppp/command.h b/usr.sbin/ppp/command.h index b491ec4..f4282d0 100644 --- a/usr.sbin/ppp/command.h +++ b/usr.sbin/ppp/command.h @@ -15,7 +15,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: command.h,v 1.7 1997/09/25 00:52:34 brian Exp $ + * $Id: command.h,v 1.8 1997/10/26 01:02:28 brian Exp $ * * TODO: */ @@ -47,5 +47,5 @@ extern int aft_cmd; extern int SetVariable(struct cmdtab const *, int, char **, int); extern void Prompt(void); -extern int IsInteractive(void); +extern int IsInteractive(int); extern void DecodeCommand(char *, int, int); diff --git a/usr.sbin/ppp/log.c b/usr.sbin/ppp/log.c index 32c28bb..298372b 100644 --- a/usr.sbin/ppp/log.c +++ b/usr.sbin/ppp/log.c @@ -1,5 +1,5 @@ /* - * $Id: $ + * $Id: log.c,v 1.17 1997/10/26 01:03:05 brian Exp $ */ #include <sys/param.h> @@ -40,6 +40,7 @@ static char *LogNames[] = { #define MSK(n) (1<<((n)-1)) static u_long LogMask = MSK(LogLINK) | MSK(LogCARRIER) | MSK(LogPHASE); +static u_long LogMaskLocal = MSK(LogERROR) | MSK(LogALERT) | MSK(LogWARN); static int LogTunno = -1; static int @@ -71,6 +72,13 @@ LogKeep(int id) } void +LogKeepLocal(int id) +{ + if (id >= LogMIN && id <= LogMAXCONF) + LogMaskLocal |= MSK(id); +} + +void LogDiscard(int id) { if (id >= LogMIN && id <= LogMAXCONF) @@ -78,19 +86,34 @@ LogDiscard(int id) } void +LogDiscardLocal(int id) +{ + if (id >= LogMIN && id <= LogMAXCONF) + LogMaskLocal &= ~MSK(id); +} + +void LogDiscardAll() { LogMask = 0; } +void +LogDiscardAllLocal() +{ + LogMaskLocal = 0; +} + int LogIsKept(int id) { - if (id < LogMIN) + if (id < LogMIN || id > LogMAX) return 0; - if (id <= LogMAXCONF) - return LogMask & MSK(id); - return id <= LogMAX; + if (id > LogMAXCONF) + return LOG_KEPT_LOCAL | LOG_KEPT_SYSLOG; + + return ((LogMaskLocal & MSK(id)) ? LOG_KEPT_LOCAL : 0) | + ((LogMask & MSK(id)) ? LOG_KEPT_SYSLOG : 0); } void @@ -121,15 +144,23 @@ LogPrintf(int lev, char *fmt,...) if (LogIsKept(lev)) { static char nfmt[200]; - if (LogIsKept(LogTUN) && LogTunno != -1) - snprintf(nfmt, sizeof nfmt, "tun%d: %s: %s", - LogTunno, LogName(lev), fmt); - else - snprintf(nfmt, sizeof nfmt, "%s: %s", LogName(lev), fmt); - if ((lev == LogERROR || lev == LogALERT || lev == LogWARN) && VarTerm) - vfprintf(VarTerm, fmt, ap); - if (lev != LogWARN || !VarTerm) + if ((LogIsKept(lev) & LOG_KEPT_LOCAL) && VarTerm) { + if ((LogIsKept(LogTUN) & LOG_KEPT_LOCAL) && LogTunno != -1) + snprintf(nfmt, sizeof nfmt, "tun%d: %s: %s", + LogTunno, LogName(lev), fmt); + else + snprintf(nfmt, sizeof nfmt, "%s: %s", LogName(lev), fmt); + vfprintf(VarTerm, nfmt, ap); + } + + if ((LogIsKept(lev) & LOG_KEPT_SYSLOG) && (lev != LogWARN || !VarTerm)) { + if ((LogIsKept(LogTUN) & LOG_KEPT_SYSLOG) && LogTunno != -1) + snprintf(nfmt, sizeof nfmt, "tun%d: %s: %s", + LogTunno, LogName(lev), fmt); + else + snprintf(nfmt, sizeof nfmt, "%s: %s", LogName(lev), fmt); vsyslog(syslogLevel(lev), nfmt, ap); + } } va_end(ap); } @@ -138,7 +169,7 @@ void LogDumpBp(int lev, char *hdr, struct mbuf * bp) { if (LogIsKept(lev)) { - char buf[49]; + char buf[50]; char *b; u_char *ptr; int f; @@ -153,15 +184,18 @@ LogDumpBp(int lev, char *hdr, struct mbuf * bp) while (f--) { sprintf(b, " %02x", (int) *ptr++); b += 3; - if (b == buf + sizeof buf - 1) { + if (b == buf + sizeof buf - 2) { + strcpy(b, "\n"); LogPrintf(lev, buf); b = buf; } } } while ((bp = bp->next) != NULL); - if (b > buf) + if (b > buf) { + strcpy(b, "\n"); LogPrintf(lev, buf); + } } } @@ -169,16 +203,16 @@ void LogDumpBuff(int lev, char *hdr, u_char * ptr, int n) { if (LogIsKept(lev)) { - char buf[49]; + char buf[50]; char *b; - int f; if (hdr && *hdr) LogPrintf(lev, "%s\n", hdr); while (n > 0) { b = buf; - for (f = 0; f < 16 && n--; f++, b += 3) + for (b = buf; b != buf + sizeof(buf) - 2 && n--; b += 3) sprintf(b, " %02x", (int) *ptr++); + strcpy(b, "\n"); LogPrintf(lev, buf); } } diff --git a/usr.sbin/ppp/log.h b/usr.sbin/ppp/log.h index f7520aa..e3197c7 100644 --- a/usr.sbin/ppp/log.h +++ b/usr.sbin/ppp/log.h @@ -1,5 +1,5 @@ /* - * $Id: $ + * $Id: log.h,v 1.14 1997/10/26 01:03:06 brian Exp $ */ #define LogMIN (1) @@ -27,8 +27,13 @@ /* The first int arg for all of the following is one of the above values */ extern const char *LogName(int); extern void LogKeep(int); +extern void LogKeepLocal(int); extern void LogDiscard(int); +extern void LogDiscardLocal(int); extern void LogDiscardAll(void); +extern void LogDiscardAllLocal(void); +#define LOG_KEPT_SYSLOG (1) /* Results of LogIsKept() */ +#define LOG_KEPT_LOCAL (2) /* Results of LogIsKept() */ extern int LogIsKept(int); extern void LogOpen(const char *); extern void LogSetTun(int); diff --git a/usr.sbin/ppp/main.c b/usr.sbin/ppp/main.c index aeb4640..64a7a7d 100644 --- a/usr.sbin/ppp/main.c +++ b/usr.sbin/ppp/main.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: main.c,v 1.85 1997/10/26 01:03:14 brian Exp $ + * $Id: main.c,v 1.86 1997/10/29 01:19:42 brian Exp $ * * TODO: * o Add commands for traffic summary, version display, etc. @@ -552,9 +552,16 @@ ReadTty() n = read(netfd, linebuff, sizeof(linebuff) - 1); if (n > 0) { aft_cmd = 1; - linebuff[n] = '\0'; - LogPrintf(LogCOMMAND, "Client: %s\n", linebuff); - DecodeCommand(linebuff, n, 1); + if (linebuff[n-1] == '\n') + linebuff[--n] = '\0'; + if (n) { + if (IsInteractive(0)) + LogPrintf(LogCOMMAND, "%s\n", linebuff); + else + LogPrintf(LogCOMMAND, "Client: %s\n", linebuff); + DecodeCommand(linebuff, n, 1); + } else + Prompt(); } else { LogPrintf(LogPHASE, "client connection closed.\n"); VarLocalAuth = LOCAL_NO_AUTH; @@ -921,7 +928,7 @@ DoLoop() VarTerm = fdopen(netfd, "a+"); mode |= MODE_INTER; Greetings(); - (void) IsInteractive(); + IsInteractive(1); Prompt(); } if ((mode & MODE_INTER) && (netfd >= 0 && FD_ISSET(netfd, &rfds)) && diff --git a/usr.sbin/ppp/ppp.8 b/usr.sbin/ppp/ppp.8 index 102d90b..95c2b63 100644 --- a/usr.sbin/ppp/ppp.8 +++ b/usr.sbin/ppp/ppp.8 @@ -1,4 +1,4 @@ -.\" $Id: ppp.8,v 1.69 1997/10/05 10:29:32 brian Exp $ +.\" $Id: ppp.8,v 1.70 1997/10/05 14:27:08 brian Exp $ .Dd 20 September 1995 .Os FreeBSD .Dt PPP 8 @@ -1299,8 +1299,9 @@ ISPs. .Sh LOGGING FACILITY .Nm -is able to generate the following log info via -.Xr syslog 3 : +is able to generate the following log info either via +.Xr syslog 3 +or directly to the screen: .Bl -column SMMMMMM -offset indent .It Li Async Dump async level packet in hex @@ -1325,28 +1326,51 @@ LOG_ERROR. .It Li Alert Output to the log file using LOG_ALERT .El +.Pp The .Dq set log -command allows you to set logging output level, of which -multiple levels can be specified. The default is equivalent to +command allows you to set the logging output level. Multiple levels +can be specified on a single command line. The default is equivalent to .Dq set log Carrier Link Phase . +.Pp +It is also possible to log directly to the screen. The syntax is +the same except that the word +.Dq local +should immediately follow +.Dq set log . +The default is +.Dq set log local +(ie. no direct screen logging). + +.Pp If The first argument to -.Dq set log +.Dq set log Op local begins with a '+' or a '-' character, the current log levels are not cleared, for example: .Bd -literal -offset indent +PPP ON awfulhak> set log carrier link phase PPP ON awfulhak> show log -Log: Carrier Link Phase -PPP ON awfulhak> set log -Link +tcp/ip +Log: Carrier Link Phase Warning Error Alert +Local: Warning Error Alert +PPP ON awfulhak> set log -link +tcp/ip -warning +PPP ON awfulhak> set log local +command PPP ON awfulhak> show log -Log: Carrier Phase TCP/IP +Log: Carrier Phase TCP/IP Warning Error Alert +Local: Command Warning Error Alert .Ed -Log messages of level Warning, Error and Alert are not controlable +.Pp +Log messages of level Warning, Error and Alert are not controllable using -.Dq set log . +.Dq set log Op local . + +.Pp +The +.Ar Warning +level is special in that it will not be logged if it can be displayed +locally. .Sh SIGNAL HANDLING @@ -1750,9 +1774,9 @@ If set to will send the packet, probably resulting in an ICMP redirect from the other end. -.It set log [+|-]value... -This command allows the adjustment of the current log level. Please -refer to the Logging Facility section for further details. +.It set log Op local [+|-]value... +This command allows the adjustment of the current log level. Refer +to the Logging Facility section for further details. .It set login chat-script This chat-script compliments the dial-script. If both are specified, diff --git a/usr.sbin/ppp/ppp.8.m4 b/usr.sbin/ppp/ppp.8.m4 index 102d90b..95c2b63 100644 --- a/usr.sbin/ppp/ppp.8.m4 +++ b/usr.sbin/ppp/ppp.8.m4 @@ -1,4 +1,4 @@ -.\" $Id: ppp.8,v 1.69 1997/10/05 10:29:32 brian Exp $ +.\" $Id: ppp.8,v 1.70 1997/10/05 14:27:08 brian Exp $ .Dd 20 September 1995 .Os FreeBSD .Dt PPP 8 @@ -1299,8 +1299,9 @@ ISPs. .Sh LOGGING FACILITY .Nm -is able to generate the following log info via -.Xr syslog 3 : +is able to generate the following log info either via +.Xr syslog 3 +or directly to the screen: .Bl -column SMMMMMM -offset indent .It Li Async Dump async level packet in hex @@ -1325,28 +1326,51 @@ LOG_ERROR. .It Li Alert Output to the log file using LOG_ALERT .El +.Pp The .Dq set log -command allows you to set logging output level, of which -multiple levels can be specified. The default is equivalent to +command allows you to set the logging output level. Multiple levels +can be specified on a single command line. The default is equivalent to .Dq set log Carrier Link Phase . +.Pp +It is also possible to log directly to the screen. The syntax is +the same except that the word +.Dq local +should immediately follow +.Dq set log . +The default is +.Dq set log local +(ie. no direct screen logging). + +.Pp If The first argument to -.Dq set log +.Dq set log Op local begins with a '+' or a '-' character, the current log levels are not cleared, for example: .Bd -literal -offset indent +PPP ON awfulhak> set log carrier link phase PPP ON awfulhak> show log -Log: Carrier Link Phase -PPP ON awfulhak> set log -Link +tcp/ip +Log: Carrier Link Phase Warning Error Alert +Local: Warning Error Alert +PPP ON awfulhak> set log -link +tcp/ip -warning +PPP ON awfulhak> set log local +command PPP ON awfulhak> show log -Log: Carrier Phase TCP/IP +Log: Carrier Phase TCP/IP Warning Error Alert +Local: Command Warning Error Alert .Ed -Log messages of level Warning, Error and Alert are not controlable +.Pp +Log messages of level Warning, Error and Alert are not controllable using -.Dq set log . +.Dq set log Op local . + +.Pp +The +.Ar Warning +level is special in that it will not be logged if it can be displayed +locally. .Sh SIGNAL HANDLING @@ -1750,9 +1774,9 @@ If set to will send the packet, probably resulting in an ICMP redirect from the other end. -.It set log [+|-]value... -This command allows the adjustment of the current log level. Please -refer to the Logging Facility section for further details. +.It set log Op local [+|-]value... +This command allows the adjustment of the current log level. Refer +to the Logging Facility section for further details. .It set login chat-script This chat-script compliments the dial-script. If both are specified, diff --git a/usr.sbin/ppp/systems.c b/usr.sbin/ppp/systems.c index 4eddc6f..79ca8a8 100644 --- a/usr.sbin/ppp/systems.c +++ b/usr.sbin/ppp/systems.c @@ -17,7 +17,7 @@ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * $Id: systems.c,v 1.16 1997/09/04 00:38:21 brian Exp $ + * $Id: systems.c,v 1.17 1997/10/26 01:03:48 brian Exp $ * * TODO: */ @@ -139,7 +139,7 @@ SelectSystem(char *name, char *file) { FILE *fp; char *cp, *wp; - int n; + int n, len; u_char olauth; char line[200]; char filename[200]; @@ -189,12 +189,19 @@ SelectSystem(char *name, char *file) if (*cp == ' ' || *cp == '\t') { n = strspn(cp, " \t"); cp += n; + len = strlen(cp); + if (!len) + continue; + if (cp[len-1] == '\n') + cp[--len] = '\0'; + if (!len) + continue; LogPrintf(LogCOMMAND, "%s: %s\n", name, cp); SetPppId(); olauth = VarLocalAuth; if (VarLocalAuth == LOCAL_NO_AUTH) VarLocalAuth = LOCAL_AUTH; - DecodeCommand(cp, strlen(cp), 0); + DecodeCommand(cp, len, 0); VarLocalAuth = olauth; SetUserId(); } else if (*cp == '#') { |