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)
This commit is contained in:
parent
5eef06c222
commit
46df5aa7bc
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=85991
@ -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;
|
||||
}
|
||||
|
@ -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 *);
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 *,
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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 *);
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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 *);
|
||||
|
Loading…
Reference in New Issue
Block a user