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/command.c | |
| parent | 5eef06c222360519f1ba82ee24350adbb1e70ac2 (diff) | |
Notes
Diffstat (limited to 'usr.sbin/ppp/command.c')
| -rw-r--r-- | usr.sbin/ppp/command.c | 86 |
1 files changed, 51 insertions, 35 deletions
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; } |
