diff options
author | Brian Somers <brian@FreeBSD.org> | 2001-11-03 21:45:32 +0000 |
---|---|---|
committer | Brian Somers <brian@FreeBSD.org> | 2001-11-03 21:45:32 +0000 |
commit | 46df5aa7bc98cd1d4769ce244d518f4e161f3e61 (patch) | |
tree | ec148ab8a0b3c8d98c08221f9c5b958f68a4203f /usr.sbin/ppp | |
parent | 5eef06c222360519f1ba82ee24350adbb1e70ac2 (diff) | |
download | src-46df5aa7bc98cd1d4769ce244d518f4e161f3e61.tar.gz src-46df5aa7bc98cd1d4769ce244d518f4e161f3e61.zip |
Add a ``log'' command for logging specific information.
Add an ``UPTIME'' variable to indicate the bundle uptime.
It's now possible to put something like this in ppp.linkdown
for a server setup:
MYADDR:
log Session closing: User USER, address HISADDR, up UPTIME
Fixed some memory leakage with commands that expand words.
Made some functions static.
Fixed a diagnostic bug (iface add .... SIOCDIFADDR)
Notes
Notes:
svn path=/head/; revision=85991
Diffstat (limited to 'usr.sbin/ppp')
-rw-r--r-- | usr.sbin/ppp/bundle.c | 11 | ||||
-rw-r--r-- | usr.sbin/ppp/bundle.h | 1 | ||||
-rw-r--r-- | usr.sbin/ppp/chat.c | 4 | ||||
-rw-r--r-- | usr.sbin/ppp/command.c | 86 | ||||
-rw-r--r-- | usr.sbin/ppp/command.h | 1 | ||||
-rw-r--r-- | usr.sbin/ppp/defs.c | 17 | ||||
-rw-r--r-- | usr.sbin/ppp/defs.h | 1 | ||||
-rw-r--r-- | usr.sbin/ppp/iface.c | 2 | ||||
-rw-r--r-- | usr.sbin/ppp/lcp.c | 2 | ||||
-rw-r--r-- | usr.sbin/ppp/log.c | 6 | ||||
-rw-r--r-- | usr.sbin/ppp/log.h | 2 | ||||
-rw-r--r-- | usr.sbin/ppp/ppp.8.m4 | 13 | ||||
-rw-r--r-- | usr.sbin/ppp/systems.h | 2 |
13 files changed, 104 insertions, 44 deletions
diff --git a/usr.sbin/ppp/bundle.c b/usr.sbin/ppp/bundle.c index 908a9a6b3707..026eb68d2dcf 100644 --- a/usr.sbin/ppp/bundle.c +++ b/usr.sbin/ppp/bundle.c @@ -1034,7 +1034,7 @@ bundle_ShowStatus(struct cmdargs const *arg) arg->bundle->iface->name, arg->bundle->bandwidth); if (arg->bundle->upat) { - int secs = time(NULL) - arg->bundle->upat; + int secs = bundle_Uptime(arg->bundle); prompt_Printf(arg->prompt, ", up time %d:%02d:%02d", secs / 3600, (secs / 60) % 60, secs % 60); @@ -1925,3 +1925,12 @@ bundle_ChangedPID(struct bundle *bundle) ioctl(bundle->dev.fd, TUNSIFPID, 0); #endif } + +int +bundle_Uptime(struct bundle *bundle) +{ + if (bundle->upat) + return time(NULL) - bundle->upat; + + return 0; +} diff --git a/usr.sbin/ppp/bundle.h b/usr.sbin/ppp/bundle.h index d4ff2b9a2681..d8c056a68a17 100644 --- a/usr.sbin/ppp/bundle.h +++ b/usr.sbin/ppp/bundle.h @@ -192,3 +192,4 @@ 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); +extern int bundle_Uptime(struct bundle *); diff --git a/usr.sbin/ppp/chat.c b/usr.sbin/ppp/chat.c index 7695eb4a172f..a81ab0e4f57b 100644 --- a/usr.sbin/ppp/chat.c +++ b/usr.sbin/ppp/chat.c @@ -716,8 +716,6 @@ ExecStr(struct physical *physical, char *command, char *out, int olen) *out = '\0'; return; } - command_Expand(argv, argc, (char const *const *)vector, - physical->dl->bundle, 0, getpid()); if (pipe(fids) < 0) { log_Printf(LogCHAT, "Unable to create pipe in ExecStr: %s\n", @@ -726,6 +724,8 @@ ExecStr(struct physical *physical, char *command, char *out, int olen) return; } if ((pid = fork()) == 0) { + command_Expand(argv, argc, (char const *const *)vector, + physical->dl->bundle, 0, getpid()); close(fids[0]); timer_TermService(); if (fids[1] == STDIN_FILENO) diff --git a/usr.sbin/ppp/command.c b/usr.sbin/ppp/command.c index 3da1db25c0eb..c68a649054a1 100644 --- a/usr.sbin/ppp/command.c +++ b/usr.sbin/ppp/command.c @@ -257,20 +257,9 @@ IdentCommand(struct cmdargs const *arg) { int f, max, n, pos; - *arg->cx->physical->link.lcp.cfg.ident = '\0'; - max = sizeof arg->cx->physical->link.lcp.cfg.ident; - - for (pos = 0, f = arg->argn; f < arg->argc && pos < max; f++) { - n = snprintf(arg->cx->physical->link.lcp.cfg.ident + pos, max - pos, - "%s%s", f == arg->argn ? "" : " ", arg->argv[f]); - if (n < 0) { - arg->cx->physical->link.lcp.cfg.ident[pos] = '\0'; - break; - } - if ((pos += n) >= max) - break; - } - + Concatinate(arg->cx->physical->link.lcp.cfg.ident, + sizeof arg->cx->physical->link.lcp.cfg.ident, + arg->argc - arg->argn, arg->argv + arg->argn); return 0; } @@ -333,7 +322,7 @@ RenameCommand(struct cmdargs const *arg) return 1; } -int +static int LoadCommand(struct cmdargs const *arg) { const char *err; @@ -365,10 +354,34 @@ LoadCommand(struct cmdargs const *arg) return 0; } -int +static int +LogCommand(struct cmdargs const *arg) +{ + char buf[LINE_LEN]; + int i; + + if (arg->argn < arg->argc) { + char *argv[MAXARGS]; + int argc = arg->argc - arg->argn; + + if (argc >= sizeof argv / sizeof argv[0]) { + argc = sizeof argv / sizeof argv[0] - 1; + log_Printf(LogWARN, "Truncating log command to %d args\n", argc); + } + command_Expand(argv, argc, arg->argv + arg->argn, arg->bundle, 0, getpid()); + Concatinate(buf, sizeof buf, argc, (const char *const *)argv); + log_Printf(LogLOG, "%s\n", buf); + command_Free(argc, argv); + return 0; + } + + return -1; +} + +static int SaveCommand(struct cmdargs const *arg) { - log_Printf(LogWARN, "save command is not implemented (yet).\n"); + log_Printf(LogWARN, "save command is not yet implemented.\n"); return 1; } @@ -452,7 +465,8 @@ void command_Expand(char **nargv, int argc, char const *const *oargv, struct bundle *bundle, int inc0, pid_t pid) { - int arg; + int arg, secs; + char buf[20]; char pidstr[12]; if (inc0) @@ -494,10 +508,25 @@ command_Expand(char **nargv, int argc, char const *const *oargv, inet_ntoa(bundle->ncp.ipcp.ns.dns[1])); nargv[arg] = subst(nargv[arg], "VERSION", Version); nargv[arg] = subst(nargv[arg], "COMPILATIONDATE", __DATE__); + + secs = bundle_Uptime(bundle); + snprintf(buf, sizeof buf, "%d:%02d:%02d", secs / 3600, (secs / 60) % 60, + secs % 60); + nargv[arg] = subst(nargv[arg], "UPTIME", buf); } nargv[arg] = NULL; } +void +command_Free(int argc, char **argv) +{ + while (argc) { + free(*argv); + argc--; + argv++; + } +} + static int ShellCommand(struct cmdargs const *arg, int bg) { @@ -750,6 +779,8 @@ static struct cmdtab const Commands[] = { "Link specific commands", "link name command ..."}, {"load", NULL, LoadCommand, LOCAL_AUTH | LOCAL_CX_OPT, "Load settings", "load [system ...]"}, + {"log", NULL, LogCommand, LOCAL_AUTH | LOCAL_CX_OPT, + "log information", "log word ..."}, #ifndef NONAT {"nat", "alias", RunListCommand, LOCAL_AUTH, "NAT control", "nat option yes|no", NatCommands}, @@ -3059,24 +3090,9 @@ SetProcTitle(struct cmdargs const *arg) log_Printf(LogWARN, "Truncating proc title to %d args\n", argc); } command_Expand(argv, argc, arg->argv + arg->argn, arg->bundle, 1, getpid()); - - ptr = title; - remaining = sizeof title - 1; - for (f = 0; f < argc && remaining; f++) { - if (f) { - *ptr++ = ' '; - remaining--; - } - len = strlen(argv[f]); - if (len > remaining) - len = remaining; - memcpy(ptr, argv[f], len); - remaining -= len; - ptr += len; - } - *ptr = '\0'; - + Concatinate(title, sizeof title, argc, (const char *const *)argv); SetTitle(title); + command_Free(argc, argv); return 0; } diff --git a/usr.sbin/ppp/command.h b/usr.sbin/ppp/command.h index 8f793013bbe4..8eb1e38d243d 100644 --- a/usr.sbin/ppp/command.h +++ b/usr.sbin/ppp/command.h @@ -63,6 +63,7 @@ extern const char Version[]; extern void command_Expand(char **, int, char const *const *, struct bundle *, int, pid_t); +extern void command_Free(int, char **); extern int command_Expand_Interpret(char *, int, char *vector[MAXARGS], int); extern int command_Interpret(char *, int, char *vector[MAXARGS]); extern void command_Run(struct bundle *, int, char const *const *, diff --git a/usr.sbin/ppp/defs.c b/usr.sbin/ppp/defs.c index 0e61f8841b80..78ef1dc0f5f4 100644 --- a/usr.sbin/ppp/defs.c +++ b/usr.sbin/ppp/defs.c @@ -387,3 +387,20 @@ zerofdset(fd_set *s) { memset(s, '\0', howmany(getdtablesize(), NFDBITS) * sizeof (fd_mask)); } + +void +Concatinate(char *buf, size_t sz, int argc, const char *const *argv) +{ + int i, n, pos; + + *buf = '\0'; + for (pos = i = 0; i < argc; i++) { + n = snprintf(buf + pos, sz - pos, "%s%s", i ? " " : "", argv[i]); + if (n < 0) { + buf[pos] = '\0'; + break; + } + if ((pos += n) >= sz) + break; + } +} diff --git a/usr.sbin/ppp/defs.h b/usr.sbin/ppp/defs.h index 47ee1c648dca..1a621953b645 100644 --- a/usr.sbin/ppp/defs.h +++ b/usr.sbin/ppp/defs.h @@ -134,3 +134,4 @@ extern const char *ex_desc(int); extern void SetTitle(const char *); extern fd_set *mkfdset(void); extern void zerofdset(fd_set *); +extern void Concatinate(char *, size_t, int, const char *const *); diff --git a/usr.sbin/ppp/iface.c b/usr.sbin/ppp/iface.c index d3ba1d9e9791..ea4105b95819 100644 --- a/usr.sbin/ppp/iface.c +++ b/usr.sbin/ppp/iface.c @@ -343,7 +343,7 @@ iface_addr_Add(const char *name, struct iface_addr *addr, int s) end, ncprange_ntoa(&addr->ifa), strerror(errno)); else { snprintf(dst, sizeof dst, "%s", ncpaddr_ntoa(&addr->peer)); - log_Printf(LogWARN, "iface add: ioctl(SIOCDIFADDR%s, %s -> %s): %s\n", + log_Printf(LogWARN, "iface add: ioctl(SIOCAIFADDR%s, %s -> %s): %s\n", end, ncprange_ntoa(&addr->ifa), dst, strerror(errno)); } } diff --git a/usr.sbin/ppp/lcp.c b/usr.sbin/ppp/lcp.c index c8eb6f7a2d0c..616bf2b6ec71 100644 --- a/usr.sbin/ppp/lcp.c +++ b/usr.sbin/ppp/lcp.c @@ -518,7 +518,7 @@ lcp_SendIdentification(struct lcp *lcp) msg + 4); fsm_Output(&lcp->fsm, CODE_IDENT, id++, msg, 4 + strlen(msg + 4), MB_LCPOUT); - free(exp[0]); + command_Free(1, exp); return 1; } diff --git a/usr.sbin/ppp/log.c b/usr.sbin/ppp/log.c index 5011ed42d6a0..d80af36fca3e 100644 --- a/usr.sbin/ppp/log.c +++ b/usr.sbin/ppp/log.c @@ -194,6 +194,8 @@ static int syslogLevel(int lev) { switch (lev) { + case LogLOG: + return LOG_INFO; case LogDEBUG: case LogTIMER: return LOG_DEBUG; @@ -210,6 +212,8 @@ syslogLevel(int lev) const char * log_Name(int id) { + if (id == LogLOG) + return "LOG"; return id < LogMIN || id > LogMAX ? "Unknown" : LogNames[id - 1]; } @@ -261,6 +265,8 @@ log_DiscardAllLocal(u_long *mask) int log_IsKept(int id) { + if (id == LogLOG) + return LOG_KEPT_SYSLOG; if (id < LogMIN || id > LogMAX) return 0; if (id > LogMAXCONF) diff --git a/usr.sbin/ppp/log.h b/usr.sbin/ppp/log.h index b841f33af863..6e13039f30e4 100644 --- a/usr.sbin/ppp/log.h +++ b/usr.sbin/ppp/log.h @@ -26,6 +26,7 @@ * $FreeBSD$ */ +#define LogLOG (0) #define LogMIN (1) #define LogASYNC (1) /* syslog(LOG_INFO, ....) */ #define LogCBCP (2) @@ -63,6 +64,7 @@ struct datalink; /* The first int arg for all of the following is one of the above values */ extern const char *log_Name(int); +extern int log_Id(const char *); extern void log_Keep(int); extern void log_KeepLocal(int, u_long *); extern void log_Discard(int); diff --git a/usr.sbin/ppp/ppp.8.m4 b/usr.sbin/ppp/ppp.8.m4 index 608576bc2a78..349749c20079 100644 --- a/usr.sbin/ppp/ppp.8.m4 +++ b/usr.sbin/ppp/ppp.8.m4 @@ -3549,8 +3549,11 @@ This value is available irrespective of whether utmp logging is enabled. .El .Pp These substitutions are also done by the -.Dq set proctitle -command. +.Dq set proctitle , +.Dq ident +and +.Dq log +commands. .Pp If you wish to pause .Nm @@ -3823,6 +3826,12 @@ or commands, .Nm will not attempt to make an immediate connection. +.It log Ar word Op Ar word Ns No ... +Send the given word(s) to the log file with the prefix +.Dq LOG: . +Word substitutions are done as explained under the +.Dq !bg +command above. .It open Op lcp|ccp|ipcp This is the opposite of the .Dq close diff --git a/usr.sbin/ppp/systems.h b/usr.sbin/ppp/systems.h index fbd010f85588..9091e730b1a7 100644 --- a/usr.sbin/ppp/systems.h +++ b/usr.sbin/ppp/systems.h @@ -40,6 +40,4 @@ extern FILE *OpenSecret(const char *); extern void CloseSecret(FILE *); extern int AllowUsers(struct cmdargs const *); extern int AllowModes(struct cmdargs const *); -extern int LoadCommand(struct cmdargs const *); -extern int SaveCommand(struct cmdargs const *); extern const char *InterpretArg(const char *, char *); |